Class PolygonGridMap<TPoint, TBasePoint>
A map that can be used for general spliced grids made from polygons.
To use this map: - Find a rectangular tessellation for your grid. - This rectangle will consist out of several polygons, each which represents a (partial) cell of your grid. - One of these polygons should correspond to the splice point (0, 0, 0). - Find the center of this polygon relative to the rectangle in normalized coordinates, that is, so that the entire rectangle corresponds to (0, 0) -> (1, 1). - Label the polygons 0, 1, 2, ... etc. - Find the vertices of each polygon in normalized coordinates. - Now calculate the spliced vector point offsets for each polygon, relative to the (0, 0, 0) polygon, in normalized coordinates.
[Version(1, 2, 0)]
public abstract class PolygonGridMap<TPoint, TBasePoint> : AbstractMap<TPoint>, IMap<TPoint>, IGridToWorldMap<TPoint> where TPoint : ISplicedPoint<TPoint, TBasePoint> where TBasePoint : IGridPoint<TBasePoint>, IVectorPoint<TBasePoint>
Type Parameters
TPoint
TBasePoint
- Inheritance
-
AbstractMap<TPoint>PolygonGridMap<TPoint, TBasePoint>
- Implements
-
IMap<TPoint>IGridToWorldMap<TPoint>
- Derived
- Inherited Members
- Extension Methods
Constructors
PolygonGridMap(Vector2, Vector2, Vector2, IEnumerable<IEnumerable<Vector2>>, IEnumerable<TPoint>, IEnumerable<Vector2>, Func<int, int, int, TPoint>, Func<TBasePoint, Vector2>, Func<VectorPoint, TBasePoint>)
Constructor of a PolygonGridMap
protected PolygonGridMap(Vector2 cellDimensions, Vector2 rectDimensions, Vector2 zeroShapeOffset, IEnumerable<IEnumerable<Vector2>> polies, IEnumerable<TPoint> offsets, IEnumerable<Vector2> rectOffsets, Func<int, int, int, TPoint> pointFactory, Func<TBasePoint, Vector2> baseMap, Func<VectorPoint, TBasePoint> rectPointMap)
Parameters
cellDimensions
Vector2size of the cells in world coordinates
rectDimensions
Vector2size of the rectangle in world coodrinates
zeroShapeOffset
Vector2normalized world coordinates of the shape(0, 0, 0) relative to the rectangle bottom left corner
polies
IEnumerable<IEnumerable<Vector2>>each item in the list corresponds to a polygon, andd each polygon is a list of vertices in order(each vertice needs to be included only once).
offsets
IEnumerable<TPoint>offsets in grid coordinates for each poly relative to(0, 0, 0) in the same order as the polies list
rectOffsets
IEnumerable<Vector2>the offsets in normalised world coordinates for each splice index
pointFactory
Func<int, int, int, TPoint>returns a new spliced point with the given coordinates
baseMap
Func<TBasePoint, Vector2>returns the world coordinate for the given base point
rectPointMap
Func<VectorPoint, TBasePoint>maps the rectangular patches with the correct base point(that corresponds to (0, 0, 0) in that rectangle).
Methods
GetCellDimensions(TPoint)
Returns the cell dimensions for this cell.
Generally, for spliced points, these are the same for cells(points) with the same splice index.
public override abstract Vector2 GetCellDimensions(TPoint point)
Parameters
point
TPoint
Returns
GridToWorld(TPoint)
This method maps a grid point to a world point.
public override 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 override TPoint RawWorldToGrid(Vector2 worldPoint)
Parameters
worldPoint
Vector2
Returns
- TPoint
Scale(IEnumerable<IEnumerable<Vector2>>, float)
Scales the vertices of a list of polygons (each represented as a list of vertices) with the factor.
public static IEnumerable<IEnumerable<Vector2>> Scale(IEnumerable<IEnumerable<Vector2>> polies, float factor)
Parameters
polies
IEnumerable<IEnumerable<Vector2>>factor
float
Returns
Scale(IEnumerable<IEnumerable<Vector2>>, Vector2)
Scales the vertices of a list of polygons (each represented as a list of vertices) compontwise with the factor.
public static IEnumerable<IEnumerable<Vector2>> Scale(IEnumerable<IEnumerable<Vector2>> polies, Vector2 factor)
Parameters
polies
IEnumerable<IEnumerable<Vector2>>factor
Vector2
Returns
Scale(IEnumerable<Vector2>, float)
Scales a list of points componntwise the factor.
public static IEnumerable<Vector2> Scale(IEnumerable<Vector2> points, float factor)
Parameters
points
IEnumerable<Vector2>factor
float
Returns
Scale(IEnumerable<Vector2>, Vector2)
Scales a list of points componntwise with the factor.
public static IEnumerable<Vector2> Scale(IEnumerable<Vector2> points, Vector2 factor)
Parameters
points
IEnumerable<Vector2>factor
Vector2