CollisionGeometryUtils
AUTO-GENERATED FILE – DO NOT EDIT MANUALLY
Pure, stateless helpers used by the placement/collision mapping pipeline. These functions are extracted from the runtime mapper to allow focused unit tests and reuse from multiple contexts without side-effects.
Source File: addons/grid_building/utils/collision_geometry_utils.gd
Extends: RefCounted
Public Methods
build_shape_transform
Flags: static
Dependency: Calculator providing pure geometry operations such as polygontile overlap.
Builds a world transform for a specific collision shape_owner
attached to a col_obj (the owning Node2D).
Order of operations
- Apply the object’s rotation and scale.
- Apply the shape owner’s local rotation and scale.
- Apply the shape owner’s local offset (position) in the object’s rotated/scaled space.
Returns identity when inputs are invalid.
Parameters
col_obj: Node2D— The collision object (owner of the shape).shape_owner: Node2D— The node that carries the local transform for the shape.
Returns
Transform2D— World transform for the individual shape owner.
Notes
- Keeps parity with legacy mapper logic; use when composing per-shape transforms.
- Does not consider a TileMap’s transform; see the
center_tile_for_*helpers for world↔local conversions against TileMap layers.
to_world_polygon
Flags: static
Converts a CollisionPolygon2D to world-space points.
Applies the node’s global transform to each local polygon vertex.
Returns an empty array when polygon_node is null.
Parameters
polygon_node: CollisionPolygon2D
Returns
PackedVector2Array— World-space vertices.
compute_tile_iteration_range
Flags: static
Converts world-space bounds to a tile iteration range.
Mirrors mapper iteration by computing the inclusive start tile and an exclusive end tile using the TileMap layer’s transform. A small epsilon is subtracted from the max corner to avoid fencepost inclusion of a tile when the bounds sit exactly on a tile border.
Parameters
bounds: Rect2— World-space AABB to iterate over.map: TileMapLayer— Target TileMap layer.
Returns
Dictionary— {"start" : Vector2i,"end_exclusive" : Vector2i}
center_tile_for_polygon_positioner
Flags: static
Computes the center tile for a polygon positioner node on a given TileMap layer.
Uses map.to_local() followed by local_to_map() to respect map transforms.
Returns Vector2i.ZERO if inputs are invalid.
Parameters
map: TileMapLayerpositioner: Node2D
Returns
Vector2i— Tile coordinates of the center.
center_tile_for_shape_object
Flags: static
Computes the center tile for a collision shape-carrying object on a TileMap layer.
Uses map.to_local() followed by local_to_map() to respect map transforms.
Returns Vector2i.ZERO if inputs are invalid.
Parameters
map: TileMapLayercol_obj: Node2D
Returns
Vector2i— Tile coordinates of the center.
compute_polygon_tile_offsets
Flags: static
Computes tile offsets covered by a world-space polygon relative to a center_tile.
This delegates to CollisionGeometryCalculator.calculate_tile_overlap() with conservative
defaults suitable for unit tests.
Thresholds
- Edge epsilon:
0.01(1% of tile size) - Min area fraction:
0.05(5% of tile area)
Parameters
world_points: PackedVector2Array— Polygon in world space.tile_size: Vector2— Size of a tile in world units.center_tile: Vector2i— Origin tile for computing offsets.tile_type: TileSet.TileShape = TileSet.TILE_SHAPE_SQUARE— Tile shape type.
Returns
Array[Vector2i]— Offsets fromcenter_tilefor all overlapped tiles.
Notes
- The production mapper may use different thresholds per shape type; these test defaults are intentionally conservative and stable.
is_polygon_convex
Flags: static
Checks strict convexity of a polygon (winding-agnostic).
Uses cross product sign consistency and ignores collinear or duplicate edges. Triangles are considered convex.
Parameters
points: PackedVector2Array
Returns
bool—trueif the polygon is strictly convex; otherwisefalse.