GeometryMath

GeometryMath

POCS geometry math utilities for tile-based calculations. Ported from: godot/addons/grid_building/core/utils/gb_geometry_math.gd Provides pure math functions for:

  • Tile polygon generation (square, isometric, half-offset)
  • Polygon intersection and overlap detection
  • Polygon bounds calculation
  • Polygon area calculation

Project: GridPlacement v6.0
Layer: Godot
Source: Godot/Core/_incomplete/Systems/Geometry/GeometryMath.cs
Namespace: GridBuilding.Godot
Kind: class

Parsing Method: AST-based (Roslyn) - NOT regex

⚠️ IMPORTANT: This documentation was generated using AST parsing, not regex.

Methods

GetTilePolygon

Gets the polygon vertices for a tile at the given position.

Returns: CoreVector2[]

Parameters:

  • CoreVector2 tilePos
  • CoreVector2 tileSize
  • TileShape tileShape

GetPolygonBounds

Gets the bounding rectangle of a polygon.

Returns: CoreRect2

Parameters:

  • CoreVector2[] polygon

PolygonArea

Calculates the area of a polygon using the shoelace formula. Optimized to avoid modulo operations in the hot loop.

Returns: float

Parameters:

  • CoreVector2[] polygon

DoesPolygonOverlapTile

Checks if a polygon overlaps with a tile.

Returns: bool

Parameters:

  • CoreVector2[] polygon
  • CoreVector2 tilePos
  • CoreVector2 tileSize
  • TileShape tileShape
  • float minOverlapThreshold

IntersectionAreaWithTile

Calculates the intersection area between a polygon and a tile.

Returns: float

Parameters:

  • CoreVector2[] polygon
  • CoreVector2 tilePos
  • CoreVector2 tileSize
  • TileShape tileShape

ClipPolygonToPolygon

Clips a subject polygon to a clip polygon using Sutherland-Hodgman algorithm. Phase 1 & 2 optimizations: ArrayPool, early bounds check, edge caching, and better capacity prediction.

Returns: CoreVector2[]

Parameters:

  • CoreVector2[] subject
  • CoreVector2[] clip

ClipPolygonToRect

Clips a polygon to a rectangle.

Returns: CoreVector2[]

Parameters:

  • CoreVector2[] polygon
  • CoreRect2 rect

RectsOverlap

Checks if two rectangles overlap.

Returns: bool

Parameters:

  • CoreRect2 a
  • CoreRect2 b

PolygonOverlapsRect

Checks if a polygon overlaps with a rectangle. Uses a simplified check based on bounding box first, then detailed intersection.

Returns: bool

Parameters:

  • CoreVector2[] polygon
  • CoreRect2 rect
  • float positionTolerance
  • float areaThreshold

ConvertSizeToPolygon

Converts a RectangleShape2D to a polygon representation with the given transform.

Returns: CoreVector2[]

Parameters:

  • CoreVector2 size
  • Transform2D transform

ConvertRectangleToPolygon

Converts a rectangle shape to a polygon representation.

Returns: CoreVector2[]

Parameters:

  • CoreVector2 size
  • Transform2D transform

ConvertCircleToPolygon

Converts a circle shape to a polygon approximation.

Returns: CoreVector2[]

Parameters:

  • float radius
  • Transform2D transform
  • int segments

ConvertCapsuleToPolygon

Converts a capsule shape to a polygon approximation.

Returns: CoreVector2[]

Parameters:

  • float radius
  • float height
  • Transform2D transform
  • int segments

DoesRectangleOverlapTileOptimized

Checks if a rectangle overlaps with a tile using optimized bounds checking.

Returns: bool

Parameters:

  • CoreVector2 size
  • Transform2D transform
  • CoreVector2 tilePos
  • CoreVector2 tileSize
  • TileShape tileShape
  • float minOverlapThreshold

DoesCircleOverlapTileOptimized

Checks if a circle overlaps with a tile using optimized bounds checking.

Returns: bool

Parameters:

  • float radius
  • Transform2D transform
  • CoreVector2 tilePos
  • CoreVector2 tileSize
  • TileShape tileShape
  • float minOverlapThreshold