Skip to content

Filter degenerate decomposition cells and short-circuit sweep generation for near-zero-area polygons#33

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-degenerate-sub-polygons
Draft

Filter degenerate decomposition cells and short-circuit sweep generation for near-zero-area polygons#33
Copilot wants to merge 2 commits intomainfrom
copilot/fix-degenerate-sub-polygons

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

decompose_polygon() could return zero/near-zero-area cells from CGAL decomposition, and forwarding those cells to generate_sweep_pattern() could trigger CGAL orientation errors or numeric failures. This PR adds area-based guards at both boundaries so degenerate polygons are excluded before sweep computation.

  • Area thresholds for degenerate geometry handling

    • Added module-level minimum-area constants in trajgenpy/Geometries.py:
      • MIN_DECOMPOSE_POLYGON_AREA = 1.0
      • MIN_SWEEP_POLYGON_AREA = 1.0
    • Documented thresholds as CRS units² and explicitly tied them to degenerate-cell protection.
  • Decomposition output filtering

    • Updated decompose_polygon() to filter sub-polygons returned by bindings.decompose(...).
    • Cells with area below MIN_DECOMPOSE_POLYGON_AREA are dropped before return.
  • Sweep generation safety guard

    • Updated generate_sweep_pattern() to return [] immediately when polygon.area < MIN_SWEEP_POLYGON_AREA.
    • This prevents below-threshold polygons from reaching bindings.generate_sweeps(...).
  • Regression coverage

    • Added tests in tests/test_geometries.py for:
      • filtering of below-threshold cells in decompose_polygon()
      • early empty-return behavior in generate_sweep_pattern() and no call-through to bindings for small polygons
if polygon.area < MIN_SWEEP_POLYGON_AREA:
    return []

polygons_list = [
    shapely.Polygon([(vertex.x, vertex.y) for vertex in polygon])
    for polygon in decompose_polygons
]
return [polygon for polygon in polygons_list if polygon.area >= MIN_DECOMPOSE_POLYGON_AREA]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants