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 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.

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.