BREAKING CHANGE: New ICollider

This commit is contained in:
2024-01-24 19:21:53 +03:00
parent 350ef030ac
commit ed15238dcd
11 changed files with 123 additions and 77 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using Syntriax.Engine.Core;
using Syntriax.Engine.Core.Abstract;
namespace Syntriax.Engine.Physics2D.Primitives;
@@ -51,6 +52,26 @@ public record Shape(IList<Vector2D> Vertices) : IEnumerable<Vector2D>
return lines;
}
public static Shape TransformShape(Shape shape, ITransform transform)
{
List<Vector2D> vertices = new(shape.Vertices.Count);
int count = shape.Vertices.Count;
for (int i = 0; i < count; i++)
vertices.Add(transform.TransformVector2D(shape[i]));
return new Shape(vertices);
}
public static void TransformShape(Shape from, ITransform transform, ref Shape to)
{
to.Vertices.Clear();
int count = from.Vertices.Count;
for (int i = 0; i < count; i++)
to.Vertices.Add(transform.TransformVector2D(from[i]));
}
public static bool ApproximatelyEquals(Shape left, Shape right)
{
if (left.Vertices.Count != right.Vertices.Count)
@@ -73,5 +94,8 @@ 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 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);
public static bool ApproximatelyEquals(this Shape left, Shape right) => Shape.ApproximatelyEquals(left, right);
}