Struct SquareGridLayout
Defines the spatial layout of a square grid by specifying the physical size of each cell and the world-space position of the grid origin, and provides the conversions between grid coordinates and world-space positions.
Implements
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public readonly struct SquareGridLayout : IEquatable<SquareGridLayout>
Remarks
The layout maps SquareCoord values to Unity world-space
UnityEngine.Vector2 positions. Cell (0, 0) occupies the rectangle
[OriginX, OriginY] to [OriginX + CellWidth, OriginY + CellHeight], and
its center is at (OriginX + CellWidth*0.5, OriginY + CellHeight*0.5).
GridToWorld(SquareCoord) returns the center of a cell; to find the top-left corner subtract half the cell dimensions from that result. WorldToGrid(Vector2) uses Floor(float) so it correctly handles positions in cells with negative column or row indices.
A SquareGridLayout is passed to ScyllaSquareGrid<TCell> and
ScyllaSparseSquareGrid<TCell> at construction time and can be retrieved
later via their Layout property.
Equality comparison uses exact floating-point equality (no epsilon). Two layout values constructed from the same literals are equal; layouts computed through different arithmetic paths may differ due to floating-point rounding.
Constructors
SquareGridLayout(float, float, float, float)
Creates a new square grid layout with the specified cell dimensions and optional origin.
Declaration
public SquareGridLayout(float cellWidth, float cellHeight, float originX = 0, float originY = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| float | cellWidth | The width of each cell in world units. Must be a finite number strictly greater than zero. |
| float | cellHeight | The height of each cell in world units. Must be a finite number strictly greater than zero. |
| float | originX | The X coordinate of the grid origin in world space. Defaults to |
| float | originY | The Y coordinate of the grid origin in world space. Defaults to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
Fields
CellHeight
The height of each cell in world units. Always a positive finite number.
Declaration
public readonly float CellHeight
Field Value
| Type | Description |
|---|---|
| float |
CellWidth
The width of each cell in world units. Always a positive finite number.
Declaration
public readonly float CellWidth
Field Value
| Type | Description |
|---|---|
| float |
OriginX
The X coordinate of the grid origin in world space.
Cell (0, 0) begins at this X position and its center is at OriginX + CellWidth * 0.5.
Declaration
public readonly float OriginX
Field Value
| Type | Description |
|---|---|
| float |
OriginY
The Y coordinate of the grid origin in world space.
Cell (0, 0) begins at this Y position and its center is at OriginY + CellHeight * 0.5.
Declaration
public readonly float OriginY
Field Value
| Type | Description |
|---|---|
| float |
Methods
Equals(SquareGridLayout)
Determines whether this layout equals other using exact
floating-point equality on all four parameters.
Declaration
public bool Equals(SquareGridLayout other)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareGridLayout | other | The layout to compare with. |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
Two layouts are equal only when all four fields have bitwise-identical float values. Layouts derived from different arithmetic paths may not compare equal even if they represent the same logical grid.
Equals(object)
Determines whether this layout equals an arbitrary object.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with. May be |
Returns
| Type | Description |
|---|---|
| bool |
|
Overrides
GetHashCode()
Returns a hash code for this layout based on all four layout parameters.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code suitable for use in hash-based collections such as Dictionary<TKey, TValue>. |
Overrides
GridToWorld(SquareCoord)
Converts a grid coordinate to the world-space position of the cell's center.
Declaration
public Vector2 GridToWorld(SquareCoord coord)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareCoord | coord | The grid coordinate to convert. |
Returns
| Type | Description |
|---|---|
| Vector2 | The world-space UnityEngine.Vector2 at the center of the cell identified by
|
Remarks
The returned position is the center of the cell, not its corner. To find the
top-left corner of cell (c, r), compute
new Vector2(c * CellWidth + OriginX, r * CellHeight + OriginY).
ToString()
Returns a human-readable string describing the cell size and origin of this layout.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string in the format
|
Overrides
WorldToGrid(Vector2)
Converts a world-space position to the grid coordinate of the cell that contains it.
Declaration
public SquareCoord WorldToGrid(Vector2 worldPos)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | worldPos | The world-space position to convert. |
Returns
| Type | Description |
|---|---|
| SquareCoord | The SquareCoord of the cell whose bounding rectangle contains
|
Remarks
Uses Floor(float) so that positions inside cells with negative column or
row indices map to the correct cell. For example, a world position at
(-0.3, -0.7) with a 1x1 grid origin at (0, 0) maps to cell (-1, -1).
Operators
operator ==(SquareGridLayout, SquareGridLayout)
Returns true if left and right have
exactly equal cell dimensions and origin coordinates.
Declaration
public static bool operator ==(SquareGridLayout left, SquareGridLayout right)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareGridLayout | left | |
| SquareGridLayout | right |
Returns
| Type | Description |
|---|---|
| bool |
operator !=(SquareGridLayout, SquareGridLayout)
Returns true if left and right differ
in at least one layout parameter.
Declaration
public static bool operator !=(SquareGridLayout left, SquareGridLayout right)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareGridLayout | left | |
| SquareGridLayout | right |
Returns
| Type | Description |
|---|---|
| bool |