feat: Circle & Shape Projections
This commit is contained in:
@@ -53,6 +53,30 @@ public record Shape(IList<Vector2D> Vertices) : IEnumerable<Vector2D>
|
||||
return lines;
|
||||
}
|
||||
|
||||
public static void Project(Shape shape, Vector2D projectionVector, IList<float> list)
|
||||
{
|
||||
list.Clear();
|
||||
|
||||
int count = shape.Vertices.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
list.Add(projectionVector.Dot(shape[i]));
|
||||
}
|
||||
|
||||
public static Projection Project(Shape shape, Vector2D projectionVector)
|
||||
{
|
||||
float min = float.MaxValue;
|
||||
float max = float.MinValue;
|
||||
|
||||
foreach (var vertex in shape)
|
||||
{
|
||||
float projectedLength = projectionVector.Dot(vertex);
|
||||
min = Math.Min(projectedLength, min);
|
||||
max = Math.Max(projectedLength, max);
|
||||
}
|
||||
|
||||
return new(min, max);
|
||||
}
|
||||
|
||||
public static Shape TransformShape(Shape shape, ITransform transform)
|
||||
{
|
||||
List<Vector2D> vertices = new(shape.Vertices.Count);
|
||||
@@ -96,6 +120,9 @@ public static class ShapeExtensions
|
||||
public static void ToLines(this Shape shape, IList<Line> lines) => Shape.GetLines(shape, lines);
|
||||
public static List<Line> ToLines(this Shape shape) => Shape.GetLines(shape);
|
||||
|
||||
public static void ToProjection(this Shape shape, Vector2D projectionVector, IList<float> list) => Shape.Project(shape, projectionVector, list);
|
||||
public static Projection ToProjection(this Shape shape, Vector2D projectionVector) => Shape.Project(shape, projectionVector);
|
||||
|
||||
public static Shape TransformShape(this ITransform transform, Shape shape) => Shape.TransformShape(shape, transform);
|
||||
public static void TransformShape(this ITransform transform, Shape from, ref Shape to) => Shape.TransformShape(from, transform, ref to);
|
||||
|
||||
|
Reference in New Issue
Block a user