Class AbstractMap<TPoint>
This class is suitable to use as base class for most maps.
AbstractMap implements the IMap interface almost completely; you only have to implement to methods that correspond to the two calculations: converting from world to grid coordinates, and converting from grid to world coordinates.
[Version(1, 0, 0)]
public abstract class AbstractMap<TPoint> : IMap<TPoint>, IGridToWorldMap<TPoint> where TPoint : IGridPoint<TPoint>
Type Parameters
TPoint
- Inheritance
-
AbstractMap<TPoint>
- Implements
-
IMap<TPoint>IGridToWorldMap<TPoint>
- Derived
- Inherited Members
- Extension Methods
Constructors
AbstractMap(Vector2)
protected AbstractMap(Vector2 cellDimensions)
Parameters
cellDimensions
Vector2
AbstractMap(Vector2, Vector2)
protected AbstractMap(Vector2 cellDimensions, Vector2 anchorTranslation)
Parameters
Fields
anchorTranslation
protected Vector2 anchorTranslation
Field Value
cellDimensions
protected Vector2 cellDimensions
Field Value
gridPointTransform
protected Func<TPoint, TPoint> gridPointTransform
Field Value
- Func<TPoint, TPoint>
inverseGridPointTransform
protected Func<TPoint, TPoint> inverseGridPointTransform
Field Value
- Func<TPoint, TPoint>
Properties
GridPointTransform
The transformation applied to points before they are returned from the map.
public Func<TPoint, TPoint> GridPointTransform { get; }
Property Value
- Func<TPoint, TPoint>
InverseGridPointTransform
The transformation applied to points before they are processed by the map.
public Func<TPoint, TPoint> InverseGridPointTransform { get; }
Property Value
- Func<TPoint, TPoint>
this[Vector2]
Gets a grid point given a world point.
public TPoint this[Vector2 point] { get; }
Parameters
point
Vector2
Property Value
- TPoint
this[TPoint]
Gets a world point given a grid point.
public Vector2 this[TPoint point] { get; }
Parameters
point
TPoint
Property Value
Methods
AnchorCellBottom()
Returns an IMap that anchors the grid cells to the bottom.
public IMap<TPoint> AnchorCellBottom()
Returns
- IMap<TPoint>
AnchorCellBottomCenter()
Returns an IMap that anchors the grid cells to the bottom center.
public IMap<TPoint> AnchorCellBottomCenter()
Returns
- IMap<TPoint>
AnchorCellBottomLeft()
Returns an IMap that anchors the grid cells to the bottom left.
public IMap<TPoint> AnchorCellBottomLeft()
Returns
- IMap<TPoint>
AnchorCellBottomRight()
Returns an IMap that anchors the grid cells to the bottom right.
public IMap<TPoint> AnchorCellBottomRight()
Returns
- IMap<TPoint>
AnchorCellCenter()
Returns an IMap that anchors the grid cells horizontally to the center.
public IMap<TPoint> AnchorCellCenter()
Returns
- IMap<TPoint>
AnchorCellLeft()
Returns an IMap that anchors the grid cells to the left.
public IMap<TPoint> AnchorCellLeft()
Returns
- IMap<TPoint>
AnchorCellMiddle()
Returns an IMap that anchors the grid cells vertically to the middle.
public IMap<TPoint> AnchorCellMiddle()
Returns
- IMap<TPoint>
AnchorCellMiddleCenter()
Returns an IMap that anchors the grid cells to the middle center.
public IMap<TPoint> AnchorCellMiddleCenter()
Returns
- IMap<TPoint>
AnchorCellMiddleLeft()
Returns an IMap that anchors the grid cells to the middle left.
public IMap<TPoint> AnchorCellMiddleLeft()
Returns
- IMap<TPoint>
AnchorCellMiddleRight()
Returns an IMap that anchors the grid cells to the middle right.
public IMap<TPoint> AnchorCellMiddleRight()
Returns
- IMap<TPoint>
AnchorCellRight()
Returns an IMap that anchors the grid cells to the right.
public IMap<TPoint> AnchorCellRight()
Returns
- IMap<TPoint>
AnchorCellTop()
Returns an IMap that anchors the grid cells to the top.
public IMap<TPoint> AnchorCellTop()
Returns
- IMap<TPoint>
AnchorCellTopCenter()
Returns an IMap that anchors the grid cells vertically to the top center.
public IMap<TPoint> AnchorCellTopCenter()
Returns
- IMap<TPoint>
AnchorCellTopLeft()
Returns an IMap that anchors the grid cells vertically to the top left.
public IMap<TPoint> AnchorCellTopLeft()
Returns
- IMap<TPoint>
AnchorCellTopRight()
Returns an IMap that anchors the grid cells vertically to the top right.
public IMap<TPoint> AnchorCellTopRight()
Returns
- IMap<TPoint>
Animate(Func<Vector2, float, Vector2>, Func<Vector2, float, Vector2>)
Animates a according to a fixed function. This is useful for animating grids when the animation does not depend on any input.
public IMap<TPoint> Animate(Func<Vector2, float, Vector2> animation, Func<Vector2, float, Vector2> inverseAnimation)
Parameters
animation
Func<Vector2, float, Vector2>This is a function that takes as parameters the a point in the static grid and a time t(in seconds) and returns the new point at that time.An example of an animation is (x, t) => x + 5 * Mathf.Sin(t / 100) * Vector(1, 0), which will move the grid right and left periodically
inverseAnimation
Func<Vector2, float, Vector2>This inverse function returns the point in the static grid, given the animated point and time.If animate(p, t) returns r, then iverseAnimation(r, t) must return p.
Returns
- IMap<TPoint>
CalcAnchorBottomLeft(IGridSpace<TPoint>)
public Vector2 CalcAnchorBottomLeft(IGridSpace<TPoint> grid)
Parameters
grid
IGridSpace<TPoint>
Returns
CalcAnchorDimensions(IGridSpace<TPoint>)
public Vector2 CalcAnchorDimensions(IGridSpace<TPoint> grid)
Parameters
grid
IGridSpace<TPoint>
Returns
CalcBottomLeft(IGridSpace<TPoint>)
public virtual Vector2 CalcBottomLeft(IGridSpace<TPoint> grid)
Parameters
grid
IGridSpace<TPoint>
Returns
CalcGridDimensions(IGridSpace<TPoint>)
public virtual Vector2 CalcGridDimensions(IGridSpace<TPoint> grid)
Parameters
grid
IGridSpace<TPoint>
Returns
FlipXY()
Returns an IMap where grid cells positioned with x-and y-coordinates (in world space) flipped.
public IMap<TPoint> FlipXY()
Returns
- IMap<TPoint>
GetAnchorTranslation()
public Vector2 GetAnchorTranslation()
Returns
GetCellDimensions()
public Vector2 GetCellDimensions()
Returns
GetCellDimensions(TPoint)
Overrides this method to get custom Grid dimension calculations
public virtual Vector2 GetCellDimensions(TPoint point)
Parameters
point
TPoint
Returns
GridToWorld(TPoint)
This method maps a grid point to a world point.
public abstract Vector2 GridToWorld(TPoint gridPoint)
Parameters
gridPoint
TPoint
Returns
RawWorldToGrid(Vector2)
This method maps a world point to a grid point, assuming that the anchor point is centered in the cell.This will allow the index accessors[] to give correct results for any anchoring.
public abstract TPoint RawWorldToGrid(Vector2 worldPoint)
Parameters
worldPoint
Vector2
Returns
- TPoint
ReflectAboutX()
Returns an IMap where grid cells are reflected about the X-point in world space.
public IMap<TPoint> ReflectAboutX()
Returns
- IMap<TPoint>
ReflectAboutY()
Returns an IMap where grid cells are reflected about the Y-point in world space.
public IMap<TPoint> ReflectAboutY()
Returns
- IMap<TPoint>
Rotate(float)
Returns an IMap where grid cells are rotated about the origin by the given angle.
public IMap<TPoint> Rotate(float angle)
Parameters
angle
float
Returns
- IMap<TPoint>
Rotate180()
Returns an IMap where grid cells are scaled about the origin by 180 degrees.
public IMap<TPoint> Rotate180()
Returns
- IMap<TPoint>
Rotate90()
Returns an IMap where grid cells are rotated about the origin by 90 degrees.
public IMap<TPoint> Rotate90()
Returns
- IMap<TPoint>
RotateAround(float, Vector2)
Returns an IMap where grid cells are rotated about the given point by the given angle.
public IMap<TPoint> RotateAround(float angle, Vector2 point)
Parameters
Returns
- IMap<TPoint>
Scale(float)
Returns an IMap where grid cells are scaled by factor.
public IMap<TPoint> Scale(float factor)
Parameters
factor
float
Returns
- IMap<TPoint>
Scale(float, float)
Returns an IMap where grid cells are scaled by the factors in each direction.
public IMap<TPoint> Scale(float factorX, float factorY)
Parameters
Returns
- IMap<TPoint>
Scale(Vector2)
public IMap<TPoint> Scale(Vector2 factor)
Parameters
factor
Vector2
Returns
- IMap<TPoint>
SetGridPointTransforms(Func<TPoint, TPoint>, Func<TPoint, TPoint>)
public IMap<TPoint> SetGridPointTransforms(Func<TPoint, TPoint> coordinateTransformation, Func<TPoint, TPoint> inverseCoordinateTransformation)
Parameters
Returns
- IMap<TPoint>
To3DXY()
Makes a map that maps to 3D, with the grid positioned in the XY plane, with the z-coordinate 0.
public IMap3D<TPoint> To3DXY()
Returns
- IMap3D<TPoint>
To3DXY(float)
Makes a map that maps to 3D, with the grid positioned in the XY plane, with the given z-coordinate.
public IMap3D<TPoint> To3DXY(float z)
Parameters
z
float
Returns
- IMap3D<TPoint>
To3DXZ()
Makes a map that maps to 3D, with the grid positioned in the XZ plane, with the z-coordinate 0.
public IMap3D<TPoint> To3DXZ()
Returns
- IMap3D<TPoint>
To3DXZ(float)
Makes a map that maps to 3D, with the grid positioned in the XZ plane, with the given z-coordinate.
public IMap3D<TPoint> To3DXZ(float y)
Parameters
y
float
Returns
- IMap3D<TPoint>
Translate(float, float)
Returns an IMap where grid cells are translated by the give amounts.
public IMap<TPoint> Translate(float offsetX, float offsetY)
Parameters
Returns
- IMap<TPoint>
Translate(Vector2)
Returns an IMap where grid cells are translated by the give amount.
public IMap<TPoint> Translate(Vector2 offset)
Parameters
offset
Vector2
Returns
- IMap<TPoint>
TranslateX(float)
Returns an IMap where grid cells are translated by the give amount.
public IMap<TPoint> TranslateX(float offsetX)
Parameters
offsetX
float
Returns
- IMap<TPoint>
TranslateY(float)
Returns an IMap where grid cells are translated by the give amount.
public IMap<TPoint> TranslateY(float offsetY)
Parameters
offsetY
float
Returns
- IMap<TPoint>
WithWindow(Rect)
Returns a WindowedMap based on this map that can be used to lay the grid out in a window.
public WindowedMap<TPoint> WithWindow(Rect window)
Parameters
window
Rect
Returns
- WindowedMap<TPoint>
Examples
For example:
var map = new RectMap(cellDimensions)
.WithWindow(screenRect)
.AlignMiddleCenter();