fix(extract): increase chord tolerance to 1mm, cap at 500 pts/edge

0.1mm was generating thousands of unnecessary points on straight
edges. Now: 1mm default, 0.5mm minimum, 500 max per edge.
Curves still get proper sampling, straight edges stay lean.
This commit is contained in:
2026-02-17 01:40:55 +00:00
parent c3125b458b
commit abc7d5f013

View File

@@ -156,10 +156,12 @@ def _sample_edge_polyline(edge: Any, chord_tol_mm: float, lister: Any = None) ->
except Exception:
length = _norm(_sub(p2, p1)) if not is_closed else 50.0
tol = max(float(chord_tol_mm), 0.01)
tol = max(float(chord_tol_mm), 0.5) # 0.5mm chord tolerance — good balance
n_pts = max(8, int(math.ceil(length / tol)))
if is_circular or is_closed:
n_pts = max(24, n_pts)
# Cap to avoid absurd point counts on long straight edges
n_pts = min(n_pts, 500)
if is_linear and not is_closed:
return [p1, p2]
@@ -377,7 +379,7 @@ def _chain_edges_into_loops(
edges: List[Any],
lister: Any = None,
tol: float = 0.01,
chord_tol_mm: float = 0.1,
chord_tol_mm: float = 1.0,
) -> List[Tuple[bool, List[Point3D]]]:
"""
Chain edges into closed loops by matching vertex endpoints.
@@ -747,7 +749,7 @@ def extract_sandbox_geometry(
body: Any,
sandbox_id: str,
lister: Any,
chord_tol_mm: float = 0.1,
chord_tol_mm: float = 1.0,
) -> Dict[str, Any]:
"""
Extract a sandbox face into a JSON-serializable dict.
@@ -859,7 +861,7 @@ def main():
body=body,
sandbox_id=sandbox_id,
lister=lister,
chord_tol_mm=0.1,
chord_tol_mm=1.0,
)
out_path = os.path.join(output_dir, f"geometry_{sandbox_id}.json")