calculate max tool slice offset once

This commit is contained in:
Stewart Allen 2023-02-13 23:10:42 -05:00
commit e1c1da746e
2 changed files with 7 additions and 6 deletions

View file

@ -109,7 +109,8 @@ class Tool {
toolCenter = (shaft_pix_int - (shaft_pix_int % 2)) / 2,
toolOffset = [],
larger_shaft = shaft_diameter - flute_diameter > 0.001,
rpixsq = flute_radius_pix_float * flute_radius_pix_float;
rpixsq = flute_radius_pix_float * flute_radius_pix_float,
maxo = -Infinity;
// for each point in tool profile, check inside radius
for (let x = 0; x < profile_pix_iter; x++) {
@ -118,6 +119,7 @@ class Tool {
dy = y - toolCenter,
dist_from_center = Math.sqrt(dx * dx + dy * dy);
if (dist_from_center <= flute_radius_pix_float) {
maxo = Math.max(maxo, dx, dy);
// console.log({x,y,dx,dy,dist:dist_from_center,ln:dbl.length})
// flute offset points
let z_offset = 0;
@ -143,7 +145,8 @@ class Tool {
this.profile = profile;
this.profileDim = {
size: shaft_diameter,
pix: profile_pix_iter + 2
pix: profile_pix_iter + 2,
maxo
};
return this;

View file

@ -58,6 +58,7 @@ class Topo4 {
this.resolution = resolution;
this.vertices = widget.getGeoVertices().toShared();
this.tool = tool.generateProfile(resolution).profile;
this.maxo = tool.profileDim.maxo * resolution;
this.diam = tool.fluteDiameter();
onupdate(0, "lathe");
@ -196,17 +197,14 @@ class Topo4 {
}
lathePath(slices, tool) {
const { resolution, step, zBottom } = this;
const { resolution, step, zBottom, maxo } = this;
const tlen = tool.length;
const slen = slices.length;
const sinc = Math.max(1, Math.ceil(step / resolution));
const heights = [];
// console.log({ slen, step, resolution, sinc });
// cull slice lines to only the ones in range (5x faster)
const maxo = Math.max(...tool) * resolution;
const oslices = [];
for (let slice of slices) {
const lines = slice.lines;