fix: drop glare holes before the margin and never auto-pick specks

Filtering holes after the margin let -2 mm grow 1 mm specks past the
3 mm cutoff, and could drop real holes shrunk by a positive margin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
immortaly007andClaude Opus 5.5 committed 2026-10-15 15:07:16 +02:00
1 parent abef0f982b
commit 41baa25a01
7 files changed
+59 -25

No files matched your search

+1 -7
View File
@@ -2,8 +2,6 @@ import type { Point, Shape } from './types';
export type Bounds = { minX: number; minY: number; maxX: number; maxY: number };
const MIN_HOLE_MM = 3;
export function bounds(points: Point[]): Bounds {
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
for (const p of points) {
@@ -70,11 +68,7 @@ export function prepareForExport(shapePx: Shape, pxPerMm: number, toleranceMm =
simplifyRing(ring.map((p) => ({ x: p.x / pxPerMm, y: p.y / pxPerMm })), toleranceMm);
const outer = toMm(shapePx.outer);
if (outer.length < 3) return null;
const holes = shapePx.holes.map(toMm).filter((hole) => {
if (hole.length < 3) return false;
const { width, height } = shapeSize({ outer: hole, holes: [] });
return width >= MIN_HOLE_MM || height >= MIN_HOLE_MM;
});
const holes = shapePx.holes.map(toMm).filter((hole) => hole.length >= 3);
const { minX, minY } = bounds(outer);
const shift = (ring: Point[]) => ring.map((p) => ({ x: p.x - minX, y: p.y - minY }));
return { outer: shift(outer), holes: holes.map(shift) };