diff --git a/Engine.Physics2D/Abstract/IShapeCollider2D.cs b/Engine.Physics2D/Abstract/IShapeCollider2D.cs
index 4280d27..87aca76 100644
--- a/Engine.Physics2D/Abstract/IShapeCollider2D.cs
+++ b/Engine.Physics2D/Abstract/IShapeCollider2D.cs
@@ -3,17 +3,17 @@ using Syntriax.Engine.Physics2D.Primitives;
namespace Syntriax.Engine.Physics2D.Abstract;
///
-/// Represents a with a custom .
+/// Represents a with a custom .
///
public interface IShapeCollider2D : ICollider2D
{
///
- /// Gets or sets the local of the .
+ /// Gets or sets the local of the .
///
- Shape ShapeLocal { get; set; }
+ Shape2D ShapeLocal { get; set; }
///
- /// Gets the world space representation of the .
+ /// Gets the world space representation of the .
///
- Shape ShapeWorld { get; }
+ Shape2D ShapeWorld { get; }
}
diff --git a/Engine.Physics2D/Collider2DShapeBehaviour.cs b/Engine.Physics2D/Collider2DShapeBehaviour.cs
index 7a2681d..95de053 100644
--- a/Engine.Physics2D/Collider2DShapeBehaviour.cs
+++ b/Engine.Physics2D/Collider2DShapeBehaviour.cs
@@ -5,13 +5,13 @@ namespace Syntriax.Engine.Physics2D;
public class Collider2DShapeBehaviour : Collider2DBehaviourBase, IShapeCollider2D
{
- public Shape ShapeWorld { get => _shapeWorld; protected set => _shapeWorld = value; }
- public Shape ShapeLocal { get; set; } = Shape.Box;
+ public Shape2D ShapeWorld { get => _shapeWorld; protected set => _shapeWorld = value; }
+ public Shape2D ShapeLocal { get; set; } = Shape2D.Box;
- private Shape _shapeWorld = Shape.Box.CreateCopy();
+ private Shape2D _shapeWorld = Shape2D.Box.CreateCopy();
public override void CalculateCollider() => Transform.TransformShape(ShapeLocal, ref _shapeWorld);
public Collider2DShapeBehaviour() { }
- public Collider2DShapeBehaviour(Shape shape) => ShapeLocal = shape;
+ public Collider2DShapeBehaviour(Shape2D shape) => ShapeLocal = shape;
}
diff --git a/Engine.Physics2D/CollisionDetector2D.cs b/Engine.Physics2D/CollisionDetector2D.cs
index b944dde..e6fd1e7 100644
--- a/Engine.Physics2D/CollisionDetector2D.cs
+++ b/Engine.Physics2D/CollisionDetector2D.cs
@@ -49,8 +49,8 @@ public class CollisionDetector2D : ICollisionDetector2D
{
Vector2D projectionVector = vertices[indexProjection].FromTo(vertices[(indexProjection + 1) % count]).Perpendicular().Normalized;
- Projection leftProjection = left.ShapeWorld.ToProjection(projectionVector);
- Projection rightProjection = right.ShapeWorld.ToProjection(projectionVector);
+ Projection1D leftProjection = left.ShapeWorld.ToProjection(projectionVector);
+ Projection1D rightProjection = right.ShapeWorld.ToProjection(projectionVector);
if (!leftProjection.Overlaps(rightProjection, out float depth))
return false;
@@ -73,8 +73,8 @@ public class CollisionDetector2D : ICollisionDetector2D
{
Vector2D projectionVector = vertices[indexProjection].FromTo(vertices[(indexProjection + 1) % count]).Perpendicular().Normalized;
- Projection shapeProjection = shapeCollider.ShapeWorld.ToProjection(projectionVector);
- Projection circleProjection = circleCollider.CircleWorld.ToProjection(projectionVector);
+ Projection1D shapeProjection = shapeCollider.ShapeWorld.ToProjection(projectionVector);
+ Projection1D circleProjection = circleCollider.CircleWorld.ToProjection(projectionVector);
if (!shapeProjection.Overlaps(circleProjection, out float depth))
return false;
@@ -86,8 +86,8 @@ public class CollisionDetector2D : ICollisionDetector2D
{
Vector2D shapeToCircleProjectionVector = shapeCollider.Transform.Position.FromTo(circleCollider.CircleWorld.Center).Normalized;
- Projection shapeProjection = shapeCollider.ShapeWorld.ToProjection(shapeToCircleProjectionVector);
- Projection circleProjection = circleCollider.CircleWorld.ToProjection(shapeToCircleProjectionVector);
+ Projection1D shapeProjection = shapeCollider.ShapeWorld.ToProjection(shapeToCircleProjectionVector);
+ Projection1D circleProjection = circleCollider.CircleWorld.ToProjection(shapeToCircleProjectionVector);
if (!shapeProjection.Overlaps(circleProjection, out float depth))
return false;
@@ -105,8 +105,8 @@ public class CollisionDetector2D : ICollisionDetector2D
Vector2D leftToRightCenterProjectionVector = left.CircleWorld.Center.FromTo(right.CircleWorld.Center).Normalized;
- Projection leftProjection = left.CircleWorld.ToProjection(leftToRightCenterProjectionVector);
- Projection rightProjection = right.CircleWorld.ToProjection(leftToRightCenterProjectionVector);
+ Projection1D leftProjection = left.CircleWorld.ToProjection(leftToRightCenterProjectionVector);
+ Projection1D rightProjection = right.CircleWorld.ToProjection(leftToRightCenterProjectionVector);
bool collision = leftProjection.Overlaps(rightProjection, out float depth);
diff --git a/Engine.Physics2D/Physics2D.cs b/Engine.Physics2D/Physics2D.cs
index 64e0f80..60b9d8b 100644
--- a/Engine.Physics2D/Physics2D.cs
+++ b/Engine.Physics2D/Physics2D.cs
@@ -5,8 +5,8 @@ namespace Syntriax.Engine.Physics2D;
public static partial class Physics2D
{
- public static bool Overlaps(this Shape shape, Vector2D point) => Overlaps(shape, point, out float _);
- public static bool Overlaps(this Shape shape, Vector2D point, out float depth)
+ public static bool Overlaps(this Shape2D shape, Vector2D point) => Overlaps(shape, point, out float _);
+ public static bool Overlaps(this Shape2D shape, Vector2D point, out float depth)
{
depth = float.MaxValue;
System.Collections.Generic.IReadOnlyList vertices = shape.Vertices;
@@ -16,7 +16,7 @@ public static partial class Physics2D
{
Vector2D projectionVector = vertices[indexProjection].FromTo(vertices[(indexProjection + 1) % count]).Perpendicular().Normalized;
- Projection shapeProjection = shape.ToProjection(projectionVector);
+ Projection1D shapeProjection = shape.ToProjection(projectionVector);
float projectedPoint = point.Dot(projectionVector);
if (shapeProjection.Max < projectedPoint || shapeProjection.Min > projectedPoint)
@@ -90,5 +90,5 @@ public static partial class Physics2D
return originalTriangleArea.ApproximatelyEquals(pointTriangleAreasSum, float.Epsilon * 3f);
}
- public static bool LaysOn(this Vector2D point, Line line) => Line.Intersects(line, point);
+ public static bool LaysOn(this Vector2D point, Line2D line) => Line2D.Intersects(line, point);
}
diff --git a/Engine.Physics2D/Primitives/Circle.cs b/Engine.Physics2D/Primitives/Circle.cs
index 5e0ae2a..5787921 100644
--- a/Engine.Physics2D/Primitives/Circle.cs
+++ b/Engine.Physics2D/Primitives/Circle.cs
@@ -59,7 +59,7 @@ public readonly struct Circle(Vector2D center, float radius)
///
/// Projects the onto the specified .
///
- public static Projection Project(Circle circle, Vector2D projectionVector)
+ public static Projection1D Project(Circle circle, Vector2D projectionVector)
{
float projectedCenter = circle.Center.Dot(projectionVector);
return new(projectedCenter - circle.Radius, projectedCenter + circle.Radius);
@@ -101,7 +101,7 @@ public static class CircleExtensions
///
/// Projects the onto the specified .
///
- public static Projection ToProjection(this Circle circle, Vector2D projectionVector) => Circle.Project(circle, projectionVector);
+ public static Projection1D ToProjection(this Circle circle, Vector2D projectionVector) => Circle.Project(circle, projectionVector);
///
/// Transforms the by the specified .
diff --git a/Engine.Physics2D/Primitives/Line.cs b/Engine.Physics2D/Primitives/Line2D.cs
similarity index 60%
rename from Engine.Physics2D/Primitives/Line.cs
rename to Engine.Physics2D/Primitives/Line2D.cs
index 84447f4..920fda5 100644
--- a/Engine.Physics2D/Primitives/Line.cs
+++ b/Engine.Physics2D/Primitives/Line2D.cs
@@ -11,64 +11,64 @@ namespace Syntriax.Engine.Physics2D.Primitives;
///
/// Initializes a new instance of the Line struct with the specified endpoints.
///
-/// The starting point of the segment.
-/// The ending point of the segment.
+/// The starting point of the segment.
+/// The ending point of the segment.
[System.Diagnostics.DebuggerDisplay("From: {From.ToString(),nq}, To: {To.ToString(),nq}, Direction: {Direction.ToString(),nq}, Length: {Length}")]
-public readonly struct Line(Vector2D from, Vector2D to)
+public readonly struct Line2D(Vector2D from, Vector2D to)
{
///
- /// The starting point of the segment.
+ /// The starting point of the segment.
///
public readonly Vector2D From = from;
///
- /// The ending point of the segment.
+ /// The ending point of the segment.
///
public readonly Vector2D To = to;
///
- /// The reversed segment.
+ /// The reversed segment.
///
- public readonly Line Reversed => new(To, From);
+ public readonly Line2D Reversed => new(To, From);
///
- /// The normalized direction of the segment.
+ /// The normalized direction of the segment.
///
public readonly Vector2D Direction => From.FromTo(To).Normalize();
///
- /// The length of the segment.
+ /// The length of the segment.
///
public readonly float Length => From.FromTo(To).Length();
///
- /// The squared length of the segment.
+ /// The squared length of the segment.
///
public readonly float LengthSquared => From.FromTo(To).LengthSquared();
///
- /// The equation of the defined by this segment.
+ /// The equation of the defined by this segment.
///
- public static LineEquation GetLineEquation(Line line)
+ public static Line2DEquation GetLineEquation(Line2D line)
{
Vector2D slopeVector = line.From.FromTo(line.To);
float slope = slopeVector.Y / slopeVector.X;
float yOffset = line.From.Y - (slope * line.From.X);
- return new LineEquation(slope, yOffset);
+ return new Line2DEquation(slope, yOffset);
}
///
- /// Determines whether the specified lies on the .
+ /// Determines whether the specified lies on the .
///
- public static bool Intersects(Line line, Vector2D point)
- => LineEquation.Resolve(GetLineEquation(line), point.X).ApproximatelyEquals(point.Y);
+ public static bool Intersects(Line2D line, Vector2D point)
+ => Line2DEquation.Resolve(GetLineEquation(line), point.X).ApproximatelyEquals(point.Y);
///
- /// Calculates the parameter 't' representing the point's position on the segment.
+ /// Calculates the parameter 't' representing the point's position on the segment.
///
- public static float GetT(Line line, Vector2D point)
+ public static float GetT(Line2D line, Vector2D point)
{
float fromX = MathF.Abs(line.From.X);
float toX = MathF.Abs(line.To.X);
@@ -91,9 +91,9 @@ public readonly struct Line(Vector2D from, Vector2D to)
}
///
- /// Checks if the segment intersects with another segment.
+ /// Checks if the segment intersects with another segment.
///
- public static bool Intersects(Line left, Line right)
+ public static bool Intersects(Line2D left, Line2D right)
{
int o1 = Vector2D.Orientation(left.From, left.To, right.From);
int o2 = Vector2D.Orientation(left.From, left.To, right.To);
@@ -112,9 +112,9 @@ public readonly struct Line(Vector2D from, Vector2D to)
}
///
- /// Checks if the point lies within the segment.
+ /// Checks if the point lies within the segment.
///
- public static bool OnSegment(Line line, Vector2D point)
+ public static bool OnSegment(Line2D line, Vector2D point)
{
if (point.X <= MathF.Max(line.From.X, line.To.X) && point.X >= MathF.Min(line.From.X, line.To.X) &&
point.Y <= MathF.Max(line.From.Y, line.To.Y) && point.Y >= MathF.Min(line.From.Y, line.To.Y))
@@ -124,9 +124,9 @@ public readonly struct Line(Vector2D from, Vector2D to)
}
///
- /// Determines whether two segments intersect.
+ /// Determines whether two segments intersect.
///
- public static bool Intersects(Line left, Line right, [NotNullWhen(returnValue: true)] out Vector2D? point)
+ public static bool Intersects(Line2D left, Line2D right, [NotNullWhen(returnValue: true)] out Vector2D? point)
{
point = null;
@@ -139,15 +139,15 @@ public readonly struct Line(Vector2D from, Vector2D to)
}
///
- /// Finds the point of intersection between two segments.
+ /// Finds the point of intersection between two segments.
///
- public static Vector2D IntersectionPoint(Line left, Line right)
+ public static Vector2D IntersectionPoint(Line2D left, Line2D right)
=> Vector2D.Lerp(left.From, left.To, IntersectionParameterT(left, right));
///
- /// Calculates the parameter 't' representing the intersection point's position on the segment.
+ /// Calculates the parameter 't' representing the intersection point's position on the segment.
///
- public static float IntersectionParameterT(Line left, Line right)
+ public static float IntersectionParameterT(Line2D left, Line2D right)
{
float numerator = (left.From.X - right.From.X) * (right.From.Y - right.To.Y) - (left.From.Y - right.From.Y) * (right.From.X - right.To.X);
float denominator = (left.From.X - left.To.X) * (right.From.Y - right.To.Y) - (left.From.Y - left.To.Y) * (right.From.X - right.To.X);
@@ -160,21 +160,18 @@ public readonly struct Line(Vector2D from, Vector2D to)
}
///
- /// Linearly interpolates between the two endpoints of the segment using parameter 't'.
+ /// Linearly interpolates between the two endpoints of the segment using parameter 't'.
///
- public static Vector2D Lerp(Line line, float t)
- => new(
- line.From.X + (line.To.X - line.From.X) * t,
- line.From.Y + (line.To.Y - line.From.Y) * t
- );
+ public static Vector2D Lerp(Line2D line, float t)
+ => Vector2D.Lerp(line.From, line.To, t);
///
- /// Calculates the closest point on the segment to the specified point.
+ /// Calculates the closest point on the segment to the specified point.
///
- public static Vector2D ClosestPointTo(Line line, Vector2D point)
+ public static Vector2D ClosestPointTo(Line2D line, Vector2D point)
{
- Vector2D edgeVector = new(line.To.X - line.From.X, line.To.Y - line.From.Y);
- Vector2D pointVector = new(point.X - line.From.X, point.Y - line.From.Y);
+ Vector2D edgeVector = line.From.FromTo(line.To);
+ Vector2D pointVector = point - line.From;
float t = (pointVector.X * edgeVector.X + pointVector.Y * edgeVector.Y) / (edgeVector.X * edgeVector.X + edgeVector.Y * edgeVector.Y);
@@ -187,49 +184,49 @@ public readonly struct Line(Vector2D from, Vector2D to)
}
///
- /// Checks if two segments are approximately equal.
+ /// Checks if two segments are approximately equal.
///
- public static bool ApproximatelyEquals(Line left, Line right)
+ public static bool ApproximatelyEquals(Line2D left, Line2D right)
=> left.From.ApproximatelyEquals(right.From) && left.To.ApproximatelyEquals(right.To);
}
///
/// Provides extension methods for the Line struct.
///
-public static class LineExtensions
+public static class Line2DExtensions
{
///
- /// Linearly interpolates between the two endpoints of the segment using parameter 't'.
+ /// Linearly interpolates between the two endpoints of the segment using parameter 't'.
///
- public static Vector2D Lerp(this Line line, float t) => Line.Lerp(line, t);
+ public static Vector2D Lerp(this Line2D line, float t) => Line2D.Lerp(line, t);
///
- /// The equation of the defined by this segment.
+ /// The equation of the defined by this segment.
///
- public static LineEquation ToLineEquation(this Line line) => Line.GetLineEquation(line);
+ public static Line2DEquation ToLineEquation(this Line2D line) => Line2D.GetLineEquation(line);
///
- /// Determines whether the specified lies on the .
+ /// Determines whether the specified lies on the .
///
- public static bool Intersects(this Line line, Vector2D point) => Line.Intersects(line, point);
+ public static bool Intersects(this Line2D line, Vector2D point) => Line2D.Intersects(line, point);
///
- /// Calculates the parameter 't' representing the point's position on the segment.
+ /// Calculates the parameter 't' representing the point's position on the segment.
///
- public static float GetT(this Line line, Vector2D point) => Line.GetT(line, point);
+ public static float GetT(this Line2D line, Vector2D point) => Line2D.GetT(line, point);
///
- /// Checks if the segment intersects with another segment.
+ /// Checks if the segment intersects with another segment.
///
- public static bool Intersects(this Line left, Line right) => Line.Intersects(left, right);
+ public static bool Intersects(this Line2D left, Line2D right) => Line2D.Intersects(left, right);
///
- /// Determines whether two segments intersect.
+ /// Determines whether two segments intersect.
///
- public static bool Intersects(this Line left, Line right, [NotNullWhen(returnValue: true)] out Vector2D? point) => Line.Intersects(left, right, out point);
+ public static bool Intersects(this Line2D left, Line2D right, [NotNullWhen(returnValue: true)] out Vector2D? point) => Line2D.Intersects(left, right, out point);
///
- /// Checks if two s are approximately equal.
+ /// Checks if two s are approximately equal.
///
- public static bool ApproximatelyEquals(this Line left, Line right) => Line.ApproximatelyEquals(left, right);
+ public static bool ApproximatelyEquals(this Line2D left, Line2D right) => Line2D.ApproximatelyEquals(left, right);
}
diff --git a/Engine.Physics2D/Primitives/LineEquation.cs b/Engine.Physics2D/Primitives/Line2DEquation.cs
similarity index 75%
rename from Engine.Physics2D/Primitives/LineEquation.cs
rename to Engine.Physics2D/Primitives/Line2DEquation.cs
index 5640f47..b64f7a2 100644
--- a/Engine.Physics2D/Primitives/LineEquation.cs
+++ b/Engine.Physics2D/Primitives/Line2DEquation.cs
@@ -8,10 +8,10 @@ namespace Syntriax.Engine.Physics2D.Primitives;
/// The slope of the line.
/// The y-intercept of the line.
///
-/// Initializes a new instance of the struct with the specified slope and y-intercept.
+/// Initializes a new instance of the struct with the specified slope and y-intercept.
///
[System.Diagnostics.DebuggerDisplay("y = {Slope}x + {OffsetY}")]
-public readonly struct LineEquation(float slope, float offsetY)
+public readonly struct Line2DEquation(float slope, float offsetY)
{
///
/// The slope of the line equation.
@@ -29,7 +29,7 @@ public readonly struct LineEquation(float slope, float offsetY)
/// The line equation to resolve.
/// The x-coordinate for which to resolve the y-coordinate.
/// The y-coordinate resolved using the line equation.
- public static float Resolve(LineEquation lineEquation, float x) => lineEquation.Slope * x + lineEquation.OffsetY; // y = mx + b
+ public static float Resolve(Line2DEquation lineEquation, float x) => lineEquation.Slope * x + lineEquation.OffsetY; // y = mx + b
///
/// Checks if two line equations are approximately equal.
@@ -37,14 +37,14 @@ public readonly struct LineEquation(float slope, float offsetY)
/// The first line equation to compare.
/// The second line equation to compare.
/// True if the line equations are approximately equal; otherwise, false.
- public static bool ApproximatelyEquals(LineEquation left, LineEquation right)
+ public static bool ApproximatelyEquals(Line2DEquation left, Line2DEquation right)
=> left.Slope.ApproximatelyEquals(right.Slope) && left.OffsetY.ApproximatelyEquals(right.OffsetY);
}
///
/// Provides extension methods for the LineEquation struct.
///
-public static class LineEquationExtensions
+public static class Line2DEquationExtensions
{
///
/// Resolves the y-coordinate for a given x-coordinate using the line equation.
@@ -52,7 +52,7 @@ public static class LineEquationExtensions
/// The line equation to resolve.
/// The x-coordinate for which to resolve the y-coordinate.
/// The y-coordinate resolved using the line equation.
- public static float Resolve(this LineEquation lineEquation, float x) => LineEquation.Resolve(lineEquation, x);
+ public static float Resolve(this Line2DEquation lineEquation, float x) => Line2DEquation.Resolve(lineEquation, x);
///
/// Checks if two line equations are approximately equal.
@@ -60,5 +60,5 @@ public static class LineEquationExtensions
/// The first line equation to compare.
/// The second line equation to compare.
/// True if the line equations are approximately equal; otherwise, false.
- public static bool ApproximatelyEquals(this LineEquation left, LineEquation right) => LineEquation.ApproximatelyEquals(left, right);
+ public static bool ApproximatelyEquals(this Line2DEquation left, Line2DEquation right) => Line2DEquation.ApproximatelyEquals(left, right);
}
diff --git a/Engine.Physics2D/Primitives/Projection.cs b/Engine.Physics2D/Primitives/Projection1D.cs
similarity index 80%
rename from Engine.Physics2D/Primitives/Projection.cs
rename to Engine.Physics2D/Primitives/Projection1D.cs
index 1db3211..3ee27bd 100644
--- a/Engine.Physics2D/Primitives/Projection.cs
+++ b/Engine.Physics2D/Primitives/Projection1D.cs
@@ -6,10 +6,10 @@ namespace Syntriax.Engine.Physics2D.Primitives;
/// The minimum value of the projection.
/// The maximum value of the projection.
///
-/// Initializes a new instance of the struct with the specified minimum and maximum values.
+/// Initializes a new instance of the struct with the specified minimum and maximum values.
///
[System.Diagnostics.DebuggerDisplay("Min: {Min}, Max: {Max}")]
-public readonly struct Projection(float min, float max)
+public readonly struct Projection1D(float min, float max)
{
///
/// Gets the minimum value of the projection.
@@ -27,7 +27,7 @@ public readonly struct Projection(float min, float max)
/// The first projection to check.
/// The second projection to check.
/// if the projections overlap; otherwise, .
- public static bool Overlaps(Projection left, Projection right) => Overlaps(left, right, out float _);
+ public static bool Overlaps(Projection1D left, Projection1D right) => Overlaps(left, right, out float _);
///
/// Checks if two projections overlap and calculates the depth of the overlap.
@@ -36,7 +36,7 @@ public readonly struct Projection(float min, float max)
/// The second projection to check.
/// The depth of the overlap, if any.
/// if the projections overlap; otherwise, .
- public static bool Overlaps(Projection left, Projection right, out float depth)
+ public static bool Overlaps(Projection1D left, Projection1D right, out float depth)
{
// TODO Try to improve this
bool rightMinInLeft = right.Min > left.Min && right.Min < left.Max;
@@ -73,9 +73,9 @@ public readonly struct Projection(float min, float max)
}
///
-/// Provides extension methods for the struct.
+/// Provides extension methods for the struct.
///
-public static class ProjectionExtensions
+public static class Projection1DExtensions
{
///
/// Checks if two projections overlap.
@@ -83,7 +83,7 @@ public static class ProjectionExtensions
/// The first projection to check.
/// The second projection to check.
/// if the projections overlap; otherwise, .
- public static bool Overlaps(this Projection left, Projection right) => Projection.Overlaps(left, right);
+ public static bool Overlaps(this Projection1D left, Projection1D right) => Projection1D.Overlaps(left, right);
///
/// Checks if two projections overlap and calculates the depth of the overlap.
@@ -92,5 +92,5 @@ public static class ProjectionExtensions
/// The second projection to check.
/// The depth of the overlap, if any.
/// if the projections overlap; otherwise, .
- public static bool Overlaps(this Projection left, Projection right, out float depth) => Projection.Overlaps(left, right, out depth);
+ public static bool Overlaps(this Projection1D left, Projection1D right, out float depth) => Projection1D.Overlaps(left, right, out depth);
}
diff --git a/Engine.Physics2D/Primitives/Shape.cs b/Engine.Physics2D/Primitives/Shape2D.cs
similarity index 78%
rename from Engine.Physics2D/Primitives/Shape.cs
rename to Engine.Physics2D/Primitives/Shape2D.cs
index 0640196..335323e 100644
--- a/Engine.Physics2D/Primitives/Shape.cs
+++ b/Engine.Physics2D/Primitives/Shape2D.cs
@@ -11,15 +11,15 @@ namespace Syntriax.Engine.Physics2D.Primitives;
///
/// The vertices of the shape.
///
-/// Initializes a new instance of the struct with the specified vertices.
+/// Initializes a new instance of the struct with the specified vertices.
///
[System.Diagnostics.DebuggerDisplay("Vertices Count: {Vertices.Count}")]
-public readonly struct Shape(List vertices) : IEnumerable
+public readonly struct Shape2D(List vertices) : IEnumerable
{
- public static readonly Shape Triangle = CreateNgon(3, Vector2D.Up);
- public static readonly Shape Box = CreateNgon(4, Vector2D.One);
- public static readonly Shape Pentagon = CreateNgon(5, Vector2D.Up);
- public static readonly Shape Hexagon = CreateNgon(6, Vector2D.Right);
+ public static readonly Shape2D Triangle = CreateNgon(3, Vector2D.Up);
+ public static readonly Shape2D Box = CreateNgon(4, Vector2D.One);
+ public static readonly Shape2D Pentagon = CreateNgon(5, Vector2D.Up);
+ public static readonly Shape2D Hexagon = CreateNgon(6, Vector2D.Right);
private readonly List _verticesList = vertices;
@@ -40,14 +40,14 @@ public readonly struct Shape(List vertices) : IEnumerable
///
/// The shape to copy.
/// A copy of the input shape.
- public static Shape CreateCopy(Shape shape) => new(new List(shape.Vertices));
+ public static Shape2D CreateCopy(Shape2D shape) => new(new List(shape.Vertices));
///
/// Creates a regular polygon (ngon) with the specified number of vertices.
///
/// The number of vertices in the polygon.
/// A regular polygon with the specified number of vertices.
- public static Shape CreateNgon(int vertexCount) => CreateNgon(vertexCount, Vector2D.Up);
+ public static Shape2D CreateNgon(int vertexCount) => CreateNgon(vertexCount, Vector2D.Up);
///
/// Creates a regular polygon (ngon) with the specified number of vertices and a rotation position.
@@ -55,7 +55,7 @@ public readonly struct Shape(List vertices) : IEnumerable
/// The number of vertices in the polygon.
/// The position to use for rotation.
/// A regular polygon with the specified number of vertices and rotation position.
- public static Shape CreateNgon(int vertexCount, Vector2D positionToRotate)
+ public static Shape2D CreateNgon(int vertexCount, Vector2D positionToRotate)
{
if (vertexCount < 3)
throw new System.ArgumentException($"{nameof(vertexCount)} must have a value of more than 2.");
@@ -75,7 +75,7 @@ public readonly struct Shape(List vertices) : IEnumerable
///
/// The shape to enclose.
/// The super triangle that encloses the given shape.
- public static Triangle GetSuperTriangle(Shape shape)
+ public static Triangle GetSuperTriangle(Shape2D shape)
{
float minX = float.MaxValue, minY = float.MaxValue;
float maxX = float.MinValue, maxY = float.MinValue;
@@ -106,7 +106,7 @@ public readonly struct Shape(List vertices) : IEnumerable
///
/// The shape to get lines from.
/// The list to populate with lines.
- public static void GetLines(Shape shape, IList lines)
+ public static void GetLines(Shape2D shape, IList lines)
{
lines.Clear();
for (int i = 0; i < shape.Vertices.Count - 1; i++)
@@ -119,9 +119,9 @@ public readonly struct Shape(List vertices) : IEnumerable
///
/// The shape to get lines from.
/// A list of lines that form the edges of the shape.
- public static List GetLines(Shape shape)
+ public static List GetLines(Shape2D shape)
{
- List lines = new(shape.Vertices.Count - 1);
+ List lines = new(shape.Vertices.Count - 1);
GetLines(shape, lines);
return lines;
}
@@ -132,7 +132,7 @@ public readonly struct Shape(List vertices) : IEnumerable
/// The shape to project.
/// The vector to project onto.
/// The list to populate with projected values.
- public static void Project(Shape shape, Vector2D projectionVector, IList list)
+ public static void Project(Shape2D shape, Vector2D projectionVector, IList list)
{
list.Clear();
@@ -147,7 +147,7 @@ public readonly struct Shape(List vertices) : IEnumerable
/// The shape to project.
/// The vector to project onto.
/// The projection of the shape onto the vector.
- public static Projection Project(Shape shape, Vector2D projectionVector)
+ public static Projection1D Project(Shape2D shape, Vector2D projectionVector)
{
float min = float.MaxValue;
float max = float.MinValue;
@@ -168,7 +168,7 @@ public readonly struct Shape(List vertices) : IEnumerable
/// The shape to transform.
/// The transform to apply.
/// The transformed shape.
- public static Shape TransformShape(Shape shape, ITransform transform)
+ public static Shape2D TransformShape(Shape2D shape, ITransform transform)
{
List vertices = new(shape.Vertices.Count);
@@ -176,7 +176,7 @@ public readonly struct Shape(List vertices) : IEnumerable
for (int i = 0; i < count; i++)
vertices.Add(transform.TransformVector2D(shape[i]));
- return new Shape(vertices);
+ return new Shape2D(vertices);
}
///
@@ -185,7 +185,7 @@ public readonly struct Shape(List vertices) : IEnumerable
/// The shape to transform.
/// The transform to apply.
/// The transformed shape.
- public static void TransformShape(Shape from, ITransform transform, ref Shape to)
+ public static void TransformShape(Shape2D from, ITransform transform, ref Shape2D to)
{
to._verticesList.Clear();
@@ -200,7 +200,7 @@ public readonly struct Shape(List vertices) : IEnumerable
/// The first shape to compare.
/// The second shape to compare.
/// true if the shapes are approximately equal; otherwise, false.
- public static bool ApproximatelyEquals(Shape left, Shape right)
+ public static bool ApproximatelyEquals(Shape2D left, Shape2D right)
{
if (left.Vertices.Count != right.Vertices.Count)
return false;
@@ -220,37 +220,37 @@ public readonly struct Shape(List vertices) : IEnumerable
}
///
-/// Provides extension methods for the struct.
+/// Provides extension methods for the struct.
///
-public static class ShapeExtensions
+public static class Shape2DExtensions
{
///
/// Creates a copy of the shape.
///
/// The shape to copy.
/// A copy of the input shape.
- public static Shape CreateCopy(this Shape shape) => Shape.CreateCopy(shape);
+ public static Shape2D CreateCopy(this Shape2D shape) => Shape2D.CreateCopy(shape);
///
/// Gets the super triangle that encloses the shape.
///
/// The shape to enclose.
/// The super triangle that encloses the shape.
- public static Triangle ToSuperTriangle(this Shape shape) => Shape.GetSuperTriangle(shape);
+ public static Triangle ToSuperTriangle(this Shape2D shape) => Shape2D.GetSuperTriangle(shape);
///
/// Gets the lines that form the edges of the shape.
///
/// The shape to get lines from.
/// The list to populate with lines.
- public static void ToLines(this Shape shape, IList lines) => Shape.GetLines(shape, lines);
+ public static void ToLines(this Shape2D shape, IList lines) => Shape2D.GetLines(shape, lines);
///
/// Gets a list of lines that form the edges of the shape.
///
/// The shape to get lines from.
/// A list of lines that form the edges of the shape.
- public static List ToLines(this Shape shape) => Shape.GetLines(shape);
+ public static List ToLines(this Shape2D shape) => Shape2D.GetLines(shape);
///
/// Projects the shape onto a vector.
@@ -258,7 +258,7 @@ public static class ShapeExtensions
/// The shape to project.
/// The vector to project onto.
/// The list to populate with projected values.
- public static void ToProjection(this Shape shape, Vector2D projectionVector, IList list) => Shape.Project(shape, projectionVector, list);
+ public static void ToProjection(this Shape2D shape, Vector2D projectionVector, IList list) => Shape2D.Project(shape, projectionVector, list);
///
/// Projects the shape onto a vector.
@@ -266,7 +266,7 @@ public static class ShapeExtensions
/// The shape to project.
/// The vector to project onto.
/// The projection of the shape onto the vector.
- public static Projection ToProjection(this Shape shape, Vector2D projectionVector) => Shape.Project(shape, projectionVector);
+ public static Projection1D ToProjection(this Shape2D shape, Vector2D projectionVector) => Shape2D.Project(shape, projectionVector);
///
/// Transforms the shape using the specified transform.
@@ -274,7 +274,7 @@ public static class ShapeExtensions
/// The transform to apply.
/// The shape to transform.
/// The transformed shape.
- public static Shape TransformShape(this ITransform transform, Shape shape) => Shape.TransformShape(shape, transform);
+ public static Shape2D TransformShape(this ITransform transform, Shape2D shape) => Shape2D.TransformShape(shape, transform);
///
/// Transforms the shape using the specified transform.
@@ -282,7 +282,7 @@ public static class ShapeExtensions
/// The transform to apply.
/// The shape to transform.
/// The transformed shape.
- public static void TransformShape(this ITransform transform, Shape from, ref Shape to) => Shape.TransformShape(from, transform, ref to);
+ public static void TransformShape(this ITransform transform, Shape2D from, ref Shape2D to) => Shape2D.TransformShape(from, transform, ref to);
///
/// Determines whether two shapes are approximately equal.
@@ -290,5 +290,5 @@ public static class ShapeExtensions
/// The first shape to compare.
/// The second shape to compare.
/// true if the shapes are approximately equal; otherwise, false.
- public static bool ApproximatelyEquals(this Shape left, Shape right) => Shape.ApproximatelyEquals(left, right);
+ public static bool ApproximatelyEquals(this Shape2D left, Shape2D right) => Shape2D.ApproximatelyEquals(left, right);
}