Grid Placement

CollisionGeometryCalculator

AUTO-GENERATED FILE — DO NOT EDIT MANUALLY

Source: placement/manager/components/collision_geometry_calculator.gd

Version: 5.0

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:

  1. The polygon is clipped against each of the 4 rectangle boundaries (left, right, top, bottom)
  2. Each clipping operation produces a new polygon that is guaranteed to be inside that boundary
  3. The final clipped polygon represents the intersection area between the original polygon and rectangle
  4. 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)