stop gap until new function is ready

This commit is contained in:
Stewart Allen 2021-05-31 22:44:13 -04:00
commit 177517778c
2 changed files with 42 additions and 33 deletions

View file

@ -323,15 +323,19 @@
let yDelta_b = C.y - B.y; let yDelta_b = C.y - B.y;
let xDelta_b = C.x - B.x; let xDelta_b = C.x - B.x;
let center = {z: A.z}; let center = {z: A.z};
if (!xDelta_a) xDelta_a = 0.00000000001; // cheat! let cheat = 0;
if (!xDelta_b) xDelta_b = 0.00000000001; // cheat! if (!xDelta_a) { xDelta_a = 0.00000000001; cheat++ } // cheat!
if (!xDelta_b) { xDelta_b = 0.00000000001; cheat++ } // cheat!
if (!yDelta_a) { yDelta_a = 0.00000000001; cheat++ } // cheat!
if (!yDelta_b) { yDelta_b = 0.00000000001; cheat++ } // cheat!
let aSlope = yDelta_a / xDelta_a; let aSlope = yDelta_a / xDelta_a;
let bSlope = yDelta_b / xDelta_b; let bSlope = yDelta_b / xDelta_b;
center.x = (aSlope*bSlope*(A.y - C.y) + bSlope*(A.x + B.x) - aSlope*(B.x+C.x) )/(2* (bSlope-aSlope) ); center.x = (aSlope * bSlope * (A.y - C.y) + bSlope * (A.x + B.x) - aSlope*(B.x+C.x)) / (2 * (bSlope-aSlope));
center.y = -1*(center.x - (A.x+B.x)/2)/aSlope + (A.y+B.y)/2; center.y = (-1 * (center.x - (A.x + B.x) / 2)) / aSlope + ((A.y+B.y) / 2);
// if (isNaN(center.x)) { if (cheat > 1 || [center.x,center.y].hasNaN()) {
// console.log({xDelta_a, xDelta_b, aSlope, bSlope}); // console.log({xDelta_a, xDelta_b, aSlope, bSlope, cheat});
// } return undefined;
}
return center; return center;
} }
@ -341,7 +345,7 @@
*/ */
function center2d(A,B,C,rad) { function center2d(A,B,C,rad) {
let center = circleCenter(A,B,C); let center = circleCenter(A,B,C);
if (rad) { if (center && rad) {
let dx = center.x - A.x; let dx = center.x - A.x;
let dy = center.y - A.y; let dy = center.y - A.y;
center.r = Math.sqrt(dx*dx + dy*dy) center.r = Math.sqrt(dx*dx + dy*dy)

View file

@ -525,35 +525,40 @@
let e2 = arcQ[el-2]; // second last in arcQ let e2 = arcQ[el-2]; // second last in arcQ
let e3 = arcQ[el-1]; // last in arcQ let e3 = arcQ[el-1]; // last in arcQ
let cc = BASE.util.center2d(e1, e2, e3, 1); // find center let cc = BASE.util.center2d(e1, e2, e3, 1); // find center
if ([cc.x,cc.y,cc.z,cc.r].hasNaN()) {
console.log({cc, e1, e2, e3});
}
let dc = 0; let dc = 0;
if (arcQ.length === 3) { if (cc) {
arcQ.center = [ cc ]; if ([cc.x,cc.y,cc.z,cc.r].hasNaN()) {
} else { console.log({cc, e1, e2, e3});
// check center point delta }
let dx = cc.x - arcQ.center[0].x; if (arcQ.length === 3) {
let dy = cc.y - arcQ.center[0].y; arcQ.center = [ cc ];
dc = Math.sqrt(dx * dx + dy * dy);
}
// if new point is off the arc
if (deem || depm || desp || dc > arcDist || cc.r >= arcMax) {
// console.log({dc, depm, desp});
if (arcQ.length === 4) {
// not enough points for an arc, drop first point and recalc center
emitQrec(arcQ.shift());
arcQ.center = [ BASE.util.center2d(arcQ[0], arcQ[1], arcQ[2], 1) ];
} else { } else {
// enough to consider an arc, emit and start new arc // check center point delta
let defer = arcQ.pop(); let dx = cc.x - arcQ.center[0].x;
drainQ(); let dy = cc.y - arcQ.center[0].y;
// re-add point that was off the last arc dc = Math.sqrt(dx * dx + dy * dy);
arcQ.push(defer); }
// if new point is off the arc
if (deem || depm || desp || dc > arcDist || cc.r >= arcMax) {
// console.log({dc, depm, desp});
if (arcQ.length === 4) {
// not enough points for an arc, drop first point and recalc center
emitQrec(arcQ.shift());
arcQ.center = [ BASE.util.center2d(arcQ[0], arcQ[1], arcQ[2], 1) ];
} else {
// enough to consider an arc, emit and start new arc
let defer = arcQ.pop();
drainQ();
// re-add point that was off the last arc
arcQ.push(defer);
}
} else {
// new point is on the arc
arcQ.center.push(cc);
} }
} else { } else {
// new point is on the arc // drainQ on invalid center
arcQ.center.push(cc); drainQ();
} }
} }
} else { } else {