add poly union to wasm geo helper
This commit is contained in:
parent
b6d91f39a5
commit
c9cf45bc40
4 changed files with 89 additions and 6 deletions
|
|
@ -92,3 +92,53 @@ Uint32 poly_offset(Uint32 memat, Uint32 polys, float offset) {
|
|||
|
||||
return resat;
|
||||
}
|
||||
|
||||
__attribute__ ((export_name("poly_union")))
|
||||
Uint32 poly_union(Uint32 memat, Uint32 polys) {
|
||||
|
||||
using namespace ClipperLib;
|
||||
|
||||
Paths ins(polys);
|
||||
Paths outs;
|
||||
Uint32 pos = memat;
|
||||
Uint16 poly = 0;
|
||||
|
||||
while (poly < polys) {
|
||||
struct length16 *ls = (struct length16 *)(mem + pos);
|
||||
Uint16 points = ls->length;
|
||||
pos += 2;
|
||||
while (points-- > 0) {
|
||||
struct point32 *ip = (struct point32 *)(mem + pos);
|
||||
pos += 8;
|
||||
ins[poly] << IntPoint(ip->x, ip->y);
|
||||
}
|
||||
poly++;
|
||||
}
|
||||
|
||||
Clipper clip;
|
||||
clip.AddPath(ins[0], ptSubject, true);
|
||||
clip.AddPath(ins[1], ptClip, true);
|
||||
clip.Execute(ctUnion, outs, pftEvenOdd, pftEvenOdd);
|
||||
|
||||
Uint32 resat = pos;
|
||||
|
||||
for (Path po : outs) {
|
||||
struct length16 *ls = (struct length16 *)(mem + pos);
|
||||
ls->length = po.size();
|
||||
pos += 2;
|
||||
for (IntPoint pt : po) {
|
||||
struct point32 *ip = (struct point32 *)(mem + pos);
|
||||
ip->x = (int)pt.X;
|
||||
ip->y = (int)pt.Y;
|
||||
pos += 8;
|
||||
}
|
||||
}
|
||||
|
||||
// null terminate
|
||||
struct length16 *ls = (struct length16 *)(mem + pos);
|
||||
ls->length = 0;
|
||||
|
||||
clip.Clear();
|
||||
|
||||
return resat;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue