11internal sealed class IsometricRhombicCoordinates : ISceneLayerCoordinates
19 public Point GetAnchorPixelAtSceneLayerCoordinates(SceneLayer sceneLayer, PointF gp)
31 float px = (dx - dy) * (
W / 2f) - originX;
32 float py = (dx + dy) * (H / 2f) - originY;
34 return new Point((
int)Math.Floor(px), (
int)Math.Floor(py));
43 public PointF GetSceneLayerCoordinatesAtPixel(SceneLayer sceneLayer, PointF pixelPt)
51 float a = (pixelPt.X + originX) / (
W / 2f);
52 float b = (pixelPt.Y + originY) / (H / 2f);
54 float dx = (a + b) / 2f;
55 float dy = (b - a) / 2f;
57 return new PointF(dx, dy);
67 public List<SceneLayerTile> GetSceneLayerTilesInPixelRange(
68 SceneLayer sceneLayer,
69 Rectangle worldPixelRange,
72 var result =
new List<SceneLayerTile>();
73 var candidateRange = TileBounds.GetTransformedTileCandidateRange(sceneLayer, worldPixelRange, includeOverhang);
74 var ul = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Left, candidateRange.Top));
75 var ur = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Right, candidateRange.Top));
76 var ll = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Left, candidateRange.Bottom));
77 var lr = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Right, candidateRange.Bottom));
79 int minX = (int)Math.Floor(
new[] { ul.X, ur.X, ll.X, lr.X }.Min()) - 1;
80 int maxX = (int)Math.Ceiling(
new[] { ul.X, ur.X, ll.X, lr.X }.Max()) + 1;
81 int minY = (int)Math.Floor(
new[] { ul.Y, ur.Y, ll.Y, lr.Y }.Min()) - 1;
82 int maxY = (int)Math.Ceiling(
new[] { ul.Y, ur.Y, ll.Y, lr.Y }.Max()) + 1;
84 for (
int y = minY; y <= maxY; y++)
86 for (
int x = minX; x <= maxX; x++)
88 var gp = sceneLayer[x, y];
93 var r = GetPixelRangeForTile(gp, includeOverhang);
95 if (r.IntersectsWith(worldPixelRange))
109 public Rectangle GetPixelRangeForTile(Tile tile,
bool includeOverhang)
111 var top = GetAnchorPixelAtSceneLayerCoordinates(tile.SceneLayer, tile.SceneLayerCoordinates);
112 int W = tile.SceneLayer.TileWidth;
113 int H = tile.SceneLayer.TileHeight;
121 return TileBounds.ApplyTileGeometry(rect, tile, includeOverhang);
130 public Rectangle GetPixelRangeForTileList(List<Tile> tileList,
bool includeOverhang)
134 foreach (var t
in tileList)
136 var r = GetPixelRangeForTile(t, includeOverhang);
137 ret = ret.IsEmpty ? r :
Rectangle.Union(ret, r);
149 public SceneLayerTile GetAdjacentSceneLayerTile(SceneLayerTile gp,
CardinalDirections dir)
157 CardinalDirections.N => m.ResolveWrappedTile(x, y - 1),
158 CardinalDirections.S => m.ResolveWrappedTile(x, y + 1),
159 CardinalDirections.E => m.ResolveWrappedTile(x + 1, y),
160 CardinalDirections.W => m.ResolveWrappedTile(x - 1, y),
161 CardinalDirections.NE => m.ResolveWrappedTile(x + 1, y - 1),
162 CardinalDirections.NW => m.ResolveWrappedTile(x - 1, y - 1),
163 CardinalDirections.SE => m.ResolveWrappedTile(x + 1, y + 1),
164 CardinalDirections.SW => m.ResolveWrappedTile(x - 1, y + 1),
175 public Point[] GetPolygonPts(Tile tile,
bool includeOverhang)
177 var top = GetAnchorPixelAtSceneLayerCoordinates(tile.SceneLayer, tile.SceneLayerCoordinates);
178 int W = tile.SceneLayer.TileWidth;
179 int H = tile.SceneLayer.TileHeight;
180 var oh = includeOverhang ? tile.Overhang :
Spacing.None;
184 new Point(top.X, top.Y - oh.Top),
185 new Point(top.X +
W / 2 + oh.Right, top.Y + H / 2),
186 new Point(top.X, top.Y + H + oh.Bottom),
187 new Point(top.X -
W / 2 - oh.Left, top.Y + H / 2)
198 public PointF FindEquivalentSceneLayerCoordinates(PointF valColRow,
int xUpperBound,
int yUpperBound)
200 float modX = valColRow.X % (xUpperBound + 1);
201 float modY = valColRow.Y % (yUpperBound + 1);
204 modX += xUpperBound + 1;
207 modY += yUpperBound + 1;
209 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.
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.