10internal sealed class OrthogonalCoordinates : ISceneLayerCoordinates
18 public Point GetAnchorPixelAtSceneLayerCoordinates(SceneLayer sceneLayer, PointF layerPoint)
25 int x = (int)(
W * layerPoint.X) - origin.X;
26 int y = (int)(H * layerPoint.Y) - origin.Y;
28 return new Point(x, y);
37 public PointF GetSceneLayerCoordinatesAtPixel(SceneLayer sceneLayer, PointF pixelPt)
45 float gx = (pixelPt.X + originX) /
W;
46 float gy = (pixelPt.Y + originY) / H;
48 return new PointF(gx, gy);
59 public List<SceneLayerTile> GetSceneLayerTilesInPixelRange(
60 SceneLayer sceneLayer,
61 Rectangle worldPixelRange,
64 var retVal =
new List<SceneLayerTile>();
65 var candidateRange = TileBounds.GetTransformedTileCandidateRange(sceneLayer, worldPixelRange, includeOverhang);
68 PointF ptUL = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Left, candidateRange.Top));
70 PointF ptBR = GetSceneLayerCoordinatesAtPixel(
72 new PointF(candidateRange.Right - 1, candidateRange.Bottom - 1));
74 int minY = (int)Math.Floor(ptUL.Y) - 1;
75 int maxY = (int)Math.Ceiling(ptBR.Y) + 1;
76 int minX = (int)Math.Floor(ptUL.X) - 1;
77 int maxX = (int)Math.Ceiling(ptBR.X) + 1;
80 for (
int y = minY; y <= maxY; y++)
82 for (
int x = minX; x <= maxX; x++)
84 var gPt = sceneLayer[x, y];
90 var rect = GetPixelRangeForTile(gPt, includeOverhang);
92 if (rect.IntersectsWith(worldPixelRange))
106 public Rectangle GetPixelRangeForTile(Tile tile,
bool includeOverhang)
108 var layer = tile.SceneLayer;
109 int W = layer.TileWidth;
110 int H = layer.TileHeight;
112 int originX = layer.OriginPx.X;
113 int originY = layer.OriginPx.Y;
117 X = (int)(
W * tile.SceneLayerCoordinates.X) - originX,
118 Y = (int)(H * tile.SceneLayerCoordinates.Y) - originY,
124 return TileBounds.ApplyTileGeometry(baseRect, tile, includeOverhang);
133 public Rectangle GetPixelRangeForTileList(List<Tile> tileList,
bool includeOverhang)
137 foreach (Tile tile
in tileList)
139 var rect = GetPixelRangeForTile(tile, includeOverhang);
140 retVal = retVal.IsEmpty ? rect :
Rectangle.Union(retVal, rect);
152 public SceneLayerTile GetAdjacentSceneLayerTile(SceneLayerTile layerPoint,
CardinalDirections direction)
209 public Point[] GetPolygonPts(Tile tile,
bool includeOverhang)
212 var r = GetPixelRangeForTile(tile, includeOverhang);
216 new Point(r.Left, r.Top),
217 new Point(r.Right, r.Top),
218 new Point(r.Right, r.Bottom),
219 new Point(r.Left, r.Bottom)
230 public PointF FindEquivalentSceneLayerCoordinates(PointF valColRow,
int xUpperBound,
int yUpperBound)
232 float modX = valColRow.X % (xUpperBound + 1);
233 float modY = valColRow.Y % (yUpperBound + 1);
236 modX += xUpperBound + 1;
239 modY += yUpperBound + 1;
241 return new PointF(modX, modY);
Point GridCoordinatesAbs
Gets the absolute grid coordinates of this tile within its parent scene layer as integer values.
override SceneLayer SceneLayer
Gets the parent scene layer that contains this tile.
Point OriginPx
Gets or sets the world-space pixel origin of this layer's (0,0) tile position.
int TileHeight
Gets or sets the height of each tile in this layer, measured in pixels.
SceneLayerTile? ResolveWrappedTile(int column, int row)
Resolves a virtual grid cell to its canonical tile. Only enabled axes wrap; an out-of-range disabled ...
int TileWidth
Gets or sets the width of each tile in this layer, measured in pixels.
CardinalDirections
Represents the eight cardinal and intercardinal directions of the compass.
@ Rectangle
Particles are spawned uniformly within a rectangular area. This is the default distribution.
@ SceneLayer
Performs direct drawing within a scene layer using world-space coordinates.