Table of Contents

Class FlatHexGrid<TCell>

Namespace
Gamelogic.Grids
Assembly
Assembly-CSharp.dll

A grid for flat hexagons, that is, hexagons with two horizontal edges.

[Version(1, 0, 0)]
[Serializable]
public class FlatHexGrid<TCell> : AbstractUniformGrid<TCell, FlatHexPoint>, IEvenGrid<TCell, FlatHexPoint, FlatHexPoint>, IVectorGrid<TCell, FlatHexPoint, FlatHexPoint>, IGrid<TCell, FlatHexPoint>, IGrid<FlatHexPoint>, IGridSpace<FlatHexPoint>, IEnumerable<FlatHexPoint>, IEnumerable, ISupportsVertexGrid<PointyTriPoint>, ISupportsEdgeGrid<FlatRhombPoint>

Type Parameters

TCell
Inheritance
FlatHexGrid<TCell>
Implements
Inherited Members
Extension Methods

Constructors

FlatHexGrid(int, int)

Construct a new grid in the default shape with the given width and height. No transformations are applied to the grid.

Normally, the static factory methods or shape building methods should be used to create grids. These constructors are provided for advanced usage.

public FlatHexGrid(int width, int height)

Parameters

width int
height int

FlatHexGrid(int, int, Func<FlatHexPoint, bool>)

Construct a new grid whose cells are determined by the given test function.

The test function should only return true for points within the bounds of the default shape.

No transformations are applied to the grid.

Normally, the static factory methods or shape building methods should be used to create grids. These constructors are provided for advanced usage.

public FlatHexGrid(int width, int height, Func<FlatHexPoint, bool> isInside)

Parameters

width int
height int
isInside Func<FlatHexPoint, bool>

FlatHexGrid(int, int, Func<FlatHexPoint, bool>, FlatHexPoint)

Construct a new grid whose cells are determined by the given test function.

The function should only return true for points within the bounds of the rectangle when the given transforms are applied to them.

Normally, the static factory methods or shape building methods should be used to create grids. These constructors are provided for advanced usage.

public FlatHexGrid(int width, int height, Func<FlatHexPoint, bool> isInside, FlatHexPoint offset)

Parameters

width int
height int
isInside Func<FlatHexPoint, bool>
offset FlatHexPoint

FlatHexGrid(int, int, Func<FlatHexPoint, bool>, Func<FlatHexPoint, FlatHexPoint>, Func<FlatHexPoint, FlatHexPoint>)

public FlatHexGrid(int width, int height, Func<FlatHexPoint, bool> isInside, Func<FlatHexPoint, FlatHexPoint> gridPointTransform, Func<FlatHexPoint, FlatHexPoint> inverseGridPointTransform)

Parameters

width int
height int
isInside Func<FlatHexPoint, bool>
gridPointTransform Func<FlatHexPoint, FlatHexPoint>
inverseGridPointTransform Func<FlatHexPoint, FlatHexPoint>

FlatHexGrid(int, int, Func<FlatHexPoint, bool>, Func<FlatHexPoint, FlatHexPoint>, Func<FlatHexPoint, FlatHexPoint>, IEnumerable<FlatHexPoint>)

public FlatHexGrid(int width, int height, Func<FlatHexPoint, bool> isInside, Func<FlatHexPoint, FlatHexPoint> gridPointTransform, Func<FlatHexPoint, FlatHexPoint> inverseGridPointTransform, IEnumerable<FlatHexPoint> neighborDirections)

Parameters

width int
height int
isInside Func<FlatHexPoint, bool>
gridPointTransform Func<FlatHexPoint, FlatHexPoint>
inverseGridPointTransform Func<FlatHexPoint, FlatHexPoint>
neighborDirections IEnumerable<FlatHexPoint>

Properties

GridOrigin

Gives the Zero point as transform by this grids transforms.

protected override FlatHexPoint GridOrigin { get; }

Property Value

FlatHexPoint

Methods

ArrayPointFromGridPoint(FlatHexPoint)

public static ArrayPoint ArrayPointFromGridPoint(FlatHexPoint point)

Parameters

point FlatHexPoint

Returns

ArrayPoint

ArrayPointFromPoint(FlatHexPoint)

protected override ArrayPoint ArrayPointFromPoint(FlatHexPoint hexPoint)

Parameters

hexPoint FlatHexPoint

Returns

ArrayPoint

ArrayPointFromPoint(int, int)

protected override ArrayPoint ArrayPointFromPoint(int hX, int hY)

Parameters

hX int
hY int

Returns

ArrayPoint

BeginShape()

Use this method to begin a shape building sequence.

public static FlatHexOp<TCell> BeginShape()

Returns

FlatHexOp<TCell>

CalculateStorage(IEnumerable<FlatHexPoint>)

public static IntRect CalculateStorage(IEnumerable<FlatHexPoint> points)

Parameters

points IEnumerable<FlatHexPoint>

Returns

IntRect

CloneStructure<TNewCellType>()

Returns a grid in the same shape, but with contents in the new type.

public override IGrid<TNewCellType, FlatHexPoint> CloneStructure<TNewCellType>()

Returns

IGrid<TNewCellType, FlatHexPoint>

Type Parameters

TNewCellType

Default(int, int)

public static FlatHexGrid<TCell> Default(int width, int height)

Parameters

width int
height int

Returns

FlatHexGrid<TCell>

DefaultContains(FlatHexPoint, int, int)

public static bool DefaultContains(FlatHexPoint point, int width, int height)

