refactor: Circle
This commit is contained in:
parent
5c185a664c
commit
5170dd0aea
|
@ -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;
|
||||||
float distanceSquared = (Position - other.Position).LengthSquared();
|
|
||||||
float radiusSumSquared = Radius * Radius + other.Radius * other.Radius;
|
|
||||||
|
|
||||||
return distanceSquared < radiusSumSquared;
|
public static bool ApproximatelyEquals(Circle left, Circle right)
|
||||||
}
|
=> left.Position.ApproximatelyEquals(right.Position) && left.Radius.ApproximatelyEquals(right.Radius);
|
||||||
|
}
|
||||||
public bool Overlaps(Vector2D point) => (Position - point).LengthSquared() <= Radius * Radius;
|
|
||||||
public bool ApproximatelyEquals(Circle other)
|
public static class CircleExtensions
|
||||||
=> Position.ApproximatelyEquals(other.Position) && Radius.ApproximatelyEquals(other.Radius);
|
{
|
||||||
|
public static bool ApproximatelyEquals(this Circle left, Circle right) => Circle.ApproximatelyEquals(left, right);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue