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:
@@ -156,10 +156,12 @@ def _sample_edge_polyline(edge: Any, chord_tol_mm: float, lister: Any = None) ->
|
|||||||
except Exception:
|
except Exception:
|
||||||
length = _norm(_sub(p2, p1)) if not is_closed else 50.0
|
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)))
|
n_pts = max(8, int(math.ceil(length / tol)))
|
||||||
if is_circular or is_closed:
|
if is_circular or is_closed:
|
||||||
n_pts = max(24, n_pts)
|
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:
|
if is_linear and not is_closed:
|
||||||
return [p1, p2]
|
return [p1, p2]
|
||||||
@@ -377,7 +379,7 @@ def _chain_edges_into_loops(
|
|||||||
edges: List[Any],
|
edges: List[Any],
|
||||||
lister: Any = None,
|
lister: Any = None,
|
||||||
tol: float = 0.01,
|
tol: float = 0.01,
|
||||||
chord_tol_mm: float = 0.1,
|
chord_tol_mm: float = 1.0,
|
||||||
) -> List[Tuple[bool, List[Point3D]]]:
|
) -> List[Tuple[bool, List[Point3D]]]:
|
||||||
"""
|
"""
|
||||||
Chain edges into closed loops by matching vertex endpoints.
|
Chain edges into closed loops by matching vertex endpoints.
|
||||||
@@ -747,7 +749,7 @@ def extract_sandbox_geometry(
|
|||||||
body: Any,
|
body: Any,
|
||||||
sandbox_id: str,
|
sandbox_id: str,
|
||||||
lister: Any,
|
lister: Any,
|
||||||
chord_tol_mm: float = 0.1,
|
chord_tol_mm: float = 1.0,
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Extract a sandbox face into a JSON-serializable dict.
|
Extract a sandbox face into a JSON-serializable dict.
|
||||||
@@ -859,7 +861,7 @@ def main():
|
|||||||
body=body,
|
body=body,
|
||||||
sandbox_id=sandbox_id,
|
sandbox_id=sandbox_id,
|
||||||
lister=lister,
|
lister=lister,
|
||||||
chord_tol_mm=0.1,
|
chord_tol_mm=1.0,
|
||||||
)
|
)
|
||||||
|
|
||||||
out_path = os.path.join(output_dir, f"geometry_{sandbox_id}.json")
|
out_path = os.path.join(output_dir, f"geometry_{sandbox_id}.json")
|
||||||
|
|||||||
Reference in New Issue
Block a user