GridPosition
AUTO-GENERATED FILE – DO NOT EDIT MANUALLY
This page documents the supported public API surface only. Private, internal, benchmark, test, and implementation-detail types are intentionally omitted.
Declaration
Summary
Represents a position in 2D grid coordinates with utility methods for coordinate conversion.
Provides POCS implementation of grid positioning logic without Godot dependencies. Supports conversion between world coordinates and grid coordinates, adjacency calculations, and grid-based movement operations.
Ported from: godot/addons/grid_building/shared/utils/positioning/gb_positioning_2d_utils.gd
Metadata
Namespace: GridPlacement.Core.Grid
Source File: cs/Core/Types/GridPosition.cs
Assembly: GridPlacement.Core
Type: struct
Implements
IEquatable<GridPosition>
Constructors
GridPosition
Initializes a new instance of the GridPosition struct.
Parameters
| Name | Description |
|---|---|
x | The X coordinate in grid space. |
y | The Y coordinate in grid space. |
tileSize | The tile size in world units. If default, a 64x64 tile size is used. |
GridPosition
Initializes a new instance of the GridPosition struct from a CoreVector2I.
Parameters
| Name | Description |
|---|---|
vector2I | The grid-space vector. |
tileSize | The tile size in world units. If default, a 64x64 tile size is used. |
Fields
X
X coordinate (column) in grid space.
Y
Y coordinate (row) in grid space.
TileSize
Tile size in world units (pixels). Default is 64x64.
Zero
Gets the zero grid position (0,0).
One
Gets the unit grid position (1,1).
Methods
ToWorldCoordinates
Convert grid position to world coordinates (tile center).
ToWorldCoordinates
Convert grid position to world coordinates with custom tile size.
FromWorldCoordinates
Convert world coordinates to grid position.
ManhattanDistanceTo
Get the Manhattan distance to another grid position.
ChebyshevDistanceTo
Get the Chebyshev distance (king’s move distance) to another grid position.
IsAdjacentTo
Check if this position is adjacent to another position (including diagonals).
GetAdjacentPositions
Get all adjacent positions (8-directional).
GetOrthogonalPositions
Get orthogonal adjacent positions (4-directional).
MoveInDirection
Move in a cardinal direction.
Clamp
Clamp position within a rectangular region.
IsWithinRegion
Check if position is within a rectangular region.
op_Addition
Adds two grid positions component-wise.
op_Subtraction
Subtracts two grid positions component-wise.
op_Multiply
Multiplies a grid position by a scalar.
op_Equality
Determines whether two grid positions are equal.
op_Inequality
Determines whether two grid positions are not equal.
op_Implicit
Converts a GridPosition to a CoreVector2I.
op_Explicit
Converts a CoreVector2I to a GridPosition.
Equals
Determines whether this instance is equal to another GridPosition.
Equals
GetHashCode
ToString
GetDirectionTo
Get the direction to another position.
GetLineTo
Get all positions in a line from this position to target.
GetPositionsInRadius
Get positions in a radius around this position.
GetPositionsInRectangle
Get positions in a rectangle around this position.