Parameters

point FlatHexPoint
width int
height int

Returns

bool

Diamond(int)

public static FlatHexGrid<TCell> Diamond(int side)

Parameters

side int

Returns

FlatHexGrid<TCell>

FatRectangle(int, int)

public static FlatHexGrid<TCell> FatRectangle(int width, int height)

Parameters

width int
height int

Returns

FlatHexGrid<TCell>

GetPrincipleNeighborDirections()

This is the set of neighbor directions so that it contains only one of the neighbor directions of a pair of opposites.

public IEnumerable<FlatHexPoint> GetPrincipleNeighborDirections()

Returns

IEnumerable<FlatHexPoint>

GetSpiralIterator(FlatHexPoint, int)

An iterator that spirals anti-clockwise around the given origin.

[Version(1, 10, 0)]
public IEnumerable<FlatHexPoint> GetSpiralIterator(FlatHexPoint origin, int ringCount)

Parameters

origin FlatHexPoint
ringCount int

Returns

IEnumerable<FlatHexPoint>

Examples

int k = 0;

foreach(var point in grid.GetSpiralIterator(point, 3))
{
	grid[point].name = k.ToString();
}

GetSpiralIterator(int)

An iterator that spirals anti-clockwise around the grid origin (0, 0).

[Version(1, 7, 0)]
public IEnumerable<FlatHexPoint> GetSpiralIterator(int ringCount)

Parameters

ringCount int

Returns

IEnumerable<FlatHexPoint>

GridPointFromArrayPoint(ArrayPoint)

public static FlatHexPoint GridPointFromArrayPoint(ArrayPoint point)

Parameters

point ArrayPoint

Returns

FlatHexPoint

Hexagon(FlatHexPoint, int)

public static FlatHexGrid<TCell> Hexagon(FlatHexPoint centre, int side)

Parameters

centre FlatHexPoint
side int

Returns

FlatHexGrid<TCell>

Hexagon(int)

public static FlatHexGrid<TCell> Hexagon(int side)

Parameters

side int

Returns

FlatHexGrid<TCell>

HorizontallyWrappedParallelogram(int, int)

Returns a grid wrapped horizontally along a parallelogram.

Since version 1.7

public static WrappedGrid<TCell, FlatHexPoint> HorizontallyWrappedParallelogram(int width, int height)

Parameters

width int
height int

Returns

WrappedGrid<TCell, FlatHexPoint>

HorizontallyWrappedRectangle(int, int)

Returns a grid wrapped horizontally along a parallelogram.

[Version(1, 7, 0)]
public static WrappedGrid<TCell, FlatHexPoint> HorizontallyWrappedRectangle(int width, int height)

Parameters

width int
height int

Returns

WrappedGrid<TCell, FlatHexPoint>

LeftTriangle(int)

public static FlatHexGrid<TCell> LeftTriangle(int side)

Parameters

side int

Returns

FlatHexGrid<TCell>

MakeEdgeGrid<TNewCell>()

Makes an edge grid for this grid.

public IGrid<TNewCell, FlatRhombPoint> MakeEdgeGrid<TNewCell>()

Returns

IGrid<TNewCell, FlatRhombPoint>

Type Parameters

TNewCell

MakeVertexGrid<TNewCell>()

Makes a grid that corresponds to the vertices of this grid.

If point is inside this grid, then all of point.GetVertices() are in the grid returned by this method.

public IGrid<TNewCell, PointyTriPoint> MakeVertexGrid<TNewCell>()

Returns

IGrid<TNewCell, PointyTriPoint>

Type Parameters

TNewCell

Parallelogram(int, int)

public static FlatHexGrid<TCell> Parallelogram(int width, int height)

Parameters

width int
height int

Returns

FlatHexGrid<TCell>

PointFromArrayPoint(int, int)

protected override FlatHexPoint PointFromArrayPoint(int aX, int aY)

Parameters

aX int
aY int

Returns

FlatHexPoint

Rectangle(int, int)

public static FlatHexGrid<TCell> Rectangle(int width, int height)

Parameters

width int
height int

Returns

FlatHexGrid<TCell>

RightTriangle(int)

public static FlatHexGrid<TCell> RightTriangle(int side)

Parameters

side int

Returns

FlatHexGrid<TCell>

Single()

public static FlatHexGrid<TCell> Single()

Returns

FlatHexGrid<TCell>

ThinRectangle(int, int)

public static FlatHexGrid<TCell> ThinRectangle(int width, int height)

Parameters

width int
height int

Returns

FlatHexGrid<TCell>

ToString()

public override string ToString()

Returns

string

VerticallyWrappedParallelogram(int, int)

Returns a grid wrapped vertically along a parallelogram.

Since version 1.7

public static WrappedGrid<TCell, FlatHexPoint> VerticallyWrappedParallelogram(int width, int height)

Parameters

width int
height int

Returns

WrappedGrid<TCell, FlatHexPoint>

WrappedHexagon(int)

Returns a new grid, wrapped along a Hexagon with the given side length.

[Version(1, 7, 0)]
public static WrappedGrid<TCell, FlatHexPoint> WrappedHexagon(int side)

Parameters

side int

Returns

WrappedGrid<TCell, FlatHexPoint>

WrappedParallelogram(int, int)

Returns a grid wrapped along a parallelogram.

Since version 1.7

public static WrappedGrid<TCell, FlatHexPoint> WrappedParallelogram(int width, int height)

Parameters

width int
height int

Returns

WrappedGrid<TCell, FlatHexPoint>