Engine-Pong/Game/Physics2D/Primitives/Circle.cs

19 lines
649 B
C#
Raw Normal View History

2024-01-23 12:16:58 +03:00
using Syntriax.Engine.Core;
2023-12-07 10:55:49 +03:00
namespace Syntriax.Engine.Physics2D.Primitives;
2024-01-23 12:16:58 +03:00
public record Circle(Vector2D Position, float Radius)
2023-12-07 10:55:49 +03:00
{
2023-12-07 11:14:18 +03:00
public bool Intersects(Circle other)
2023-12-07 10:55:49 +03:00
{
2023-12-07 11:14:18 +03:00
float distanceSquared = (Position - other.Position).LengthSquared();
float radiusSumSquared = Radius * Radius + other.Radius * other.Radius;
2023-12-07 10:55:49 +03:00
return distanceSquared < radiusSumSquared;
}
2024-01-23 12:16:58 +03:00
public bool Overlaps(Vector2D point) => (Position - point).LengthSquared() <= Radius * Radius;
2023-12-07 11:14:18 +03:00
public bool ApproximatelyEquals(Circle other)
=> Position.ApproximatelyEquals(other.Position) && Radius.ApproximatelyEquals(other.Radius);
2023-12-07 10:55:49 +03:00
}