28public static class TileTransformGeometry
34 public static PointF TransformPoint(PointF point,
TileTransform transform) => transform
switch
36 TileTransform.Identity => point,
37 TileTransform.Rotate90 =>
new(-point.Y, point.X),
39 TileTransform.Rotate270 =>
new(point.Y, -point.X),
41 TileTransform.FlipVertical =>
new(point.X, -point.Y),
43 TileTransform.FlipAntiDiagonal =>
new(-point.Y, -point.X),
44 _ =>
throw new ArgumentOutOfRangeException(nameof(transform))
51 public static Size TransformSize(Size size,
TileTransform transform)
53 var point = TransformPoint(
new(size.Width, size.Height), transform);
54 return new((int)Math.Abs(point.X), (
int)Math.Abs(point.Y));
63 TileTransform.Identity => value,
64 TileTransform.Rotate90 =>
new(value.Bottom, value.Left, value.Top, value.Right),
65 TileTransform.Rotate180 =>
new(value.Right, value.Bottom, value.Left, value.Top),
66 TileTransform.Rotate270 =>
new(value.Top, value.Right, value.Bottom, value.Left),
67 TileTransform.FlipHorizontal =>
new(value.Right, value.Top, value.Left, value.Bottom),
68 TileTransform.FlipVertical =>
new(value.Left, value.Bottom, value.Right, value.Top),
69 TileTransform.FlipDiagonal =>
new(value.Top, value.Left, value.Bottom, value.Right),
70 TileTransform.FlipAntiDiagonal =>
new(value.Bottom, value.Right, value.Top, value.Left),
71 _ =>
throw new ArgumentOutOfRangeException(nameof(transform))
78 public static CollisionAdjust TransformCollisionAdjust(CollisionAdjust value,
TileTransform transform)
80 var edges = TransformSpacing(
new(value.
Left, value.
Top, value.
Right, value.
Bottom), transform);
81 return new(edges.Top, edges.Bottom, edges.Left, edges.Right);
90 var x = TransformPoint(TransformPoint(
new(1, 0), current), operation);
91 var y = TransformPoint(TransformPoint(
new(0, 1), current), operation);
93 if (TransformPoint(
new(1, 0), candidate) == x && TransformPoint(
new(0, 1), candidate) == y)
95 throw new InvalidOperationException(
"Orthogonal transforms must be closed under composition.");
105 var size = TransformSize(cell.Size, transform);
106 int x = cell.X + (int)Math.Floor((cell.Width - size.Width) / 2d);
107 int y = cell.Y + (int)Math.Floor((cell.Height - size.Height) / 2d);
108 var edges = TransformSpacing(sourceOverhang, transform);
109 return Rectangle.FromLTRB(x - edges.Left, y - edges.Top, x + size.Width + edges.Right, y + size.Height + edges.Bottom);
117 public static PointF MapToDestination(PointF normalizedPoint, RectangleF destination,
TileTransform transform)
119 var point = TransformPoint(
new(normalizedPoint.X - .5f, normalizedPoint.Y - .5f), transform);
120 return new(destination.X + (point.X + .5f) * destination.Width,
121 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.