12internal sealed class IsometricAxialCoordinates : ISceneLayerCoordinates
15 private static void WH(
34 public Point GetAnchorPixelAtSceneLayerCoordinates(SceneLayer sceneLayer, PointF gp)
46 float px = -originX + gp.X *
W + gp.Y * halfW;
47 float py = -originY + gp.Y * halfH;
49 return new Point((
int)Math.Floor(px), (
int)Math.Floor(py));
58 public PointF GetSceneLayerCoordinatesAtPixel(SceneLayer sceneLayer, PointF pixelPt)
70 float gyF = (pixelPt.Y + originY) / halfH;
71 float gxF = (pixelPt.X + originX - gyF * halfW) /
W;
73 return new PointF(gxF, gyF);
83 public List<SceneLayerTile> GetSceneLayerTilesInPixelRange(
84 SceneLayer sceneLayer,
85 Rectangle worldPixelRange,
88 var result =
new List<SceneLayerTile>();
97 var candidateRange = TileBounds.GetTransformedTileCandidateRange(sceneLayer, worldPixelRange, includeOverhang);
100 var ul = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Left, candidateRange.Top));
101 var ur = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Right, candidateRange.Top));
102 var ll = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Left, candidateRange.Bottom));
103 var lr = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Right, candidateRange.Bottom));
105 int minX = (int)System.Math.Floor(System.Math.Min(System.Math.Min(ul.X, ur.X), System.Math.Min(ll.X, lr.X))) -
108 int maxX = (int)System.Math.Ceiling(System.Math.Max(System.Math.Max(ul.X, ur.X), System.Math.Max(ll.X, lr.X))) +
111 int minY = (int)System.Math.Floor(System.Math.Min(System.Math.Min(ul.Y, ur.Y), System.Math.Min(ll.Y, lr.Y))) -
114 int maxY = (int)System.Math.Ceiling(System.Math.Max(System.Math.Max(ul.Y, ur.Y), System.Math.Max(ll.Y, lr.Y))) +
121 int xStart = System.Math.Max(minX, 0);
122 int xEnd = System.Math.Min(maxX, cols - 1);
123 int yStart = System.Math.Max(minY, 0);
124 int yEnd = System.Math.Min(maxY, rows - 1);
126 if (xStart > xEnd || yStart > yEnd)
129 for (
int y = yStart; y <= yEnd; y++)
131 for (
int x = xStart; x <= xEnd; x++)
133 var gp = sceneLayer[x, y];
138 var r = GetPixelRangeForTile(gp, includeOverhang);
140 if (r.IntersectsWith(worldPixelRange))
154 public Rectangle GetPixelRangeForTile(Tile tile,
bool includeOverhang)
164 var top = GetAnchorPixelAtSceneLayerCoordinates(tile.SceneLayer, tile.SceneLayerCoordinates);
173 return TileBounds.ApplyTileGeometry(rect, tile, includeOverhang);
182 public Rectangle GetPixelRangeForTileList(List<Tile> tileList,
bool includeOverhang)
186 foreach (var t
in tileList)
188 var r = GetPixelRangeForTile(t, includeOverhang);
189 ret = ret.IsEmpty ? r :
Rectangle.Union(ret, r);
201 public SceneLayerTile GetAdjacentSceneLayerTile(SceneLayerTile gp,
CardinalDirections dir)
210 CardinalDirections.N => m.ResolveWrappedTile(x, y - 1),
211 CardinalDirections.S => m.ResolveWrappedTile(x, y + 1),
212 CardinalDirections.E => m.ResolveWrappedTile(x + 1, y),
213 CardinalDirections.W => m.ResolveWrappedTile(x - 1, y),
214 CardinalDirections.NE => m.ResolveWrappedTile(x + 1, y - 1),
215 CardinalDirections.NW => m.ResolveWrappedTile(x - 1, y - 1),
216 CardinalDirections.SE => m.ResolveWrappedTile(x + 1, y + 1),
217 CardinalDirections.SW => m.ResolveWrappedTile(x - 1, y + 1),
228 public Point[] GetPolygonPts(Tile tile,
bool includeOverhang)
237 var top = GetAnchorPixelAtSceneLayerCoordinates(tile.SceneLayer, tile.SceneLayerCoordinates);
238 var oh = includeOverhang ? tile.Overhang :
Spacing.None;
243 new Point(top.X, top.Y - oh.Top),
244 new Point(top.X +
W / 2 + oh.Right, top.Y + H / 2),
245 new Point(top.X, top.Y + H + oh.Bottom),
246 new Point(top.X -
W / 2 - oh.Left, top.Y + H / 2)
257 public PointF FindEquivalentSceneLayerCoordinates(PointF valColRow,
int xUpperBound,
int yUpperBound)
260 float modX = valColRow.X % (xUpperBound + 1);
261 float modY = valColRow.Y % (yUpperBound + 1);
264 modX += xUpperBound + 1;
267 modY += yUpperBound + 1;
269 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 GridRowCount
Gets the number of rows (tiles high) in this layer's grid.
int TileHeight
Gets or sets the height of each tile in this layer, measured in pixels.
int GridColumnCount
Gets the number of columns (tiles wide) in this layer's grid.
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.
record struct Spacing([property:JsonProperty("left")] int Left, [property:JsonProperty("top")] int Top, [property:JsonProperty("right")] int Right, [property:JsonProperty("bottom")] int Bottom)
Represents dimensions in pixels when spacing Tilesheets.