GBGeometryUtils

AUTO-GENERATED FILE – DO NOT EDIT MANUALLY

Utility functions for geometry calculations and shape operations.

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

Public Methods

points_array_to_rect_2d

1
2
3
4
points_array_to_rect_2d(
    p_vector_array: PackedVector2Array,
    p_rect_position: Vector2
) -> Rect2

Flags: static

Converts an array of Vector2 points to a bounding Rect2. Returns a Rect2 that bounds all points in the given PackedVector2Array, with the origin at p_rect_position.


get_collision_object_shapes

1
get_collision_object_shapes(p_collision_object: CollisionObject2D) -> Array[Shape2D]

Flags: static

Returns all Shape2D instances owned by a CollisionObject2D.

p_collision_object: CollisionObject2D - Collision object to extract shapes from


get_all_collision_shapes_by_owner

1
get_all_collision_shapes_by_owner(root_node: Node2D) -> Dictionary[Node2D, Array]

Flags: static

Returns a dictionary mapping each collidable node (CollisionObject2D or CollisionPolygon2D) to its array of Shape2D objects. This allows you to check collision layers/masks and know which shapes belong to which node. Supports both standard collision objects and polygon-defined collision shapes. Recursively returns a dictionary mapping each collidable node (CollisionObject2D or CollisionPolygon2D) to its array of Shape2D objects. Includes root and all children. Useful for mapping collision owners to their shapes for collision checks.


get_shapes_from_owner

1
get_shapes_from_owner(p_owner: Node2D) -> Array[Shape2D]

Flags: static

Helper to get all shape 2Ds that a owner Node2D has. Returns all Shape2D objects owned by a Node2D (CollisionObject2D or CollisionPolygon2D). Converts polygons to ConvexPolygonShape2D if possible.

p_owner: Node2D - Node to extract shapes from (CollisionObject2D or CollisionPolygon2D)


grow_rect2_to_increment

1
2
3
4
grow_rect2_to_increment(
    p_rect: Rect2,
    p_increment: Vector2
) -> Rect2

Flags: static

Grows a rect2 by the given increment values Returns a Rect2 grown by the given increment vector, handling negative sizes correctly. Useful for expanding bounding boxes or shapes by a margin.


grow_rect2_to_square

1
grow_rect2_to_square(p_rect: Rect2) -> Rect2

Flags: static

Returns a square Rect2 that fully contains the input Rect2, rounding up to the largest dimension. Useful for fitting non-square shapes into square tiles or grids.


get_rect2_position_offset

1
get_rect2_position_offset(p_rect: Rect2) -> Vector2

Flags: static

Gets the direction difference between center to position and center to end

Returns the difference vector with magnitude and direction of the further point between position and end Returns the offset vector from the center to the position of a Rect2. Useful for calculating position differences or alignment offsets.


get_overlapped_tiles_for_rect

1
2
3
4
5
6
get_overlapped_tiles_for_rect(
    rect_center: Vector2,
    rect_size: Vector2,
    tile_map: TileMapLayer,
    epsilon: float = 0.1
) -> Array[Vector2i]

Flags: static

Returns all tile positions overlapped by a rectangle, with a small buffer (epsilon) to avoid counting adjacent tiles for exact fits. Useful for mapping which tiles are covered by a rectangular shape in a TileMapLayer.


is_tile_covered_by_collision_shape

1
2
3
4
5
6
7
is_tile_covered_by_collision_shape(
    tile_pos: Vector2,
    tile_size: Vector2,
    collision_shape: CollisionShape2D,
    tile_type: TileSet.TileShape,
    epsilon: float = 0.01
) -> bool

Flags: static

Checks if a tile is covered by a CollisionShape2D (using Geometry2D intersection) Returns true if a tile is covered by a CollisionShape2D, using intersection area (with epsilon threshold). Useful for strict collision checks between tiles and collision shapes. tile_type: TileSet.TileShape (required) epsilon: minimum intersection area to count as covered (default 0.01)


is_tile_covered_by_collision_polygon

1
2
3
4
5
6
7
is_tile_covered_by_collision_polygon(
    tile_pos: Vector2,
    tile_size: Vector2,
    collision_polygon: CollisionPolygon2D,
    tile_type: TileSet.TileShape,
    epsilon: float = 0.01
) -> bool

Flags: static

Checks if a tile is covered by a CollisionPolygon2D (using Geometry2D intersection) Returns true if a tile is covered by a CollisionPolygon2D, using intersection area (with epsilon threshold). Useful for strict collision checks between tiles and collision polygons. tile_type: TileSet.TileShape (required) epsilon: minimum intersection area to count as covered (default 0.01)