fix invalid point offset calculations

This commit is contained in:
Stewart Allen 2020-04-26 13:19:13 -04:00
commit 223d791a8a

View file

@ -322,7 +322,7 @@ let gs_kiri_sla = exports;
polys.forEach(p => p.forEachSegment((p1, p2) => { polys.forEach(p => p.forEachSegment((p1, p2) => {
let rec = {dist: p1.distTo2D(p2), p1, p2}; let rec = {dist: p1.distTo2D(p2), p1, p2};
if (rec.dist >= spacing) crit++; if (rec.dist >= spacing || slice.ord_first) crit++;
seg.push(rec); seg.push(rec);
})); }));
@ -350,6 +350,7 @@ let gs_kiri_sla = exports;
} }
// drop points too close to other pillars // drop points too close to other pillars
if (!slice.ord_first)
drop: for (let i=0; i<out.length; i++) { drop: for (let i=0; i<out.length; i++) {
for (let j=i+1; j<out.length; j++) { for (let j=i+1; j<out.length; j++) {
if (out[i].distTo2D(out[j]) <= size) { if (out[i].distTo2D(out[j]) <= size) {
@ -382,7 +383,7 @@ let gs_kiri_sla = exports;
.centerCircle(point, size/2, points, true) .centerCircle(point, size/2, points, true)
.setZ(slice.z), .setZ(slice.z),
max = process.slaSupportSize, max = process.slaSupportSize,
inc = process.slaSlice * 2, inc = process.slaSlice/2,
end = false, // center intersects end = false, // center intersects
over = [], // overlapping points over = [], // overlapping points
safe = [], // non-overlapping points safe = [], // non-overlapping points
@ -412,7 +413,7 @@ let gs_kiri_sla = exports;
// not landing on the base and size is max'd // not landing on the base and size is max'd
if (!slice.synth && track.max) { if (!slice.synth && track.max) {
let nusize = track.min; let nusize = track.min;
while (nusize < max) { while (track.length) {
let prec = track.pop(), let prec = track.pop(),
npil = newPolygon() npil = newPolygon()
.centerCircle(point, nusize/2, points, true) .centerCircle(point, nusize/2, points, true)
@ -423,6 +424,9 @@ let gs_kiri_sla = exports;
prec.slice.supports[spos] = npil; prec.slice.supports[spos] = npil;
nusize += inc; nusize += inc;
} }
if (nusize > prec.size) {
break;
}
} }
} }
return; return;
@ -435,7 +439,9 @@ let gs_kiri_sla = exports;
safe.forEach(p => { x += p.x; y += p.y }); safe.forEach(p => { x += p.x; y += p.y });
x /= safe.length; x /= safe.length;
y /= safe.length; y /= safe.length;
point = point.offsetPointTo({x, y, z:slice.z}, inc / 2); if (x !== point.x || y !== point.y) {
point = point.offsetPointTo({x, y, z:slice.z}, inc);
}
} }
// once max'ed out, can only shrink in size // once max'ed out, can only shrink in size
if (track.max) { if (track.max) {
@ -456,6 +462,7 @@ let gs_kiri_sla = exports;
track.push({slice, point, pillar, size}); track.push({slice, point, pillar, size});
if (slice.down) { if (slice.down) {
projectPillar(process, slice.down, point, Math.min(size, max), track); projectPillar(process, slice.down, point, Math.min(size, max), track);
} else {
} }
} }
} }