CollisionGeometryCalculator

Pure function to check if two polygons intersect

sort Weight: 10

Pure function to check if two polygons intersect

Version: v5.0.0

STABLE

Inherits: RefCounted
Source: collision_geometry_calculator.gd
Parsing: AST-based for maximum accuracy with symbol typing


Constants

AREA_REL_EPS:

when the minimum required overlap is 51.2 (5% of tile area).


AREA_ABS_EPS:

This catches cases where sanitization removes a tiny triangle worth ~1-2 square units.


Methods

_get_polygon_bounds

Signature: static _get_polygon_bounds(polygon: PackedVector2Array) -> Rect2

Pure function to get polygon bounds

Returns: Rect2

Static: true

Parameters:

  • polygon: PackedVector2Array

_clip_polygon_to_edge

Signature: static _clip_polygon_to_edge(polygon: PackedVector2Array, edge_start: Vector2, edge_end: Vector2) -> PackedVector2Array

Used for general polygon-to-polygon clipping

Returns: PackedVector2Array

Static: true

Parameters:

  • polygon: PackedVector2Array
  • edge_start: Vector2
  • edge_end: Vector2

_line_intersection

Signature: static _line_intersection(p1: Vector2, p2: Vector2, p3: Vector2, p4: Vector2) -> Vector2

Returns Vector2.INF if lines don’t intersect

Returns: Vector2

Static: true

Parameters:

  • p1: Vector2
  • p2: Vector2
  • p3: Vector2
  • p4: Vector2

polygons_overlap

Signature: static polygons_overlap(poly1: PackedVector2Array, poly2: PackedVector2Array, min_overlap_ratio: float, reference_area: float) -> bool

Uses Sutherland-Hodgman clipping to compute precise overlap area

Returns: bool

Static: true

Parameters:

  • poly1: PackedVector2Array
  • poly2: PackedVector2Array
  • min_overlap_ratio: float
  • reference_area: float

polygon_overlaps_rect

Signature: static polygon_overlaps_rect(polygon: PackedVector2Array, rect: Rect2, epsilon: float, min_overlap_ratio: float) -> bool

producing accurate overlap areas for all polygon shapes.

Returns: bool

Static: true

Parameters:

  • polygon: PackedVector2Array
  • rect: Rect2
  • epsilon: float
  • min_overlap_ratio: float

_sanitize_polygon

Signature: static _sanitize_polygon(polygon: PackedVector2Array) -> PackedVector2Array

Remove duplicate consecutive points and collinear middle points from polygon

Returns: PackedVector2Array

Static: true

Parameters:

  • polygon: PackedVector2Array

clip_polygon_to_rect

Signature: static clip_polygon_to_rect(polygon: PackedVector2Array, rect: Rect2) -> PackedVector2Array

The algorithm maintains polygon validity and handles edge cases properly.

Returns: PackedVector2Array

Static: true

Parameters:

  • polygon: PackedVector2Array
  • rect: Rect2

point_inside_boundary

Signature: static point_inside_boundary(p: Vector2, boundary: int, left: float, right: float, top: float, bottom: float) -> bool

and ensure inclusive boundary checking.

Returns: bool

Static: true

Parameters:

  • p: Vector2
  • boundary: int
  • left: float
  • right: float
  • top: float
  • bottom: float

_compute_intersection

Signature: static _compute_intersection(a: Vector2, b: Vector2, boundary: int, left: float, right: float, top: float, bottom: float) -> Vector2

Returns: Vector2

Static: true

Parameters:

  • a: Vector2
  • b: Vector2
  • boundary: int
  • left: float
  • right: float
  • top: float
  • bottom: float

polygon_area

Signature: static polygon_area(polygon: PackedVector2Array) -> float

This gives the signed area; we take the absolute value for overlap measurements.

Returns: float

Static: true

Parameters:

  • polygon: PackedVector2Array

point_in_polygon

Signature: static point_in_polygon(point: Vector2, polygon: PackedVector2Array) -> bool

PUBLIC for testing - uses ray casting algorithm for point-in-polygon test

Returns: bool

Static: true

Parameters:

  • point: Vector2
  • polygon: PackedVector2Array

_lines_intersect

Signature: static _lines_intersect(p1: Vector2, p2: Vector2, p3: Vector2, p4: Vector2) -> bool

Pure function to check if two lines intersect

Returns: bool

Static: true

Parameters:

  • p1: Vector2
  • p2: Vector2
  • p3: Vector2
  • p4: Vector2

_polygons_intersect

Signature: static _polygons_intersect(poly1: PackedVector2Array, poly2: PackedVector2Array, epsilon: float) -> bool

Pure function to check if two polygons intersect

Returns: bool

Static: true

Parameters:

  • poly1: PackedVector2Array
  • poly2: PackedVector2Array
  • epsilon: float