add clean and simplify to wasm offset
This commit is contained in:
parent
87642e8cf3
commit
2f2cfbc165
4 changed files with 15 additions and 9 deletions
|
|
@ -526,7 +526,7 @@
|
||||||
zed = opts.z || 0;
|
zed = opts.z || 0;
|
||||||
|
|
||||||
if (opts.wasm && geo.wasm) {
|
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 {
|
} else {
|
||||||
let coff = new ClipperLib.ClipperOffset(opts.miter, opts.arc),
|
let coff = new ClipperLib.ClipperOffset(opts.miter, opts.arc),
|
||||||
ctre = new ClipperLib.PolyTree();
|
ctre = new ClipperLib.PolyTree();
|
||||||
|
|
|
||||||
|
|
@ -76,12 +76,12 @@ if (!self.window) (function() {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
function polyOffset(polys, offset, z) {
|
function polyOffset(polys, offset, z, clean, simple) {
|
||||||
geo.count.offset++;
|
geo.count.offset++;
|
||||||
let wasm = geo.wasm,
|
let wasm = geo.wasm,
|
||||||
buffer = geo.wasm.shared,
|
buffer = geo.wasm.shared,
|
||||||
pcount = writePolys(new DataWriter(wasm.heap, buffer), polys),
|
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);
|
out = readPolys(new DataReader(wasm.heap, resat), z);
|
||||||
return polyNest(out);
|
return polyNest(out);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ Uint32 writePolys(Paths &outs, Uint32 pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__ ((export_name("poly_offset")))
|
__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 ins(polys);
|
||||||
Paths outs;
|
Paths outs;
|
||||||
|
|
@ -94,11 +94,17 @@ Uint32 poly_offset(Uint32 memat, Uint32 polys, float offset) {
|
||||||
|
|
||||||
pos = readPolys(ins, pos, polys);
|
pos = readPolys(ins, pos, polys);
|
||||||
|
|
||||||
// clean and simplify polygons
|
if (clean > 0) {
|
||||||
// Paths cleans, simples;
|
Paths cleans;
|
||||||
// CleanPolygons(ins, cleans, 250);
|
CleanPolygons(ins, cleans, clean);
|
||||||
// SimplifyPolygons(cleans, simples, pftNonZero);
|
ins = cleans;
|
||||||
// ins = simples;
|
}
|
||||||
|
|
||||||
|
if (simple > 0) {
|
||||||
|
Paths simples;
|
||||||
|
SimplifyPolygons(ins, simples);
|
||||||
|
ins = simples;
|
||||||
|
}
|
||||||
|
|
||||||
ClipperOffset co;
|
ClipperOffset co;
|
||||||
co.AddPaths(ins, jtMiter, etClosedPolygon);
|
co.AddPaths(ins, jtMiter, etClosedPolygon);
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in a new issue