add wasm debugging options

This commit is contained in:
Stewart Allen 2021-06-22 22:04:26 -04:00
commit ab2ff26fb0
4 changed files with 34 additions and 20 deletions

2
.gitignore vendored
View file

@ -4,4 +4,4 @@ tmp
node_modules
package-lock.json
logs/*
data/*
data/*

View file

@ -71,9 +71,9 @@ if (!self.window) (function() {
break;
}
}
// if (debug) {
// console.log({diff_resat: resat, memat});
// }
if (debug) {
console.log({offset: polys, resat, memat, len: resat - memat});
}
wasm.free(memat);
return polyNest(out);
}
@ -193,9 +193,11 @@ if (!self.window) (function() {
free: exports.mem_clr,
diff: exports.poly_diff,
union: exports.poly_union,
offset: exports.poly_offset
offset: exports.poly_offset,
set_debug: exports.set_debug
};
if (debug) {
wasm.set_debug(1);
runTests();
}
});

View file

@ -11,7 +11,7 @@ typedef int int32;
using namespace ClipperLib;
Uint8 *mem = 0;
const Uint8 debug = 0;
Uint8 debug = 0;
extern "C" {
extern void polygon(Uint32 points, Uint32 inners);
@ -38,27 +38,35 @@ void mem_clr(Uint32 loc) {
free((void *)loc);
}
Uint32 readPoly(Path path, Uint32 pos) {
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;
path << IntPoint(ip->x, ip->y);
if (debug) point(ip->x, ip->y);
}
return pos;
}
Uint32 readPolys(Paths paths, Uint32 pos, Uint32 count) {
Uint32 poly = 0;
if (debug) abc(poly, count, pos);
while (count > 0) {
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;
paths[poly] << IntPoint(ip->x, ip->y);
if (debug) point(ip->x, ip->y);
}
poly++;
count--;
while (count-- > 0) {
pos = readPoly(paths[poly++], pos);
}
if (debug) abc(poly, count, pos);
return pos;
}
__attribute__ ((export_name("set_debug")))
void set_debug(Uint8 value) {
debug = value;
}
__attribute__ ((export_name("poly_offset")))
Uint32 poly_offset(Uint32 memat, Uint32 polys, float offset) {
@ -69,6 +77,10 @@ Uint32 poly_offset(Uint32 memat, Uint32 polys, float offset) {
// 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;
@ -83,7 +95,7 @@ Uint32 poly_offset(Uint32 memat, Uint32 polys, float offset) {
poly++;
}
if (debug) abc(memat, pos, memat - pos);
if (debug) abc(memat, pos, pos - memat);
// clean and simplify polygons
// Paths cleans, simples;

Binary file not shown.