borrow bucket map from cam slicer to allow negative z indices

This commit is contained in:
Stewart Allen 2023-01-08 20:33:13 -05:00
commit 5a56453390
2 changed files with 16 additions and 6 deletions

View file

@ -45,6 +45,7 @@ async function slice(points, options = {}) {
zScale, // bucket span in z units
zSum = 0.0, // sanity check that points enclose non-zere volume
buckets = [], // banded/grouped faces to speed up slice/search
bucketMap = {},
overlapMax = options.overlap || 0.75,
bucketMax = options.bucketMax || 100,
onupdate = options.onupdate || function() {},
@ -161,11 +162,6 @@ async function slice(points, options = {}) {
return {};
}
// create empty buckets
for (i = 0; i < bucketCount; i++) {
buckets.push({ points: [], slices: [] });
}
if (bucketCount > 1) {
let failAt = (points.length * overlapMax) | 0, bucket;
// copy triples into all matching z-buckets
@ -179,7 +175,12 @@ async function slice(points, options = {}) {
bM = Math.min(Math.ceil(zM * zScale), bucketCount);
// add point to all buckets in range
for (j = bm; j < bM; j++) {
bucket = buckets[j].points;
let map = bucketMap[j];
if (!map) {
map = bucketMap[j] = { points: [], slices: [] };
buckets.push(map);
}
bucket = map.points;
bucket.push(p1);
bucket.push(p2);
bucket.push(p3);
@ -196,6 +197,7 @@ async function slice(points, options = {}) {
// fallback if we can't partition point space
if (bucketCount === 1) {
buckets = [{ points, slices: [] }];
bucketMap[0] = buckets[0];
}
// create buckets data structure