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: Core
Source: Core/_incomplete/Systems/Geometry/GeometryMath.cs
Namespace: GridBuilding.Core
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 tilePosCoreVector2 tileSizeTileShape 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[] polygonCoreVector2 tilePosCoreVector2 tileSizeTileShape tileShapefloat minOverlapThreshold
IntersectionAreaWithTile
Calculates the intersection area between a polygon and a tile.
Returns: float
Parameters:
CoreVector2[] polygonCoreVector2 tilePosCoreVector2 tileSizeTileShape 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[] subjectCoreVector2[] clip
ClipPolygonToRect
Clips a polygon to a rectangle.
Returns: CoreVector2[]
Parameters:
CoreVector2[] polygonCoreRect2 rect
RectsOverlap
Checks if two rectangles overlap.
Returns: bool
Parameters:
CoreRect2 aCoreRect2 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[] polygonCoreRect2 rectfloat positionTolerancefloat areaThreshold
ConvertSizeToPolygon
Converts a RectangleShape2D to a polygon representation with the given transform.
Returns: CoreVector2[]
Parameters:
CoreVector2 sizeTransform2D transform
ConvertRectangleToPolygon
Converts a rectangle shape to a polygon representation.
Returns: CoreVector2[]
Parameters:
CoreVector2 sizeTransform2D transform
ConvertCircleToPolygon
Converts a circle shape to a polygon approximation.
Returns: CoreVector2[]
Parameters:
float radiusTransform2D transformint segments
ConvertCapsuleToPolygon
Converts a capsule shape to a polygon approximation.
Returns: CoreVector2[]
Parameters:
float radiusfloat heightTransform2D transformint segments
DoesRectangleOverlapTileOptimized
Checks if a rectangle overlaps with a tile using optimized bounds checking.
Returns: bool
Parameters:
CoreVector2 sizeTransform2D transformCoreVector2 tilePosCoreVector2 tileSizeTileShape tileShapefloat minOverlapThreshold
DoesCircleOverlapTileOptimized
Checks if a circle overlaps with a tile using optimized bounds checking.
Returns: bool
Parameters:
float radiusTransform2D transformCoreVector2 tilePosCoreVector2 tileSizeTileShape tileShapefloat minOverlapThreshold