fix(Medium2D): fix subdivision when merged geometry is a polygon with holes #3018
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Greptile Overview
Greptile Summary
Fixed handling of polygons with holes (interiors) in the
subdivide()function. When merged geometry results in a polygon with holes, the function now properly converts it into aPolySlabwith subtraction operations usingGeometryGroup. The fix also includes a refactoring ofevaluate_inf_shape()to extract coordinate processing into a helper function for better code organization.shapely_to_polyslab()helper function in utils_2d.py:125 to handle polygons with interior holes by creating aClipOperationwith difference operationevaluate_inf_shape()in base.py:724 to use_processed_coords()helper for cleaner coordinate processingtest_subdivide_geometry_group_with_polygon_holes()that verifies the fix by checking forClipOperationwith difference operation in finalized structuresConfidence Score: 4/5
shapely_to_polyslab()is incorrect - it declares-> PolySlabbut can returnClipOperationwhen holes exist. This won't cause runtime issues since the outer function expectsGeometry, but it creates type checking inconsistency.Important Files Changed
File Analysis
evaluate_inf_shape()to extract coordinate processing into helper function for better code organizationSequence Diagram
sequenceDiagram participant Sim as Simulation participant Sub as subdivide() participant STP as shapely_to_polyslab() participant Geo as Geometry participant CO as ClipOperation Sim->>Sub: subdivide(geom, structures) Note over Sub: Process geometry with<br/>neighboring structures Sub->>Sub: Convert shapely polygons<br/>to multipolygon loop For each polygon Sub->>STP: shapely_to_polyslab(polygon, axis, center) alt Polygon has no holes STP->>Geo: Create PolySlab with exterior vertices Geo-->>STP: Return PolySlab else Polygon has holes (interiors) STP->>Geo: Create PolySlab with exterior vertices STP->>Geo: Create PolySlab for each interior STP->>Geo: Create GeometryGroup from interiors STP->>CO: polyslab - GeometryGroup Note over CO: Creates ClipOperation<br/>with operation="difference" CO-->>STP: Return ClipOperation end STP-->>Sub: Return Geometry (PolySlab or ClipOperation) end Sub-->>Sim: Return list of (Geometry, Structure, Structure) Note over Sim: Finalized structures contain<br/>ClipOperation with difference operation