using System;

namespace InterpreterLibrary.Models
{
    public struct PointF
    {
        public PointF(float x, float y)
        {
            X = x;
            Y = y;
        }

        public float X { get; set; }
        public float Y { get; set; }

        public static implicit operator PointF(CrossCutting.PointF source)
        {
            return new PointF(source.X, source.Y);
        }

        public static implicit operator CrossCutting.PointF(PointF source)
        {
            return new CrossCutting.PointF(source.X, source.Y);
        }

        public static bool operator ==(PointF point1, PointF point2)
        {
            if (ReferenceEquals(point1, point2))
                return true;

            if ((object) point1 == null || (object) point2 == null)
                return false;

            return point1.X == point2.X && point1.Y == point2.Y;
        }

        public static implicit operator PointF(System.Drawing.PointF source)
        {
            return new PointF(source.X, source.Y);
        }

        public static implicit operator System.Drawing.PointF(PointF source)
        {
            return new System.Drawing.PointF(source.X, source.Y);
        }

        public static bool operator !=(PointF line1, PointF line2)
        {
            return !(line1 == line2);
        }

        public float DistanceTo(PointF start)
        {
            return (float) Math.Sqrt((X - start.X) * (X - start.X) + (Y - start.Y) * (Y - start.Y));
        }

        public override string ToString()
        {
            return $"({X}, {Y})";
        }
    }
}
