Skip to content

GBGeometryUtils

Utility functions for geometry calculations and shape operations.

Provides static methods for working with collision shapes, bounding boxes, and coordinate transformations in grid building contexts.

static func points_array_to_rect_2d( p_vector_array: PackedVector2Array, p_rect_position: Vector2 ) -> Rect2

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.

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

Returns all Shape2D instances owned by a CollisionObject2D.

p_collision_object: CollisionObject2D - Collision object to extract shapes from

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

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.

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

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)

static func grow_rect2_to_increment( p_rect: Rect2, p_increment: Vector2 ) -> Rect2

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.

static func grow_rect2_to_square( p_rect: Rect2 ) -> Rect2

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.

static func get_rect2_position_offset( p_rect: Rect2 ) -> Vector2

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.

static func get_overlapped_tiles_for_rect( rect_center: Vector2, rect_size: Vector2, tile_map: TileMapLayer, epsilon: float ) -> Array[Vector2i]

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.

static func is_tile_covered_by_collision_shape( tile_pos: Vector2, tile_size: Vector2, collision_shape: CollisionShape2D, tile_type: TileSet.TileShape, epsilon: float ) -> bool

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)

static func is_tile_covered_by_collision_polygon( tile_pos: Vector2, tile_size: Vector2, collision_polygon: CollisionPolygon2D, tile_type: TileSet.TileShape, epsilon: float ) -> bool

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)

addons/grid_building/utils/gb_geometry_utils.gd


This API reference is automatically generated from the plugin source code. For implementation examples and usage guides, see the guides section.