use epsilon value for more accurate zflat calculation

This commit is contained in:
Stewart Allen 2025-10-29 19:40:52 -04:00
commit 052716ec6d
3 changed files with 10 additions and 10 deletions

View file

@ -12,6 +12,8 @@ import { polygons } from '../geo/polygons.js';
import { newPoint } from '../geo/point.js';
import { config } from '../geo/base.js';
const epsilon = 10e-5;
function dval(v, dv) {
return v !== undefined ? v : dv;
}
@ -75,7 +77,7 @@ export async function slice(points, options = {}) {
// used to calculate buckets (rough sum of z span)
zSum += (Math.abs(p1.z - p2.z) + Math.abs(p2.z - p3.z) + Math.abs(p3.z - p1.z));
// use co-flat and co-line detection to adjust slice Z
if (p1.z === p2.z && p2.z === p3.z && p1.z >= zMin) {
if (Math.abs(p1.z - p2.z) < epsilon && Math.abs(p2.z - p3.z) < epsilon && p1.z >= zMin) {
// detect faces co-planar with Z and sum the enclosed area
let zkey = p1.z,
area = Math.abs(base.util.area2(p1,p2,p3)) / 2;

View file

@ -688,7 +688,7 @@ export async function holes(settings, widget, individual, rec, onProgress) {
let opts = { each: onEach, progress: (num, total) => onProgress(num / total * 0.5, "slice") };
await slicer.slice(indices, opts);
let shadowedDrills = false;
// console.log("slices",slices)
for (let [i, slice] of slices.entries()) {
for (let top of slice.tops) {
// console.log("slicing",slice.z,top)
@ -698,13 +698,13 @@ export async function holes(settings, widget, individual, rec, onProgress) {
continue;
}
for (let poly of inner) {
if (poly.points.length < 7) continue;
if (poly.points.length < 7) {
continue;
}
let center = poly.calcCircleCenter();
center.area = poly.area();
center.overlapping = [center];
center.depth = 0;
// console.log("center",center)
if (poly.circularity() < 0.98) {
// if not circular, don't add to holes
continue;
@ -717,8 +717,7 @@ export async function holes(settings, widget, individual, rec, onProgress) {
let overlap = false;
for (let [i, circle] of circles.entries()) {
let dist = circle.distTo2D(center);
// //if on the same xy point,
// if on the same xy point,
if (dist <= centerDiff) {
// console.log("overlap",center,circle);
circle.overlapping.push(center);
@ -732,12 +731,10 @@ export async function holes(settings, widget, individual, rec, onProgress) {
}
onProgress(0.5 + (i / slices.length * 0.25), "recognize circles");
}
let drills = [];
for (let [i, c] of circles.entries()) {
let overlapping = c.overlapping;
let last = overlapping.shift();
while (overlapping.length) {
let circ = overlapping.shift();

View file

@ -12,6 +12,7 @@ const { sliceConnect, sliceDedup } = slicer;
const { config } = base;
const timing = false;
const zDecimal = 3;
const epsilon = 10e-5;
const begin = function () {
if (timing) console.time(...arguments);
@ -94,7 +95,7 @@ export class Slicer {
countZ(p3.z);
}
// use co-flat and co-line detection to adjust slice Z
if (p1.z === p2.z && p2.z === p3.z) {
if (Math.abs(p1.z - p2.z) < epsilon && Math.abs(p2.z - p3.z) < epsilon) {
// detect zFlat faces to avoid slicing directly on them
let zkey = p1.z.toFixed(zDecimal),
area = Math.abs(util.area2(p1, p2, p3)) / 2;