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(SceneLayer sceneLayer, Rectangle worldPixelRange,
bool includeOverhang)
61 var retVal =
new List<SceneLayerTile>();
62 var candidateRange = TileBounds.GetTransformedTileCandidateRange(sceneLayer, worldPixelRange, includeOverhang);
65 PointF ptUL = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Left, candidateRange.Top));
66 PointF ptBR = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Right - 1, candidateRange.Bottom - 1));
68 int minY = (int)Math.Floor(ptUL.Y) - 1;
69 int maxY = (int)Math.Ceiling(ptBR.Y) + 1;
70 int minX = (int)Math.Floor(ptUL.X) - 1;
71 int maxX = (int)Math.Ceiling(ptBR.X) + 1;
74 for (
int y = minY; y <= maxY; y++)
76 for (
int x = minX; x <= maxX; x++)
78 var gPt = sceneLayer[x, y];
79 if (gPt ==
null)
continue;
82 var rect = GetPixelRangeForTile(gPt, includeOverhang);
83 if (rect.IntersectsWith(worldPixelRange))
97 public Rectangle GetPixelRangeForTile(Tile tile,
bool includeOverhang)
99 var layer = tile.SceneLayer;
100 int W = layer.TileWidth;
101 int H = layer.TileHeight;
103 int originX = layer.OriginPx.X;
104 int originY = layer.OriginPx.Y;
108 X = (int)(
W * tile.SceneLayerCoordinates.X) - originX,
109 Y = (int)(H * tile.SceneLayerCoordinates.Y) - originY,
115 return TileBounds.ApplyTileGeometry(baseRect, tile, includeOverhang);
124 public Rectangle GetPixelRangeForTileList(List<Tile> tileList,
bool includeOverhang)
128 foreach (Tile tile
in tileList)
130 var rect = GetPixelRangeForTile(tile, includeOverhang);
131 retVal = retVal.IsEmpty ? rect :
Rectangle.Union(retVal, rect);
143 public SceneLayerTile GetAdjacentSceneLayerTile(SceneLayerTile layerPoint,
CardinalDirections direction)
184 public Point[] GetPolygonPts(Tile tile,
bool includeOverhang)
187 var r = GetPixelRangeForTile(tile, includeOverhang);
190 new Point(r.Left, r.Top),
191 new Point(r.Right, r.Top),
192 new Point(r.Right, r.Bottom),
193 new Point(r.Left, r.Bottom)
204 public PointF FindEquivalentSceneLayerCoordinates(PointF valColRow,
int xUpperBound,
int yUpperBound)
206 float modX = valColRow.X % (xUpperBound + 1);
207 float modY = valColRow.Y % (yUpperBound + 1);
210 modX += xUpperBound + 1;
213 modY += yUpperBound + 1;
215 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.