using System;
using System.Diagnostics;
namespace Engine.Core;
/// 
/// Represents a 2D circle.
/// 
/// The center of the circle.
/// The radius of the circle.
/// 
/// Initializes a new instance of the  struct with the specified center and radius.
/// 
[DebuggerDisplay("Center: {Center.ToString(),nq}, Radius: {Radius}")]
public readonly struct Circle(Vector2D center, float radius) : IEquatable
{
    /// 
    /// The center of the .
    /// 
    public readonly Vector2D Center = center;
    /// 
    /// The radius of the .
    /// 
    public readonly float Radius = radius;
    /// 
    /// Gets the squared radius of the .
    /// 
    public readonly float RadiusSquared => Radius * Radius;
    /// 
    /// Gets the diameter of the .
    /// 
    public readonly float Diameter => 2f * Radius;
    /// 
    /// A predefined unit  with a center at the origin and a radius of 1.
    /// 
    public static readonly Circle UnitCircle = new(Vector2D.Zero, 1f);
    public static bool operator ==(Circle left, Circle right) => left.Center == right.Center && left.Radius == right.Radius;
    public static bool operator !=(Circle left, Circle right) => left.Center != right.Center || left.Radius != right.Radius;
    public static implicit operator Circle(Sphere3D sphere) => new(sphere.Center, sphere.Radius);
    /// 
    /// Sets the center of the .
    /// 
    public static Circle SetCenter(Circle circle, Vector2D center) => new(center, circle.Radius);
    /// 
    /// Sets the radius of the .
    /// 
    public static Circle SetRadius(Circle circle, float radius) => new(circle.Center, radius);
    /// 
    /// Displaces the  by the specified .
    /// 
    public static Circle Displace(Circle circle, Vector2D displaceVector) => new(circle.Center + displaceVector, circle.Radius);
    /// 
    /// Projects the  onto the specified .
    /// 
    public static Projection1D Project(Circle circle, Vector2D projectionVector)
    {
        float projectedCenter = circle.Center.Dot(projectionVector);
        return new(projectedCenter - circle.Radius, projectedCenter + circle.Radius);
    }
    /// 
    /// Transforms the  by the specified .
    /// 
    public static Circle Transform(ITransform2D transform, Circle circle)
        => new(transform.Transform(circle.Center), circle.Radius * (transform.Scale.Magnitude / Vector2D.One.Magnitude));
    /// 
    /// Checks if two s are approximately equal.
    /// 
    /// The first .
    /// The second .
    /// The epsilon range.
    ///  if the s are approximately equal; otherwise, .
    public static bool ApproximatelyEquals(Circle left, Circle right, float epsilon = float.Epsilon)
        => left.Center.ApproximatelyEquals(right.Center, epsilon) && left.Radius.ApproximatelyEquals(right.Radius, epsilon);
    /// 
    /// Determines whether the specified object is equal to the current .
    /// 
    /// The object to compare with the current .
    ///  if the specified object is equal to the current ; otherwise, .
    public override bool Equals(object? obj) => obj is Circle circle && this == circle;
    public bool Equals(Circle other) => this == other;
    /// 
    /// Generates a hash code for the .
    /// 
    /// A hash code for the .
    public override int GetHashCode() => System.HashCode.Combine(Center, Radius);
    /// 
    /// Converts the  to its string representation.
    /// 
    /// A string representation of the .
    public override string ToString() => $"{nameof(Circle)}({Center}, {Radius})";
}
/// 
/// Provides extension methods for the  struct.
/// 
public static class CircleExtensions
{
    /// 
    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);
    /// 
    public static Projection1D ProjectTo(this Circle circle, Vector2D projectionVector) => Circle.Project(circle, projectionVector);
    /// 
    public static Circle Transform(this ITransform2D transform, Circle circle) => Circle.Transform(transform, circle);
    /// 
    public static Circle Transform(this Circle circle, ITransform2D transform) => Circle.Transform(transform, circle);
    /// 
    public static bool ApproximatelyEquals(this Circle left, Circle right, float epsilon = float.Epsilon) => Circle.ApproximatelyEquals(left, right, epsilon);
}