35public static class TileTransformGeometry
41 public static PointF TransformPoint(PointF point,
TileTransform transform) => transform
switch
43 TileTransform.Identity => point,
44 TileTransform.Rotate90 =>
new(-point.Y, point.X),
46 TileTransform.Rotate270 =>
new(point.Y, -point.X),
48 TileTransform.FlipVertical =>
new(point.X, -point.Y),
50 TileTransform.FlipAntiDiagonal =>
new(-point.Y, -point.X),
51 _ =>
throw new ArgumentOutOfRangeException(nameof(transform))
58 public static Size TransformSize(Size size,
TileTransform transform)
60 var point = TransformPoint(
new(size.Width, size.Height), transform);
61 return new((int)Math.Abs(point.X), (
int)Math.Abs(point.Y));
70 TileTransform.Identity => value,
71 TileTransform.Rotate90 =>
new(
81 TileTransform.Rotate270 =>
new(
91 TileTransform.FlipVertical =>
new(
101 TileTransform.FlipAntiDiagonal =>
new(
106 _ =>
throw new ArgumentOutOfRangeException(nameof(transform))
113 public static CollisionAdjust TransformCollisionAdjust(CollisionAdjust value,
TileTransform transform)
115 var edges = TransformSpacing(
136 var x = TransformPoint(TransformPoint(
new(1, 0), current), operation);
137 var y = TransformPoint(TransformPoint(
new(0, 1), current), operation);
140 if (TransformPoint(
new(1, 0), candidate) == x && TransformPoint(
new(0, 1), candidate) == y)
143 throw new InvalidOperationException(
"Orthogonal transforms must be closed under composition.");
151 public static Spacing ScaleOverhang(Size sourceSize, Size cellSize,
Spacing sourceOverhang)
153 if (sourceOverhang.IsEmpty)
154 return sourceOverhang;
156 double footprintWidth = (double)sourceSize.Width - sourceOverhang.Left - sourceOverhang.Right;
157 double footprintHeight = (double)sourceSize.Height - sourceOverhang.Top - sourceOverhang.Bottom;
161 double scaleX = sourceSize.Width > 0 && footprintWidth > 0
162 ? cellSize.Width / footprintWidth
165 double scaleY = sourceSize.Height > 0 && footprintHeight > 0
166 ? cellSize.Height / footprintHeight
170 ScaleEdge(sourceOverhang.Left, scaleX),
171 ScaleEdge(sourceOverhang.Top, scaleY),
172 ScaleEdge(sourceOverhang.Right, scaleX),
173 ScaleEdge(sourceOverhang.Bottom, scaleY));
176 private static int ScaleEdge(
int edge,
double scale) =>
177 (int)Math.Round(edge * scale, MidpointRounding.AwayFromZero);
190 GetVisualBounds(cell, ScaleOverhang(sourceSize, cell.Size, sourceOverhang), transform);
199 var size = TransformSize(cell.Size, transform);
200 int x = cell.X + (int)Math.Floor((cell.Width - size.Width) / 2d);
201 int y = cell.Y + (int)Math.Floor((cell.Height - size.Height) / 2d);
202 var edges = TransformSpacing(sourceOverhang, transform);
207 x + size.Width + edges.Right,
208 y + size.Height + edges.Bottom);
216 public static PointF MapToDestination(PointF normalizedPoint, RectangleF destination,
TileTransform transform)
218 var point = TransformPoint(
new(normalizedPoint.X - .5f, normalizedPoint.Y - .5f), transform);
221 destination.X + (point.X + .5f) * destination.Width,
222 destination.Y + (point.Y + .5f) * destination.Height);
@ Rectangle
Particles are spawned uniformly within a rectangular area. This is the default distribution.
TileTransform
The eight orthogonal orientations of artwork placed in a fixed scene cell.
@ FlipDiagonal
Reflection across the top-left to bottom-right diagonal (axis swap).
@ FlipVertical
Reflection across the horizontal axis.
@ Rotate90
Clockwise quarter turn.
@ Rotate270
Counterclockwise quarter turn.
@ FlipAntiDiagonal
Reflection across the top-right to bottom-left diagonal.
@ Identity
Original orientation.
@ FlipHorizontal
Reflection across the vertical axis.
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.
int Top
Gets or sets the number of pixels by which to inset the top edge.
int Left
Gets or sets the number of pixels by which to inset the left edge.
int Bottom
Gets or sets the number of pixels by which to inset the bottom edge.
int Right
Gets or sets the number of pixels by which to inset the right edge.