mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-11 20:19:26 +08:00
整理,准备曲线算法
This commit is contained in:
@@ -9,6 +9,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class PointInfoBase : BindableBase
|
||||
{
|
||||
public static PointInfoBase Zero { get; } = new PointInfoBase(0, 0);
|
||||
|
||||
public PointInfoBase()
|
||||
{
|
||||
ColorViewModel = new ColorViewModel()
|
||||
@@ -24,6 +26,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Y = point.Y;
|
||||
}
|
||||
|
||||
public PointInfoBase(double x, double y) : this()
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
private double _x;
|
||||
public double X
|
||||
@@ -100,6 +107,36 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -114,5 +151,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
return lst.Select(p => (PointInfoBase)p).ToList();
|
||||
}
|
||||
|
||||
public override string ToString() => $"PointInfoBase(x={X}, y={Y})";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user