This commit is contained in:
Val Erastov 2015-01-30 16:26:42 -08:00
parent 467389ad7e
commit 658f2220ee
6 changed files with 148 additions and 24 deletions

5
todo
View file

@ -4,14 +4,17 @@
- add support for arcs and lines
- add object properties panel
- make dims selectable
- delete objects from scene
- initialization / adding new objects
- cut inside
- border cases
- RCP framework
- facets
- assembly constraints
- export to STL
- object basic 3d operations(rotate/scale/translate)
- object basic 3d operations(rotate/scale/translate)
- wireframe for solids
- save/share in the cloud
- open library

15
web/app/struct-tests.js Normal file
View file

@ -0,0 +1,15 @@
TCAD.struct.tests = {};
TCAD.struct.tests.testHashTable = function() {
var map = new TCAD.struct.HashTable(TCAD.struct.stringEq, TCAD.struct.stringHash);
map.put("John", "Doe");
map.put("Patric", "Kane");
map.put("Andrew", "Wozniak");
console.log(map.get("John"));
console.log(map.get("Patric"));
console.log(map.get("Andrew"));
};

93
web/app/struct.js Normal file
View file

@ -0,0 +1,93 @@
TCAD.struct = {};
TCAD.struct.stringEq = function(s1, s2) {
return s1 === s2;
};
TCAD.struct.stringHash = function(s) {
var h = 0;
for (var i = 0; i < s.length; i++) {
h = 31 * h + s.charAt(i);
}
return h;
};
TCAD.struct.HashTable = function(equals, hashCode) {
this.equals = equals;
this.hashCode = hashCode;
this.table = this._arr(8);
this.used = 0;
};
TCAD.struct.HashTable.prototype._hash = function(e) {
return this.hashCode(e);
};
TCAD.struct.HashTable.prototype._index = function(e) {
var hash = this._hash(e);
return hash % (this.table.length - 1);
};
TCAD.struct.HashTable.prototype._arr = function(size) {
var out = [];
out.length = size;
for (var i = 0; i < size; ++i) {
out[i] = null;
}
return out;
};
TCAD.struct.HashTable.prototype._rebuild = function(size) {
var old = this.table;
this.table = this._arr(size);
for (var j = 0; j < old.length; ++j) {
var e = old[j];
if (e === null) continue;
var idx = this._index(e[0]);
for (var i = idx; i < this.table.length; ++ i) {
if (this.table[i] === null) {
this.table[i] = e;
}
}
}
};
TCAD.struct.HashTable.prototype.put = function(key, value) {
var n_used = this.used;
this._put(key, value);
if (!(this.used > n_used && this.used * 3 >= (this.table.length) * 2)) {
return;
}
this._rebuild((this.used > 50000 ? 2 : 4) * used);
};
TCAD.struct.HashTable.prototype._put = function(key, value) {
var idx = this._index(key);
for (var i = idx; i < this.table.length; ++ i) {
var e = this.table[i];
if (e === null) {
this.table[i] = [key, value];
this.used ++;
}
if (this.equals(e[0], key)) {
e[1] = value;
}
}
};
TCAD.struct.HashTable.prototype.get = function(key) {
var idx = this._index(key);
for (var i = idx; i < this.table.length; ++ i) {
var e = this.table[i];
if (e === null) {
return null;
}
if (this.equals(e[0], key)) {
return e[1];
}
}
};

16
web/app/test-utils.js Normal file
View file

@ -0,0 +1,16 @@
function _test_utils_msg(msg) {
return (msg === undefined ? "" : "\n" + msg);
}
function assert(statement, msg) {
if (!statement) {
throw "ASSERTION ERROR." + _test_utils_msg(msg) ;
}
}
function assertEQ(expected, actual, msg) {
if ( expected !== actual ) {
throw "ASSERTION ERROR. \n Expected: " + a + ", Actual: " + b + _test_utils_msg(msg) ;
}
}

View file

@ -26,7 +26,6 @@
<script>window.onload = function() {
window._TCAD_APP = new TCAD.App();
TCAD.craft._mergeCSGPolygonsTest2();
}</script>
</head>
<body>

View file

@ -1,31 +1,29 @@
<html>
<head>
<title>Test Suite</title>
<style>
html, body {
background: gray;
height: 100%;
padding: 0;
margin: 0;
}
.panel {
background: #444;
border: 0px solid black;
}
</style>
<script src="lib/three/three.js"></script>
<script src="lib/three/TrackballControls.js"></script>
<script src="lib/three/OrbitControls.js"></script>
<script src="lib/dat.gui.min.js"></script>
<script src="lib/csg.js"></script>
<script src="lib/pnltri.js"></script>
<script src="app/main.js"></script>
<script src="app/ctrl.js"></script>
<script src="app/viewer.js"></script>
<script src="app/engine.js"></script>
<script src="app/vector.js"></script>
<script src="app/math/math.js"></script>
<script src="app/workbench.js"></script>
<script src="app/math/graph.js"></script>
<script src="app/struct.js"></script>
<script src="app/struct-tests.js"></script>
<script>window.onload = function() {
TCAD.struct.tests.testHashTable();
}</script>
</head>
<body>
<div class="panel" style="width: 100%; height: 50px;"></div>
<div style="width: 100%; height: calc(100% - 100px);">
<div class="panel" style="background: blue; float: left; width: 245px; height: 100%;"></div>
<!-- div style="background-color: blue; height: 20px; width: 100px; float: left;"><canvas width="300" height="300" id="viewer"></canvas></div-->
<div style="background: black; float: left; width: calc(100% - 296px); height: 100%;"></div>
<div class="panel" style="background-color: yellow; width: 50px; float: right; height: 100%; "></div>
</div>
<div class="panel" style="width: 100%; height: 50px; border-top-width: 1px;"></div>
</body>
</html>