diff --git a/web/kiri/gyroid-test.html b/web/kiri/gyroid-test.html index 4faf21c6..1fa56073 100644 --- a/web/kiri/gyroid-test.html +++ b/web/kiri/gyroid-test.html @@ -96,8 +96,51 @@ } } + class Grid { + constructor(x,y,div) { + this.x = (x/div)|0; + this.y = (y/div)|0; + this.div = div; + this.grid = new Array(this.x * this.y); + } + + get(x,y) { + x = (x/this.div)|0; + y = (y/this.div)|0; + let pos = x + y * this.x; + let rec = this.grid[pos]; + if (rec) return rec; + return this.grid[pos] = []; + } + + _get(x,y) { + if (x < 0 || y < 0 || x > this.x || y > this.y) return undefined; + return this.grid[x + y * this.x]; + } + + peers(x,y) { + let grid = this.grid; + let r = this.x; + // console.log('peers',x,y) + x = (x/this.div)|0; + y = (y/this.div)|0; + let peers = [], p; + p = this._get(x,y); if (p) peers.push(p); + p = this._get(x-1,y); if (p) peers.push(p); + p = this._get(x+1,y); if (p) peers.push(p); + p = this._get(x,y-1); if (p) peers.push(p); + p = this._get(x,y+1); if (p) peers.push(p); + p = this._get(x+1,y+1); if (p) peers.push(p); + p = this._get(x-1,y+1); if (p) peers.push(p); + p = this._get(x+1,y-1); if (p) peers.push(p); + p = this._get(x-1,y-1); if (p) peers.push(p); + // console.log('---',x,y,peers,this.x,this.y) + return peers; + } + } + let PI2 = Math.PI * 2; - let rez = 200; + let rez = 300; let inc = PI2 / rez; let zcache = {}; let timer = new Timer(); @@ -198,18 +241,20 @@ // create sparse representation let sparse = []; let center = rez / 2; - let edgev = size-1; + let grid = new Grid(size,size,10); for (let x=0; x maxdist) { break; } @@ -272,6 +333,7 @@ } } while (added); } while (cleared < sparse.length); + console.log('chains',chain.length); timer.mark('chain'); // simplify poly