GridService2D

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

1
public sealed class GridService2D

Summary

Contract: Provides grid metadata (tile size + origin) and deterministic conversion between world space (CoreVector2) and grid space (CoreVector2I) for a uniform 2D grid.

Coordinate / rounding rules:

  • Origin defines the world-space origin of grid cell (0,0) (the grid “anchor”).
  • WorldToGrid uses floor(local / tileSize) per-axis (not rounding).
  • GridToWorld returns the world-space center of a cell.

Edge cases:

  • If a tile size component is 0, that axis maps to 0 in WorldToGrid.
  • No bounds checking is performed; negative coordinates are valid.

Metadata

Namespace: GridPlacement.Core.Services.Grid

Source File: cs/Core/Services/Grid/GridService2D.cs

Assembly: GridPlacement.Core

Type: class

Constructors

GridService2D

1
public GridService2D(GridState2D state)

Creates a grid conversion service.

Parameters

NameDescription
stateGrid state containing tile size and origin.

GridService2D

1
2
3
4
public GridService2D(
    CoreVector2? tileSize = null,
    CoreVector2? origin = null
)

Creates a grid conversion service with optional tile size and origin.

Parameters

NameDescription
tileSizeOptional tile size. Defaults to (64, 64).
originOptional origin. Defaults to (0, 0).

Properties

TileSize

1
public CoreVector2 TileSize { get; set; }

Gets or sets the dimensions of a single grid tile in world units.


Origin

1
public CoreVector2 Origin { get; set; }

Gets or sets the world-space origin of the grid cell at (0, 0).


TargetMap

1
public IGridMap2D? TargetMap { get; set; }

Gets or sets the current active target map for grid operations.


Maps

1
public IReadOnlyList<IGridMap2D> Maps { get; set; }

Gets or sets the collection of maps available to this service.


Methods

GetSnapshot

1
public Snapshot GetSnapshot()

WorldToGrid

1
public CoreVector2I WorldToGrid(CoreVector2 worldPosition)

Converts a world position to a grid cell coordinate.

Remarks

Behavior contract:

  • Computes local = worldPosition - Origin
  • Computes grid = floor(local / TileSize) per-axis.
  • If TileSize.X == 0, X is returned as 0 (same for Y).
  • Negative positions are supported and will produce negative grid coordinates.

GridToWorld

1
public CoreVector2 GridToWorld(CoreVector2I gridPosition)

Converts a grid cell coordinate to a world position.

Remarks

Behavior contract:

  • Returns the world-space center of the given cell.
  • The returned position is Origin + (grid * TileSize) + (TileSize * 0.5) per-axis.
  • No validation is performed.

IsValidGridPosition

1
public bool IsValidGridPosition(CoreVector2I gridPosition)

SnapToTileCenter

1
public CoreVector2 SnapToTileCenter(CoreVector2 worldPosition)

Snaps an arbitrary world position to the center of the tile it falls within.

Remarks

Equivalent to GridToWorld(WorldToGrid(worldPosition)).


Events

TargetMapChanged

1
public event Action<IGridMap2D?>? TargetMapChanged

Raised when the active target map has changed.


MapsChanged

1
public event Action<IReadOnlyList<IGridMap2D>>? MapsChanged

Raised when the list of available maps has changed.