From d6b53d425ec2d02ecb5ac35388e8815eadb65f14 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sat, 14 Jan 2023 12:11:49 -0500 Subject: [PATCH] checkpont complete trace extraction from topo --- src/kiri-mode/cam/topo.js | 189 +++++++++++++++++++------------------- 1 file changed, 94 insertions(+), 95 deletions(-) diff --git a/src/kiri-mode/cam/topo.js b/src/kiri-mode/cam/topo.js index 82a6c89e..bd7a7a0e 100644 --- a/src/kiri-mode/cam/topo.js +++ b/src/kiri-mode/cam/topo.js @@ -150,92 +150,12 @@ class Topo { )); const trace = new Trace({ + probe, curvesOnly, maxangle, flatness }); - const { push_point, end_poly, newtrace, newslice } = trace; - - const inClip = function(clips, checkZ, point) { - for (let i=0; i box.max.y) { - gridy++; - continue; - } - // find tool z at grid point - let tv = toolAtZ(gridx, gridy); - checkr.x = x; - checkr.y = y; - // when tabs are on and this point is inside the - // tab polygon, ensure z is at least tabHeight - if (clipTab && tv < tabHeight && inClip(clipTab, tv, checkr)) { - tv = tabZ; - } - // if the value is on the floor and inside the clip - // poly (usually shadow), end the segment - if (clipTo && !inClip(clipTo, undefined, checkr)) { - end_poly(); - gridy++; - continue; - } - push_point(x, y, tv); - gridy++; - } - end_poly(); - } - - function traceX(params) { - let { from, to, step, box, y, gridx, gridy } = params; - let { clipTab, tabHeight, clipTo } = params; - const checkr = newPoint(0,0); - newtrace(); - newslice(); - for (let x = from; x < to; x += step) { - if (x < box.min.x || y > box.max.x) { - gridx++; - continue; - } - // find tool z at grid point - let tv = toolAtZ(gridx, gridy); - checkr.x = x; - checkr.y = y; - // when tabs are on and this point is inside the - // tab polygon, ensure z is at least tabHeight - if (clipTab && tv < tabHeight && inClip(clipTab, tv, checkr)) { - tv = tabZ; - } - // if the value is on the floor and inside the clip - // poly (usually shadow), end the segment - if (clipTo && !inClip(clipTo, undefined, checkr)) { - end_poly(); - gridx++; - continue; - } - push_point(x, y, tv); - gridx++; - } - end_poly(); - } - if (contourY) { // emit slice per X for (x = minX - partOff; x <= maxX + partOff; x += toolStep) { @@ -243,7 +163,7 @@ class Topo { gridx = Math.round(((x - minX) / boundsX) * stepsX); gridy = -gridDelta; - traceY({ + const segments = trace.crossY({ from: minY - partOff, to: maxY + partOff, step: resolution, @@ -256,14 +176,12 @@ class Topo { tabHeight }); - const sliceout = trace.sliceout; - - if (sliceout.length > 0) { + if (segments.length > 0) { let slice = newSlice(gridx); - slice.camLines = sliceout; + slice.camLines = segments; slice.output() .setLayer("contour y", {face: color, line: color}) - .addPolys(sliceout); + .addPolys(segments); newslices.push(slice); } onupdate(++stepsTaken, stepsTotal, "contour y"); @@ -277,7 +195,7 @@ class Topo { gridy = Math.round(((y - minY) / boundsY) * stepsY); gridx = -gridDelta; - traceX({ + const segments = trace.crossX({ from: minX - partOff, to: maxX + partOff, step: resolution, @@ -290,14 +208,12 @@ class Topo { tabHeight }); - const sliceout = trace.sliceout; - - if (sliceout.length > 0) { + if (segments.length > 0) { let slice = newSlice(gridy); - slice.camLines = sliceout; + slice.camLines = segments; slice.output() .setLayer("contour x", {face: color, line: color}) - .addPolys(sliceout); + .addPolys(segments); newslices.push(slice); } onupdate(++stepsTaken, stepsTotal, "contour x"); @@ -500,7 +416,9 @@ class Trace { constructor(params) { - const { curvesOnly, maxangle, flatness } = params; + const { probe, curvesOnly, maxangle, flatness } = params; + + this.probe = probe; let trace, slice, @@ -562,12 +480,93 @@ class Trace { trace = newPolygon().setOpen(); } + const object = this.object = this; + + this.inClip = function (clips, checkZ, point) { + for (let i=0; i box.max.y) { + gridy++; + continue; + } + // find tool z at grid point + let tv = toolAtZ(gridx, gridy); + checkr.x = x; + checkr.y = y; + // when tabs are on and this point is inside the + // tab polygon, ensure z is at least tabHeight + if (clipTab && tv < tabHeight && inClip(clipTab, tv, checkr)) { + tv = trace.tabZ; + } + // if the value is on the floor and inside the clip + // poly (usually shadow), end the segment + if (clipTo && !inClip(clipTo, undefined, checkr)) { + end_poly(); + gridy++; + continue; + } + push_point(x, y, tv); + gridy++; + } + end_poly(); return this.slice; } + crossX(params) { + const { push_point, end_poly, newtrace, newslice, inClip } = this.object; + const { toolAtZ, toolAtXY, zAtXY } = this.probe; + let { from, to, step, box, y, gridx, gridy } = params; + let { clipTab, tabHeight, clipTo } = params; + const checkr = newPoint(0,0); + newslice(); + newtrace(); + for (let x = from; x < to; x += step) { + if (x < box.min.x || y > box.max.x) { + gridx++; + continue; + } + // find tool z at grid point + let tv = toolAtZ(gridx, gridy); + checkr.x = x; + checkr.y = y; + // when tabs are on and this point is inside the + // tab polygon, ensure z is at least tabHeight + if (clipTab && tv < tabHeight && inClip(clipTab, tv, checkr)) { + tv = trace.tabZ; + } + // if the value is on the floor and inside the clip + // poly (usually shadow), end the segment + if (clipTo && !inClip(clipTo, undefined, checkr)) { + end_poly(); + gridx++; + continue; + } + push_point(x, y, tv); + gridx++; + } + end_poly(); + return this.slice; + } } function raster_slice(inputs) {