2021-08-05 18:20:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
|
2022-10-28 22:45:39 +08:00
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
2021-08-05 18:20:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
public class PointInfoBase : BindableBase
|
|
|
|
|
|
{
|
2023-01-07 11:32:01 +08:00
|
|
|
|
public static PointInfoBase Zero { get; } = new PointInfoBase(0, 0);
|
|
|
|
|
|
|
2021-08-05 18:20:22 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-07 11:32:01 +08:00
|
|
|
|
public PointInfoBase(double x, double y) : this()
|
|
|
|
|
|
{
|
|
|
|
|
|
X = x;
|
|
|
|
|
|
Y = y;
|
|
|
|
|
|
}
|
2021-08-05 18:20:22 +08:00
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-07 11:32:01 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-05 18:20:22 +08:00
|
|
|
|
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<PointInfoBase> ToList(List<Point> lst)
|
|
|
|
|
|
{
|
|
|
|
|
|
return lst.Select(p => (PointInfoBase)p).ToList();
|
|
|
|
|
|
}
|
2023-01-07 11:32:01 +08:00
|
|
|
|
|
|
|
|
|
|
public override string ToString() => $"PointInfoBase(x={X}, y={Y})";
|
2021-08-05 18:20:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|