2024-01-23 18:39:25 +03:00
|
|
|
using Syntriax.Engine.Core;
|
2024-01-24 19:21:53 +03:00
|
|
|
using Syntriax.Engine.Core.Abstract;
|
2024-01-23 18:39:25 +03:00
|
|
|
|
|
|
|
namespace Syntriax.Engine.Physics2D.Primitives;
|
|
|
|
|
2024-01-24 18:44:26 +03:00
|
|
|
public record Circle(Vector2D Center, float Radius)
|
2024-01-23 18:39:25 +03:00
|
|
|
{
|
2024-01-23 19:14:23 +03:00
|
|
|
public float RadiusSquared => Radius * Radius;
|
|
|
|
public float Diameter => 2f * Radius;
|
2024-01-23 18:39:25 +03:00
|
|
|
|
2024-01-24 19:21:53 +03:00
|
|
|
public static Circle SetCenter(Circle circle, Vector2D center) => new(center, circle.Radius);
|
|
|
|
public static Circle SetRadius(Circle circle, float radius) => new(circle.Center, radius);
|
|
|
|
|
|
|
|
public static Circle Displace(Circle circle, Vector2D displaceVector) => new(circle.Center + displaceVector, circle.Radius);
|
|
|
|
|
2024-01-26 12:41:51 +03:00
|
|
|
public static Projection Project(Circle circle, Vector2D projectionVector)
|
|
|
|
{
|
|
|
|
float projectedCenter = circle.Center.Dot(projectionVector);
|
|
|
|
return new(projectedCenter - circle.Radius, projectedCenter + circle.Radius);
|
|
|
|
}
|
|
|
|
|
2024-01-24 19:21:53 +03:00
|
|
|
public static Circle TransformCircle(ITransform transform, Circle circle)
|
|
|
|
=> new(transform.TransformVector2D(circle.Center), circle.Radius * transform.Scale.Magnitude);
|
|
|
|
|
2024-01-23 19:14:23 +03:00
|
|
|
public static bool ApproximatelyEquals(Circle left, Circle right)
|
2024-01-24 18:44:26 +03:00
|
|
|
=> left.Center.ApproximatelyEquals(right.Center) && left.Radius.ApproximatelyEquals(right.Radius);
|
2024-01-23 19:14:23 +03:00
|
|
|
}
|
2024-01-23 18:39:25 +03:00
|
|
|
|
2024-01-23 19:14:23 +03:00
|
|
|
public static class CircleExtensions
|
|
|
|
{
|
2024-01-24 19:21:53 +03:00
|
|
|
public static Circle SetCenter(this Circle circle, Vector2D center) => Circle.SetCenter(circle, center);
|
|
|
|
public static Circle SetRadius(this Circle circle, float radius) => Circle.SetRadius(circle, radius);
|
|
|
|
|
|
|
|
public static Circle Displace(this Circle circle, Vector2D displaceVector) => Circle.Displace(circle, displaceVector);
|
|
|
|
|
2024-01-26 12:41:51 +03:00
|
|
|
public static Projection ToProjection(this Circle circle, Vector2D projectionVector) => Circle.Project(circle, projectionVector);
|
|
|
|
|
2024-01-25 18:37:51 +03:00
|
|
|
public static Circle TransformCircle(this ITransform transform, Circle circle) => Circle.TransformCircle(transform, circle);
|
2024-01-24 19:21:53 +03:00
|
|
|
|
2024-01-23 19:14:23 +03:00
|
|
|
public static bool ApproximatelyEquals(this Circle left, Circle right) => Circle.ApproximatelyEquals(left, right);
|
2024-01-23 18:39:25 +03:00
|
|
|
}
|