resolve function calling in wasm
This commit is contained in:
parent
3e650511f0
commit
0a2f467c9f
3 changed files with 38 additions and 115 deletions
|
|
@ -326,7 +326,7 @@
|
||||||
} else {
|
} else {
|
||||||
let woutA = filter(geo.poly.diff(setA, setB, z));
|
let woutA = filter(geo.poly.diff(setA, setB, z));
|
||||||
outA.appendAll(woutA);
|
outA.appendAll(woutA);
|
||||||
console.log({outA, woutA});
|
// console.log({outA, woutA});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -347,7 +347,7 @@
|
||||||
} else {
|
} else {
|
||||||
let woutB = filter(geo.poly.diff(setB, setA, z));
|
let woutB = filter(geo.poly.diff(setB, setA, z));
|
||||||
outB.appendAll(woutB);
|
outB.appendAll(woutB);
|
||||||
console.log({outB, woutB});
|
// console.log({outB, woutB});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,33 +38,48 @@ void mem_clr(Uint32 loc) {
|
||||||
free((void *)loc);
|
free((void *)loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 readPoly(Path path, Uint32 pos) {
|
Uint32 readPoly(Path &path, Uint32 pos) {
|
||||||
struct length16 *ls = (struct length16 *)(mem + pos);
|
struct length16 *ls = (struct length16 *)(mem + pos);
|
||||||
Uint16 points = ls->length;
|
Uint16 points = ls->length;
|
||||||
if (debug) polygon(points, 0);
|
// if (debug) polygon(points, 0);
|
||||||
pos += 2;
|
pos += 2;
|
||||||
while (points-- > 0) {
|
while (points-- > 0) {
|
||||||
struct point32 *ip = (struct point32 *)(mem + pos);
|
struct point32 *ip = (struct point32 *)(mem + pos);
|
||||||
pos += 8;
|
pos += 8;
|
||||||
path << IntPoint(ip->x, ip->y);
|
path << IntPoint(ip->x, ip->y);
|
||||||
if (debug) point(ip->x, ip->y);
|
// if (debug) point(ip->x, ip->y);
|
||||||
}
|
}
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 readPolys(Paths paths, Uint32 pos, Uint32 count) {
|
Uint32 readPolys(Paths &paths, Uint32 pos, Uint32 count) {
|
||||||
Uint32 poly = 0;
|
Uint32 poly = 0;
|
||||||
if (debug) abc(poly, count, pos);
|
// if (debug) abc(poly, count, pos);
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
pos = readPoly(paths[poly++], pos);
|
pos = readPoly(paths[poly++], pos);
|
||||||
}
|
}
|
||||||
if (debug) abc(poly, count, pos);
|
// if (debug) abc(poly, count, pos);
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__ ((export_name("set_debug")))
|
Uint32 writePolys(Paths &outs, Uint32 pos) {
|
||||||
void set_debug(Uint8 value) {
|
for (Path po : outs) {
|
||||||
debug = value;
|
// if (debug) polygon(po.size(), 1);
|
||||||
|
struct length16 *ls = (struct length16 *)(mem + pos);
|
||||||
|
ls->length = po.size();
|
||||||
|
pos += 2;
|
||||||
|
for (IntPoint pt : po) {
|
||||||
|
// if (debug) point(pt.X, pt.Y);
|
||||||
|
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;
|
||||||
|
return pos + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__ ((export_name("poly_offset")))
|
__attribute__ ((export_name("poly_offset")))
|
||||||
|
|
@ -75,27 +90,7 @@ Uint32 poly_offset(Uint32 memat, Uint32 polys, float offset) {
|
||||||
Uint32 pos = memat;
|
Uint32 pos = memat;
|
||||||
Uint16 poly = 0;
|
Uint16 poly = 0;
|
||||||
|
|
||||||
// pos = readPolys(ins, pos, polys);
|
pos = readPolys(ins, pos, polys);
|
||||||
|
|
||||||
// while (polys-- > 0) {
|
|
||||||
// pos = readPoly(ins[poly++], pos);
|
|
||||||
// }
|
|
||||||
|
|
||||||
while (poly < polys) {
|
|
||||||
struct length16 *ls = (struct length16 *)(mem + pos);
|
|
||||||
Uint16 points = ls->length;
|
|
||||||
if (debug) polygon(points, 0);
|
|
||||||
pos += 2;
|
|
||||||
while (points-- > 0) {
|
|
||||||
struct point32 *ip = (struct point32 *)(mem + pos);
|
|
||||||
pos += 8;
|
|
||||||
ins[poly] << IntPoint(ip->x, ip->y);
|
|
||||||
if (debug) point(ip->x, ip->y);
|
|
||||||
}
|
|
||||||
poly++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (debug) abc(memat, pos, pos - memat);
|
|
||||||
|
|
||||||
// clean and simplify polygons
|
// clean and simplify polygons
|
||||||
// Paths cleans, simples;
|
// Paths cleans, simples;
|
||||||
|
|
@ -109,23 +104,7 @@ Uint32 poly_offset(Uint32 memat, Uint32 polys, float offset) {
|
||||||
|
|
||||||
Uint32 resat = pos;
|
Uint32 resat = pos;
|
||||||
|
|
||||||
for (Path po : outs) {
|
pos = writePolys(outs, pos);
|
||||||
if (debug) polygon(po.size(), 1);
|
|
||||||
struct length16 *ls = (struct length16 *)(mem + pos);
|
|
||||||
ls->length = po.size();
|
|
||||||
pos += 2;
|
|
||||||
for (IntPoint pt : po) {
|
|
||||||
if (debug) point(pt.X, pt.Y);
|
|
||||||
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;
|
|
||||||
|
|
||||||
co.Clear();
|
co.Clear();
|
||||||
|
|
||||||
|
|
@ -140,17 +119,7 @@ Uint32 poly_union(Uint32 memat, Uint32 polys, float offset) {
|
||||||
Uint32 pos = memat;
|
Uint32 pos = memat;
|
||||||
Uint16 poly = 0;
|
Uint16 poly = 0;
|
||||||
|
|
||||||
while (poly < polys) {
|
pos = readPolys(ins, pos, 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;
|
Clipper clip;
|
||||||
clip.AddPaths(ins, ptSubject, true);
|
clip.AddPaths(ins, ptSubject, true);
|
||||||
|
|
@ -158,29 +127,13 @@ Uint32 poly_union(Uint32 memat, Uint32 polys, float offset) {
|
||||||
|
|
||||||
Uint32 resat = pos;
|
Uint32 resat = pos;
|
||||||
|
|
||||||
for (Path po : outs) {
|
pos = writePolys(outs, pos);
|
||||||
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();
|
clip.Clear();
|
||||||
|
|
||||||
return resat;
|
return resat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
__attribute__ ((export_name("poly_diff")))
|
__attribute__ ((export_name("poly_diff")))
|
||||||
Uint32 poly_diff(Uint32 memat, Uint32 polysA, Uint32 polysB, float offset) {
|
Uint32 poly_diff(Uint32 memat, Uint32 polysA, Uint32 polysB, float offset) {
|
||||||
|
|
||||||
|
|
@ -189,29 +142,8 @@ Uint32 poly_diff(Uint32 memat, Uint32 polysA, Uint32 polysB, float offset) {
|
||||||
Paths outs;
|
Paths outs;
|
||||||
Uint32 pos = memat;
|
Uint32 pos = memat;
|
||||||
|
|
||||||
for (Uint32 poly = 0; poly < polysA; poly++ ) {
|
pos = readPolys(inA, pos, polysA);
|
||||||
struct length16 *ls = (struct length16 *)(mem + pos);
|
pos = readPolys(inB, pos, polysB);
|
||||||
Uint16 points = ls->length;
|
|
||||||
pos += 2;
|
|
||||||
while (points-- > 0) {
|
|
||||||
struct point32 *ip = (struct point32 *)(mem + pos);
|
|
||||||
pos += 8;
|
|
||||||
inA[poly] << IntPoint(ip->x, ip->y);
|
|
||||||
}
|
|
||||||
poly++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Uint32 poly = 0; poly < polysB; poly++ ) {
|
|
||||||
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;
|
|
||||||
inB[poly] << IntPoint(ip->x, ip->y);
|
|
||||||
}
|
|
||||||
poly++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Clipper clip;
|
Clipper clip;
|
||||||
clip.AddPaths(inA, ptSubject, true);
|
clip.AddPaths(inA, ptSubject, true);
|
||||||
|
|
@ -220,23 +152,14 @@ Uint32 poly_diff(Uint32 memat, Uint32 polysA, Uint32 polysB, float offset) {
|
||||||
|
|
||||||
Uint32 resat = pos;
|
Uint32 resat = pos;
|
||||||
|
|
||||||
for (Path po : outs) {
|
pos = writePolys(outs, pos);
|
||||||
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();
|
clip.Clear();
|
||||||
|
|
||||||
return resat;
|
return resat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__ ((export_name("set_debug")))
|
||||||
|
void set_debug(Uint8 value) {
|
||||||
|
debug = value;
|
||||||
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in a new issue