2023-01-08 09:22:37 +08:00
|
|
|
|
using System;
|
2023-01-12 23:02:53 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
2023-01-08 09:22:37 +08:00
|
|
|
|
|
|
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
|
|
|
|
{
|
|
|
|
|
|
public static partial class PathGenerators
|
|
|
|
|
|
{
|
2023-02-04 11:16:39 +08:00
|
|
|
|
public static double SourceMarkerAdjustement(PointBase[] route, double markerWidth, double markerHeight)
|
2023-01-08 09:22:37 +08:00
|
|
|
|
{
|
|
|
|
|
|
var angleInRadians = Math.Atan2(route[1].Y - route[0].Y, route[1].X - route[0].X) + Math.PI;
|
2023-01-16 22:38:58 +08:00
|
|
|
|
var xChange = markerWidth * Math.Cos(angleInRadians);
|
2023-02-04 12:17:03 +08:00
|
|
|
|
var yChange = markerHeight * Math.Sin(angleInRadians);
|
2023-01-16 22:38:58 +08:00
|
|
|
|
route[0] = new PointBase(route[0].X - xChange, route[0].Y - yChange);
|
2023-01-08 09:22:37 +08:00
|
|
|
|
return angleInRadians * 180 / Math.PI;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-04 11:16:39 +08:00
|
|
|
|
public static double TargetMarkerAdjustement(PointBase[] route, double markerWidth, double markerHeight)
|
2023-01-08 09:22:37 +08:00
|
|
|
|
{
|
|
|
|
|
|
var angleInRadians = Math.Atan2(route[route.Length - 1].Y - route[route.Length - 2].Y, route[route.Length - 1].X - route[route.Length - 2].X);
|
2023-01-16 22:38:58 +08:00
|
|
|
|
var xChange = markerWidth * Math.Cos(angleInRadians);
|
2023-02-04 12:17:03 +08:00
|
|
|
|
var yChange = markerHeight * Math.Sin(angleInRadians);
|
2023-01-16 22:38:58 +08:00
|
|
|
|
route[route.Length - 1] = new PointBase(route[route.Length - 1].X - xChange, route[route.Length - 1].Y - yChange);
|
2023-01-08 09:22:37 +08:00
|
|
|
|
return angleInRadians * 180 / Math.PI;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static PointBase[] ConcatRouteAndSourceAndTarget(PointBase[] route, PointBase source, PointBase target)
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = new PointBase[route.Length + 2];
|
|
|
|
|
|
result[0] = source;
|
|
|
|
|
|
route.CopyTo(result, 1);
|
2023-01-12 23:02:53 +08:00
|
|
|
|
result[result.Length - 1] = target;
|
2023-01-08 09:22:37 +08:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2023-01-12 23:02:53 +08:00
|
|
|
|
|
2023-01-24 17:53:04 +08:00
|
|
|
|
private static void DoShift(PointBase[] points, ConnectionViewModel link)
|
2023-01-12 23:02:53 +08:00
|
|
|
|
{
|
|
|
|
|
|
double left = link.Area.Left;
|
|
|
|
|
|
double top = link.Area.Top;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < points.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
points[i].X = points[i].X - left;
|
|
|
|
|
|
points[i].Y = points[i].Y - top;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-01-08 09:22:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|