using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Media; namespace AIStudio.Wpf.DiagramDesigner { public class PointInfoBase : BindableBase { public static PointInfoBase Zero { get; } = new PointInfoBase(0, 0); public PointInfoBase() { ColorViewModel = new ColorViewModel() { LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) }, FillColor = new ColorObject() { Color = Colors.Lavender }, }; } public PointInfoBase(Point point) : this() { X = point.X; Y = point.Y; } public PointInfoBase(double x, double y) : this() { X = x; Y = y; } private double _x; public double X { get { return _x; } set { if(SetProperty(ref _x, value)) { RaisePropertyChanged(nameof(Left)); } } } private double _y; public double Y { get { return _y; } set { if (SetProperty(ref _y, value)) { RaisePropertyChanged(nameof(Top)); } } } public double Left { get { return X - ConnectorWidth / 2; } } public double Top { get { return Y - ConnectorHeight / 2; } } private double connectorWidth = 8; public double ConnectorWidth { get { return connectorWidth; } set { connectorWidth = value; } } private double connectorHeight = 8; public double ConnectorHeight { get { return connectorHeight; } set { connectorHeight = value; } } private IColorViewModel _colorViewModel; public IColorViewModel ColorViewModel { get { return _colorViewModel; } set { SetProperty(ref _colorViewModel, value); } } public double Dot(PointInfoBase other) => X * other.X + Y * other.Y; public PointInfoBase Lerp(PointInfoBase other, double t) => new PointInfoBase(X * (1.0 - t) + other.X * t, Y * (1.0 - t) + other.Y * t); // Maybe just make Points mutable? public PointInfoBase Add(double value) => new PointInfoBase(X + value, Y + value); public PointInfoBase Add(double x, double y) => new PointInfoBase(X + x, Y + y); public PointInfoBase Substract(double value) => new PointInfoBase(X - value, Y - value); public PointInfoBase Substract(double x, double y) => new PointInfoBase(X - x, Y - y); public double DistanceTo(PointInfoBase other) => Math.Sqrt(Math.Pow(X - other.X, 2) + Math.Pow(Y - other.Y, 2)); public void Deconstruct(out double x, out double y) { x = X; y = Y; } public static PointInfoBase operator -(PointInfoBase a, PointInfoBase b) { return new Point(a.X - b.X, a.Y - b.Y); } public static PointInfoBase operator +(PointInfoBase a, PointInfoBase b) { return new Point(a.X + b.X, a.Y + b.Y); } public static implicit operator PointInfoBase(Point point) { return new PointInfoBase(point); } public static implicit operator Point(PointInfoBase pointInfoBase) { return new Point(pointInfoBase.X, pointInfoBase.Y); } public static List ToList(List lst) { return lst.Select(p => (PointInfoBase)p).ToList(); } public override string ToString() => $"PointInfoBase(x={X}, y={Y})"; } }