fix trace selection for z indices affected by floating point rounding

This commit is contained in:
Stewart Allen 2023-02-27 10:38:09 -08:00
commit 88c6f973c6

View file

@ -80,8 +80,8 @@ class Slicer {
p2 = newPoint(0,0,0),
p3 = newPoint(0,0,0);
// for (let i = 0, il = points.length; i < il; ) {
// points[i] = points[i++].toFixed(5);
// for (let i = 0, il = points.length; i < il; i++) {
// points[i] = points[i].round(5);
// }
for (let i = 0, il = points.length; i < il; ) {
@ -162,11 +162,8 @@ class Slicer {
const step = Math.ceil(zlen / count);
const buckets = [];
// console.log({ plen, zlen, ppz, count, step });
// console.log({ points, zs, count, step });
if (count === 1) {
buckets.push({ zs });
} else {
for (let c = 0, b = 0; c < count; c++) {
if (b >= zlen) break;
buckets.push({
@ -178,7 +175,8 @@ class Slicer {
let p1 = newPoint(0,0,0),
p2 = newPoint(0,0,0),
p3 = newPoint(0,0,0);
p3 = newPoint(0,0,0),
ep = 0.001;
begin("create buckets");
for (let i = 0, il = points.length; i < il; ) {
@ -192,16 +190,19 @@ class Slicer {
const min = Math.min(...zs);
const max = Math.max(...zs);
if (zmin < min && zmax < min) {
if (Math.abs(zmin - min) > ep && Math.abs(zmax - min) > ep) {
continue;
}
}
if (zmin > max && zmax > max) {
if (Math.abs(zmin - max) > ep && Math.abs(zmax - max) > ep) {
continue;
}
}
index.push(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, p3.x, p3.y, p3.z);
}
}
end("create buckets");
}
// console.log({ zs, zlen, count, step, buckets, flatoff });