refactor: Circle

This commit is contained in:
Syntriax 2024-01-23 19:14:23 +03:00
parent 5c185a664c
commit 5170dd0aea
1 changed files with 9 additions and 10 deletions

View File

@ -4,15 +4,14 @@ namespace Syntriax.Engine.Physics2D.Primitives;
public record Circle(Vector2D Position, float Radius)
{
public bool Intersects(Circle other)
{
float distanceSquared = (Position - other.Position).LengthSquared();
float radiusSumSquared = Radius * Radius + other.Radius * other.Radius;
public float RadiusSquared => Radius * Radius;
public float Diameter => 2f * Radius;
return distanceSquared < radiusSumSquared;
}
public bool Overlaps(Vector2D point) => (Position - point).LengthSquared() <= Radius * Radius;
public bool ApproximatelyEquals(Circle other)
=> Position.ApproximatelyEquals(other.Position) && Radius.ApproximatelyEquals(other.Radius);
public static bool ApproximatelyEquals(Circle left, Circle right)
=> left.Position.ApproximatelyEquals(right.Position) && left.Radius.ApproximatelyEquals(right.Radius);
}
public static class CircleExtensions
{
public static bool ApproximatelyEquals(this Circle left, Circle right) => Circle.ApproximatelyEquals(left, right);
}