diff --git a/todo b/todo index d69a0b0e..4edb7cc2 100644 --- a/todo +++ b/todo @@ -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 diff --git a/web/app/struct-tests.js b/web/app/struct-tests.js new file mode 100644 index 00000000..7488cdb1 --- /dev/null +++ b/web/app/struct-tests.js @@ -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")); + +}; + diff --git a/web/app/struct.js b/web/app/struct.js new file mode 100644 index 00000000..d7bf1172 --- /dev/null +++ b/web/app/struct.js @@ -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]; + } + } +}; + + + diff --git a/web/app/test-utils.js b/web/app/test-utils.js new file mode 100644 index 00000000..d64f71f3 --- /dev/null +++ b/web/app/test-utils.js @@ -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) ; + } +} \ No newline at end of file diff --git a/web/index.html b/web/index.html index 0f07f4e1..82edb9bf 100644 --- a/web/index.html +++ b/web/index.html @@ -26,7 +26,6 @@ diff --git a/web/test.html b/web/test.html index 0af2b453..36caa05e 100644 --- a/web/test.html +++ b/web/test.html @@ -1,31 +1,29 @@ - + Test Suite - + + + + + + + + + + + + + + + + + - -
-
-
- -
-
-
-
\ No newline at end of file