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 record Circle(Vector2D Position, float Radius)
{ {
public bool Intersects(Circle other) public float RadiusSquared => Radius * Radius;
public float Diameter => 2f * Radius;
public static bool ApproximatelyEquals(Circle left, Circle right)
=> left.Position.ApproximatelyEquals(right.Position) && left.Radius.ApproximatelyEquals(right.Radius);
}
public static class CircleExtensions
{ {
float distanceSquared = (Position - other.Position).LengthSquared(); public static bool ApproximatelyEquals(this Circle left, Circle right) => Circle.ApproximatelyEquals(left, right);
float radiusSumSquared = Radius * Radius + other.Radius * other.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);
} }