23internal sealed class ObliqueRightCoordinates : ISceneLayerCoordinates
32 public Point GetAnchorPixelAtSceneLayerCoordinates(SceneLayer sceneLayer, PointF layerPoint)
34 GetGeometry(sceneLayer, out _, out
int H, out
int skewX, out
int faceWidth);
36 float x = -sceneLayer.OriginPx.X
37 + layerPoint.X * faceWidth
38 + layerPoint.Y * skewX;
40 float y = -sceneLayer.OriginPx.Y
54 public PointF GetSceneLayerCoordinatesAtPixel(SceneLayer sceneLayer, PointF pixelPt)
56 GetGeometry(sceneLayer, out _, out
int H, out
int skewX, out
int faceWidth);
58 float row = (pixelPt.Y + sceneLayer.
OriginPx.Y) / H;
59 float col = (pixelPt.X + sceneLayer.OriginPx.X - row * skewX) / faceWidth;
61 return new PointF(col, row);
71 public List<SceneLayerTile> GetSceneLayerTilesInPixelRange(
72 SceneLayer sceneLayer,
73 Rectangle worldPixelRange,
76 var result =
new List<SceneLayerTile>();
77 var candidateRange = TileBounds.GetTransformedTileCandidateRange(sceneLayer, worldPixelRange, includeOverhang);
79 var upperLeft = GetSceneLayerCoordinatesAtPixel(
81 new PointF(candidateRange.Left, candidateRange.Top));
83 var upperRight = GetSceneLayerCoordinatesAtPixel(
85 new PointF(candidateRange.Right, candidateRange.Top));
87 var lowerLeft = GetSceneLayerCoordinatesAtPixel(
89 new PointF(candidateRange.Left, candidateRange.Bottom));
91 var lowerRight = GetSceneLayerCoordinatesAtPixel(
93 new PointF(candidateRange.Right, candidateRange.Bottom));
95 int minX = (int)Math.Floor(
new[]
103 int maxX = (int)Math.Ceiling(
new[]
111 int minY = (int)Math.Floor(
new[]
119 int maxY = (int)Math.Ceiling(
new[]
127 for (
int y = minY; y <= maxY; y++)
129 for (
int x = minX; x <= maxX; x++)
131 var tile = sceneLayer[x, y];
135 var tileRange = GetPixelRangeForTile(tile, includeOverhang);
136 if (tileRange.IntersectsWith(worldPixelRange))
150 public Rectangle GetPixelRangeForTile(Tile tile,
bool includeOverhang)
152 var anchor = GetAnchorPixelAtSceneLayerCoordinates(
154 tile.SceneLayerCoordinates);
159 tile.SceneLayer.TileWidth,
160 tile.SceneLayer.TileHeight);
162 return TileBounds.ApplyTileGeometry(baseRect, tile, includeOverhang);
171 public Rectangle GetPixelRangeForTileList(List<Tile> tileList,
bool includeOverhang)
175 foreach (var tile
in tileList)
177 var tileRange = GetPixelRangeForTile(tile, includeOverhang);
178 result = result.IsEmpty
193 public SceneLayerTile GetAdjacentSceneLayerTile(
194 SceneLayerTile layerPoint,
201 return direction
switch
203 CardinalDirections.N => sceneLayer.ResolveWrappedTile(x, y - 1),
204 CardinalDirections.NE => sceneLayer.ResolveWrappedTile(x + 1, y - 1),
205 CardinalDirections.E => sceneLayer.ResolveWrappedTile(x + 1, y),
206 CardinalDirections.SE => sceneLayer.ResolveWrappedTile(x + 1, y + 1),
207 CardinalDirections.S => sceneLayer.ResolveWrappedTile(x, y + 1),
208 CardinalDirections.SW => sceneLayer.ResolveWrappedTile(x - 1, y + 1),
209 CardinalDirections.W => sceneLayer.ResolveWrappedTile(x - 1, y),
210 CardinalDirections.NW => sceneLayer.ResolveWrappedTile(x - 1, y - 1),
221 public Point[] GetPolygonPts(Tile tile,
bool includeOverhang)
230 var anchor = GetAnchorPixelAtSceneLayerCoordinates(
232 tile.SceneLayerCoordinates);
234 var overhang = includeOverhang
241 anchor.X - overhang.Left,
242 anchor.Y - overhang.Top),
245 anchor.X + faceWidth + overhang.Right,
246 anchor.Y - overhang.Top),
249 anchor.X +
W + overhang.Right,
250 anchor.Y + H + overhang.Bottom),
253 anchor.X + skewX - overhang.Left,
254 anchor.Y + H + overhang.Bottom)
265 public PointF FindEquivalentSceneLayerCoordinates(
270 float modX = valColRow.X % (xUpperBound + 1);
271 float modY = valColRow.Y % (yUpperBound + 1);
274 modX += xUpperBound + 1;
277 modY += yUpperBound + 1;
279 return new PointF(modX, modY);
282 private static void GetGeometry(
283 SceneLayer sceneLayer,
295 faceWidth = width - skewX;
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.