diff --git a/src/geo/polygons.js b/src/geo/polygons.js index 59b82f91..4dd6107f 100644 --- a/src/geo/polygons.js +++ b/src/geo/polygons.js @@ -526,7 +526,7 @@ zed = opts.z || 0; if (opts.wasm && geo.wasm) { - polys = geo.wasm.js.offset(polys, offs, zed); + polys = geo.wasm.js.offset(polys, offs, zed, clean ? CONF.clipperClean : 0, simple ? 1 : 0); } else { let coff = new ClipperLib.ClipperOffset(opts.miter, opts.arc), ctre = new ClipperLib.PolyTree(); diff --git a/src/geo/wasm.js b/src/geo/wasm.js index 9e33106f..9ff2c98d 100644 --- a/src/geo/wasm.js +++ b/src/geo/wasm.js @@ -76,12 +76,12 @@ if (!self.window) (function() { return out; } - function polyOffset(polys, offset, z) { + function polyOffset(polys, offset, z, clean, simple) { geo.count.offset++; let wasm = geo.wasm, buffer = geo.wasm.shared, pcount = writePolys(new DataWriter(wasm.heap, buffer), polys), - resat = wasm.fn.offset(buffer, pcount, offset * factor), + resat = wasm.fn.offset(buffer, pcount, offset * factor, clean, simple), out = readPolys(new DataReader(wasm.heap, resat), z); return polyNest(out); } diff --git a/wasm/kiri-geo.cpp b/wasm/kiri-geo.cpp index 5e9ea426..259c9e71 100644 --- a/wasm/kiri-geo.cpp +++ b/wasm/kiri-geo.cpp @@ -85,7 +85,7 @@ Uint32 writePolys(Paths &outs, Uint32 pos) { } __attribute__ ((export_name("poly_offset"))) -Uint32 poly_offset(Uint32 memat, Uint32 polys, float offset) { +Uint32 poly_offset(Uint32 memat, Uint32 polys, float offset, float clean, Uint8 simple) { Paths ins(polys); Paths outs; @@ -94,11 +94,17 @@ Uint32 poly_offset(Uint32 memat, Uint32 polys, float offset) { pos = readPolys(ins, pos, polys); - // clean and simplify polygons - // Paths cleans, simples; - // CleanPolygons(ins, cleans, 250); - // SimplifyPolygons(cleans, simples, pftNonZero); - // ins = simples; + if (clean > 0) { + Paths cleans; + CleanPolygons(ins, cleans, clean); + ins = cleans; + } + + if (simple > 0) { + Paths simples; + SimplifyPolygons(ins, simples); + ins = simples; + } ClipperOffset co; co.AddPaths(ins, jtMiter, etClosedPolygon); diff --git a/wasm/kiri-geo.wasm b/wasm/kiri-geo.wasm index 83487c75..db0d7bd7 100755 Binary files a/wasm/kiri-geo.wasm and b/wasm/kiri-geo.wasm differ