CollisionGeometryCalculator
AUTO-GENERATED FILE — DO NOT EDIT MANUALLY
Source: systems/placement/managers/collision_geometry_calculator.gd
Version: 5.1
class_name: CollisionGeometryCalculator
extends: RefCounted
Summary
Pure logic class for collision geometry calculations. Contains no state and can be easily tested in isolation.
POLYGON CLIPPING ALGORITHM - SUTHERLAND-HODGMAN
This class implements the Sutherland-Hodgman polygon clipping algorithm for determining polygon-rectangle overlap areas. The algorithm is correct for both convex and concave polygons.
Algorithm Overview:
- The polygon is clipped against each of the 4 rectangle boundaries (left, right, top, bottom)
- Each clipping operation produces a new polygon that is guaranteed to be inside that boundary
- The final clipped polygon represents the intersection area between the original polygon and rectangle
- The area of this clipped polygon determines if the overlap meets the minimum threshold
Why Sutherland-Hodgman is Correct:
- Works for both convex and concave polygons (unlike some simpler algorithms)
- Produces a valid polygon as output (no self-intersections or invalid geometry)
- Handles edge cases like polygons completely inside/outside the rectangle
- Deterministic and numerically stable with proper epsilon handling
Default Overlap Thresholds:
- Edge epsilon: 0.01 (1% tolerance for numerical precision)
- Minimum overlap ratio: 0.05 (5% of tile area required for detection)
- Polygons with < 5% tile overlap are considered non-overlapping (prevents spurious micro-overlaps)
Key Methods:
- clip_polygon_to_rect(): Implements the core Sutherland-Hodgman algorithm
- polygon_overlaps_rect(): Uses clipping to determine if overlap meets threshold
- polygon_area(): Calculates area using shoelace formula for overlap measurement
Testing: All clipping methods are public for comprehensive unit testing validation.
Signals
(none)
Exports
(none)
Methods
(none)