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(SceneLayer sceneLayer, Rectangle worldPixelRange,
bool includeOverhang)
69 var result =
new List<SceneLayerTile>();
70 var candidateRange = TileBounds.GetTransformedTileCandidateRange(sceneLayer, worldPixelRange, includeOverhang);
71 var ul = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Left, candidateRange.Top));
72 var ur = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Right, candidateRange.Top));
73 var ll = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Left, candidateRange.Bottom));
74 var lr = GetSceneLayerCoordinatesAtPixel(sceneLayer,
new PointF(candidateRange.Right, candidateRange.Bottom));
76 int minX = (int)Math.Floor(
new[] { ul.X, ur.X, ll.X, lr.X }.Min()) - 1;
77 int maxX = (int)Math.Ceiling(
new[] { ul.X, ur.X, ll.X, lr.X }.Max()) + 1;
78 int minY = (int)Math.Floor(
new[] { ul.Y, ur.Y, ll.Y, lr.Y }.Min()) - 1;
79 int maxY = (int)Math.Ceiling(
new[] { ul.Y, ur.Y, ll.Y, lr.Y }.Max()) + 1;
81 for (
int y = minY; y <= maxY; y++)
83 for (
int x = minX; x <= maxX; x++)
85 var gp = sceneLayer[x, y];
86 if (gp ==
null)
continue;
87 var r = GetPixelRangeForTile(gp, includeOverhang);
88 if (r.IntersectsWith(worldPixelRange)) result.Add(gp);
100 public Rectangle GetPixelRangeForTile(Tile tile,
bool includeOverhang)
102 var top = GetAnchorPixelAtSceneLayerCoordinates(tile.SceneLayer, tile.SceneLayerCoordinates);
103 int W = tile.SceneLayer.TileWidth;
int H = tile.SceneLayer.TileHeight;
104 var rect =
new Rectangle(top.X -
W / 2, top.Y,
W, H);
105 return TileBounds.ApplyTileGeometry(rect, tile, includeOverhang);
114 public Rectangle GetPixelRangeForTileList(List<Tile> tileList,
bool includeOverhang)
117 foreach (var t
in tileList)
119 var r = GetPixelRangeForTile(t, includeOverhang);
120 ret = ret.IsEmpty ? r :
Rectangle.Union(ret, r);
131 public SceneLayerTile GetAdjacentSceneLayerTile(SceneLayerTile gp,
CardinalDirections dir)
136 CardinalDirections.N => m.ResolveWrappedTile(x, y - 1),
137 CardinalDirections.S => m.ResolveWrappedTile(x, y + 1),
138 CardinalDirections.E => m.ResolveWrappedTile(x + 1, y),
139 CardinalDirections.W => m.ResolveWrappedTile(x - 1, y),
140 CardinalDirections.NE => m.ResolveWrappedTile(x + 1, y - 1),
141 CardinalDirections.NW => m.ResolveWrappedTile(x - 1, y - 1),
142 CardinalDirections.SE => m.ResolveWrappedTile(x + 1, y + 1),
143 CardinalDirections.SW => m.ResolveWrappedTile(x - 1, y + 1),
154 public Point[] GetPolygonPts(Tile tile,
bool includeOverhang)
156 var top = GetAnchorPixelAtSceneLayerCoordinates(tile.SceneLayer, tile.SceneLayerCoordinates);
157 int W = tile.SceneLayer.TileWidth;
int H = tile.SceneLayer.TileHeight;
158 var oh = includeOverhang ? tile.Overhang :
Spacing.None;
162 new Point(top.X, top.Y - oh.Top),
163 new Point(top.X +
W/2 + oh.Right, top.Y + H/2),
164 new Point(top.X, top.Y + H + oh.Bottom),
165 new Point(top.X -
W/2 - oh.Left, top.Y + H/2)
176 public PointF FindEquivalentSceneLayerCoordinates(PointF valColRow,
int xUpperBound,
int yUpperBound)
178 float modX = valColRow.X % (xUpperBound + 1);
179 float modY = valColRow.Y % (yUpperBound + 1);
180 if (modX < 0) modX += xUpperBound + 1;
181 if (modY < 0) modY += yUpperBound + 1;
182 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.