Class ScyllaHexGrid<TCell>.Builder
Fluent builder for constructing ScyllaHexGrid<TCell> instances with complex or convenient configurations. Call Build() to obtain an IScyllaGrid<TCoord, TCell> (which may be a synchronized wrapper), or BuildConcrete() to obtain the concrete ScyllaHexGrid<TCell> directly.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaHexGrid<TCell>.Builder
Remarks
var grid = ScyllaHexGrid<int>.CreateBuilder()
.WithSize(16, 16)
.WithLayout(new HexGridLayout(1f, HexOrientation.PointyTop))
.WithDefaultValue(0)
.Build();
Methods
Build()
Builds and returns the configured grid as an IScyllaGrid<TCoord, TCell> interface. If Synchronized(object) was called, returns a ScyllaHexGrid<TCell>.SynchronizedScyllaHexGrid wrapper; otherwise, returns the concrete ScyllaHexGrid<TCell> directly.
Declaration
public IScyllaGrid<HexCoord, TCell> Build()
Returns
| Type | Description |
|---|---|
| IScyllaGrid<HexCoord, TCell> | An IScyllaGrid<TCoord, TCell> instance configured according to the builder settings. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when WithLayout(HexGridLayout) was not called before building. |
BuildConcrete()
Builds and returns the concrete unsynchronized ScyllaHexGrid<TCell> instance. Use this overload when you need access to the dense-grid-specific API such as GetRange(HexCoord, int, Span<HexCoord>), GetRing(HexCoord, int, Span<HexCoord>), or DrawLine(HexCoord, HexCoord, Span<HexCoord>).
Declaration
public ScyllaHexGrid<TCell> BuildConcrete()
Returns
| Type | Description |
|---|---|
| ScyllaHexGrid<TCell> | The configured concrete ScyllaHexGrid<TCell> instance. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when Synchronized(object) was called (use Build() instead), or when WithLayout(HexGridLayout) was not called. |
Synchronized(object)
Configures the builder to return a synchronized (thread-safe) wrapper.
Declaration
public ScyllaHexGrid<TCell>.Builder Synchronized(object syncRoot = null)
Parameters
| Type | Name | Description |
|---|---|---|
| object | syncRoot | Optional external lock object. |
Returns
| Type | Description |
|---|---|
| ScyllaHexGrid<TCell>.Builder | This builder instance for method chaining. |
WithDefaultValue(TCell)
Sets the default value to fill all cells with after construction.
Declaration
public ScyllaHexGrid<TCell>.Builder WithDefaultValue(TCell value)
Parameters
| Type | Name | Description |
|---|---|---|
| TCell | value | The default value. |
Returns
| Type | Description |
|---|---|
| ScyllaHexGrid<TCell>.Builder | This builder instance for method chaining. |
WithHexagonalBounds(int)
Configures the grid to cover a hexagonal region centered at the origin with the given radius.
Sets the grid dimensions and origin so that all hexes within the radius fit inside the
rectangular axial bounding box: Q range [-radius, +radius], R range [-radius, +radius].
Declaration
public ScyllaHexGrid<TCell>.Builder WithHexagonalBounds(int radius)
Parameters
| Type | Name | Description |
|---|---|---|
| int | radius | The hexagonal radius. Must be at least 0. A radius of 0 produces a 1x1 grid. |
Returns
| Type | Description |
|---|---|
| ScyllaHexGrid<TCell>.Builder | This builder instance for method chaining. |
Remarks
The resulting grid dimensions are (2radius+1) x (2radius+1). Note that a
rectangular axial region includes some cells that fall outside the true hexagonal area;
use GetRange(HexCoord, int, Span<HexCoord>) to enumerate only cells within the exact
hexagonal radius at runtime.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
WithLayout(HexGridLayout)
Sets the spatial layout for world-space conversions.
Declaration
public ScyllaHexGrid<TCell>.Builder WithLayout(HexGridLayout layout)
Parameters
| Type | Name | Description |
|---|---|---|
| HexGridLayout | layout | The layout to use. |
Returns
| Type | Description |
|---|---|
| ScyllaHexGrid<TCell>.Builder | This builder instance for method chaining. |
WithOrigin(int, int)
Sets the minimum Q and R origin values for the grid bounds.
Declaration
public ScyllaHexGrid<TCell>.Builder WithOrigin(int qMin, int rMin)
Parameters
| Type | Name | Description |
|---|---|---|
| int | qMin | The minimum Q value. |
| int | rMin | The minimum R value. |
Returns
| Type | Description |
|---|---|
| ScyllaHexGrid<TCell>.Builder | This builder instance for method chaining. |
WithSize(int, int)
Sets the grid dimensions in axial space.
Declaration
public ScyllaHexGrid<TCell>.Builder WithSize(int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| int | width | The number of columns in Q direction. Must be at least 1. |
| int | height | The number of rows in R direction. Must be at least 1. |
Returns
| Type | Description |
|---|---|
| ScyllaHexGrid<TCell>.Builder | This builder instance for method chaining. |