diff --git a/js/geo-polygon.js b/js/geo-polygon.js index f65d746a..f23233fc 100644 --- a/js/geo-polygon.js +++ b/js/geo-polygon.js @@ -112,14 +112,18 @@ var gs_base_polygon = exports; * Polygon Prototype Functions ******************************************************************* */ - PRO.toString = function() { + PRO.toString = function(verbose) { let l; if (this.inner && this.inner.length) { - l = '/' + this.inner.map(i => i.toString()).join(','); + l = '/' + this.inner.map(i => i.toString(verbose)).join(','); } else { l = ''; } - return `P[${this.points.length,this.area().toFixed(2)}${l}]`; + if (verbose) { + return `P[{${this.area().toFixed(2)}}[${this.points.length}](${this.points.map(p=>`${p.x},${p.y}`).join('|')})${l}]`; + } else { + return `P[${this.points.length,this.area().toFixed(2)}${l}]`; + } }; // return which plane (x,y,z) this polygon is coplanar with @@ -1069,6 +1073,9 @@ var gs_base_polygon = exports; * @returns {?Polygon[]} returns output array provided as input or new array if not provided */ PRO.offset = function(offset, output) { + // let offs = geo.poly.offset([this], -offset, this.getZ()); + // if (output) output.appendAll(offs); + // return output || offs; return POLY().expand([this], -offset, this.getZ(), output); }; diff --git a/js/geo-wasm.js b/js/geo-wasm.js index 4bcde68d..0f75c0df 100644 --- a/js/geo-wasm.js +++ b/js/geo-wasm.js @@ -68,7 +68,35 @@ if (!self.window) } } wasm.free(memat); - return out; + return polyNest(out); + } + + // nest closed polygons without existing parent / child relationships + function polyNest(polys) { + polys.sort((a,b) => { + return b.bounds.minx - a.bounds.minx; + }); + // from smallest to largest, check for enclosing bounds and nest + for (let i=0, il=polys.length; ilength = po.size(); pos += 2; for (IntPoint pt : po) { // point(pt.X, pt.Y); struct point32 *ip = (struct point32 *)(mem + pos); - ip->x = pt.X; - ip->y = pt.Y; + ip->x = (int)pt.X; + ip->y = (int)pt.Y; pos += 8; } } + // null terminate + struct length16 *ls = (struct length16 *)(mem + pos); + ls->length = 0; + co.Clear(); return resat; diff --git a/wasm/kiri-geo.wasm b/wasm/kiri-geo.wasm index cc9ea758..989dbfad 100644 Binary files a/wasm/kiri-geo.wasm and b/wasm/kiri-geo.wasm differ