namespace TraceCad.Core.Geometry;

public readonly record struct Vector2(double X, double Y)
{
    public double Length => Math.Sqrt((X * X) + (Y * Y));

    public Vector2 Normalized()
    {
        var length = Length;
        return length <= GeometryConstants.Epsilon ? new Vector2(0.0, 0.0) : new Vector2(X / length, Y / length);
    }

    public double Dot(Vector2 other) => (X * other.X) + (Y * other.Y);

    public double Cross(Vector2 other) => (X * other.Y) - (Y * other.X);

    public static Vector2 operator +(Vector2 left, Vector2 right) =>
        new(left.X + right.X, left.Y + right.Y);

    public static Vector2 operator -(Vector2 left, Vector2 right) =>
        new(left.X - right.X, left.Y - right.Y);

    public static Vector2 operator *(Vector2 vector, double scalar) =>
        new(vector.X * scalar, vector.Y * scalar);
}
