Boundary画线算法,精度导致的问题修复

This commit is contained in:
艾竹
2023-04-16 14:56:53 +08:00
parent 4b8a03afb6
commit cbfbf96033
6 changed files with 40 additions and 8 deletions

View File

@@ -181,8 +181,8 @@ namespace AIStudio.Wpf.DiagramDesigner.Geometrys
/// <param name='point2'>The second PointBase to compare</param>
public static bool Equals(PointBase point1, PointBase point2)
{
return point1.X.Equals(point2.X) &&
point1.Y.Equals(point2.Y);
return Math.Abs(point1.X - point2.X) < 0.01f &&
Math.Abs(point1.Y - point2.Y) < 0.01f;
}
/// <summary>

View File

@@ -53,12 +53,12 @@ namespace AIStudio.Wpf.DiagramDesigner
var p0 = GetFirstSegment(source, sourceOrientation, gridCellSize, gridMargin);
var p1 = GetFirstSegment(sink, sinkOrientation, gridCellSize, gridMargin);
if (p0 == p1)
if (p0.Equals(p1))
return points;
var p2 = new PointBase(GetNearestCross(p0.X, p1.X, gridCellSize.Width, gridMargin.Width), GetNearestCross(p0.Y, p1.Y, gridCellSize.Height, gridMargin.Height));
var p3 = new PointBase(GetNearestCross(p1.X, p0.X, gridCellSize.Width, gridMargin.Width), GetNearestCross(p1.Y, p0.Y, gridCellSize.Height, gridMargin.Height));
if (p2 == p3)
if (p2.Equals(p3))
{
points.Add(p0);
points.Add(p2);
@@ -93,12 +93,12 @@ namespace AIStudio.Wpf.DiagramDesigner
public static double GetNearestCross(double a, double b, double cellSize, double margin)
{
if (Math.Abs(a - b) < 0.0001 && (int)((a - margin)/ cellSize) == ((a - margin) / cellSize))
if (Math.Abs(a - b) < 0.0001 && (int)(Math.Round((a - margin)/ cellSize, 3)) == (Math.Round((a - margin) / cellSize,3)))
return a;
else if (a < b)
return Math.Ceiling((a - margin) / cellSize) * cellSize + margin;
return Math.Ceiling(Math.Round((a - margin) / cellSize, 3)) * cellSize + margin;
else
return Math.Floor((a - margin) / cellSize) * cellSize + margin;
return Math.Floor(Math.Round((a - margin) / cellSize, 3)) * cellSize + margin;
}
public static PointBase SegmentMiddlePoint(PointBase p1, PointBase p2)

View File

@@ -192,6 +192,7 @@ namespace AIStudio.Wpf.DiagramDesigner
private double _itemWidth = 65;
[CanDo]
[Browsable(true)]
public double ItemWidth
{
get
@@ -210,6 +211,7 @@ namespace AIStudio.Wpf.DiagramDesigner
private double _itemHeight = 65;
[CanDo]
[Browsable(true)]
public double ItemHeight
{
get
@@ -361,6 +363,7 @@ namespace AIStudio.Wpf.DiagramDesigner
private double _left;
[CanDo]
[Browsable(true)]
public double Left
{
get
@@ -375,6 +378,7 @@ namespace AIStudio.Wpf.DiagramDesigner
private double _top;
[CanDo]
[Browsable(true)]
public double Top
{
get

View File

@@ -125,6 +125,7 @@ namespace AIStudio.Wpf.DiagramDesigner
this.IsGroup = designerbase.IsGroup;
this.ZIndex = designerbase.ZIndex;
this.Text = designerbase.Text;
this.Name = designerbase.Name;
ColorViewModel = CopyHelper.Mapper(designerbase.ColorItem);
FontViewModel = CopyHelper.Mapper<FontViewModel, FontItem>(designerbase.FontItem);