GBGeometryMath

AUTO-GENERATED FILE – DO NOT EDIT MANUALLY

Geometry & collision math utilities for the grid building addon.

Source File: addons/grid_building/utils/gb_geometry_math.gd

Public Methods

polygon_intersection_area

1
2
3
4
polygon_intersection_area(
    poly_a: PackedVector2Array,
    poly_b: PackedVector2Array
) -> float

Flags: static

Returns the intersection area between two polygons using Godot’s Geometry2D.

poly_a: PackedVector2Array - First polygon.

poly_b: PackedVector2Array - Second polygon.

Returns: float - Area of intersection (0.0 if no overlap).


get_tile_polygon

1
2
3
4
5
get_tile_polygon(
    tile_top_left_pos: Vector2,
    tile_size: Vector2,
    tile_shape: TileSet.TileShape
) -> PackedVector2Array

Flags: static

Returns the corners of a tile as a polygon for collision or geometry checks.

tile_top_left_pos: Vector2 - Top-left position of the tile in world space.

tile_size: Vector2 - Size of the tile (width, height).

tile_shape: TileSet.TileShape - Tile shape from TileSet (SQUARE, ISOMETRIC, HALF_OFFSET_SQUARE).

Returns: PackedVector2Array - Polygon corners in counterclockwise order.


intersection_area_with_tile

1
2
3
4
5
6
intersection_area_with_tile(
    polygon: PackedVector2Array,
    tile_top_left_pos: Vector2,
    tile_size: Vector2,
    tile_shape: TileSet.TileShape
) -> float

Flags: static

Returns the intersection area between a polygon and a tile polygon.

polygon: PackedVector2Array - The polygon to check.

tile_top_left_pos: Vector2 - Top-left position of the tile in world space (not center).

tile_size: Vector2 - Size of the tile (width, height).

tile_shape: TileSet.TileShape - Tile shape from TileSet (SQUARE, ISOMETRIC, etc.).

Returns: float - Area of intersection (0.0 if no overlap).


does_polygon_overlap_tile

1
2
3
4
5
6
7
does_polygon_overlap_tile(
    polygon: PackedVector2Array,
    tile_top_left_pos: Vector2,
    tile_size: Vector2,
    tile_shape: TileSet.TileShape,
    epsilon: float
) -> bool

Flags: static

Returns true if the intersection area between a polygon and a tile polygon exceeds epsilon.

polygon: PackedVector2Array - The polygon to check.

tile_top_left_pos: Vector2 - Top-left position of the tile in world space (not center).

tile_size: Vector2 - Size of the tile (width, height).

tile_shape: TileSet.TileShape - Tile shape from TileSet (SQUARE, ISOMETRIC, etc.).

epsilon: float - Minimum intersection area to count as covered.

Returns: bool - True if intersection area > epsilon.


does_shape_overlap_tile_optimized

1
2
3
4
5
6
7
8
does_shape_overlap_tile_optimized(
    shape: Shape2D,
    shape_transform: Transform2D,
    tile_top_left_pos: Vector2,
    tile_size: Vector2,
    tile_shape: TileSet.TileShape,
    epsilon: float = 0.01
) -> bool

Flags: static

Optimized collision detection using native Godot collision as primary method.

shape: Shape2D - The collision shape to test.

shape_transform: Transform2D - Transform of the shape.

tile_top_left_pos: Vector2 - Top-left position of the tile in world space (not center).

tile_size: Vector2 - Size of the tile.

tile_shape: TileSet.TileShape - Tile shape from TileSet (SQUARE, ISOMETRIC, HALF_OFFSET_SQUARE).

epsilon: float - Minimum overlap area (only used for polygon fallback).

Returns: bool - True if shape overlaps the tile.


does_polygon_overlap_tile_optimized

1
2
3
4
5
6
7
does_polygon_overlap_tile_optimized(
    polygon: PackedVector2Array,
    tile_top_left_pos: Vector2,
    tile_size: Vector2,
    tile_shape: TileSet.TileShape,
    epsilon: float = 0.01
) -> bool

Flags: static

Optimized polygon overlap detection - uses native collision when possible.

polygon: PackedVector2Array - The polygon points to test.

tile_top_left_pos: Vector2 - Top-left position of the tile in world space (not center).

tile_size: Vector2 - Size of the tile.

tile_shape: TileSet.TileShape - Tile shape from TileSet (SQUARE, ISOMETRIC, HALF_OFFSET_SQUARE).

epsilon: float - Minimum intersection area threshold.

Returns: bool - True if polygon overlaps the tile significantly.


get_polygon_bounds

1
get_polygon_bounds(polygon: PackedVector2Array) -> Rect2

Flags: static

Returns the bounding rectangle of a polygon.

polygon: PackedVector2Array - The polygon points.

Returns: Rect2 - Bounding rectangle of the polygon.


convert_shape_to_polygon

1
2
3
4
convert_shape_to_polygon(
    shape: Shape2D,
    transform: Transform2D
) -> PackedVector2Array

Flags: static

Converts a Shape2D to a polygon for consistent processing.

shape: Shape2D - The shape to convert.

transform: Transform2D - Transform to apply to the shape.

Returns: PackedVector2Array - Polygon representation of the shape.


intersection_polygon_area

1
intersection_polygon_area(points: PackedVector2Array) -> float

Flags: static

Calculates the area of a polygon defined by a PackedVector2Array. Used to determine the area of intersection between two polygons (e.g., tile and collision shape). Returns 0.0 if the input does not form a valid polygon (fewer than 3 points). This is used in overlap checks to ensure that only true area overlaps (not just edge or point contacts) are counted.


is_exact_polygon_match

1
2
3
4
is_exact_polygon_match(
    poly_a: PackedVector2Array,
    poly_b: PackedVector2Array
) -> bool

Flags: static

Checks if two polygons are exactly the same (vertex by vertex)


exact_polygon_area

1
exact_polygon_area(poly: PackedVector2Array) -> float

Flags: static

Returns area for exact polygon match


Private Methods

_is_axis_aligned_rectangle

1
_is_axis_aligned_rectangle(polygon: PackedVector2Array) -> bool

Flags: static, private

Returns true if the polygon is an axis-aligned rectangle (all edges horizontal or vertical).

polygon: PackedVector2Array - Polygon to check.

Returns: bool - True if axis-aligned rectangle.