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

@@ -102,6 +102,26 @@ namespace AIStudio.Wpf.Flowchart
ConnectionViewModel connector10 = new ConnectionViewModel(coend.BottomConnector, end.TopConnector, _service.DrawModeViewModel.LineDrawMode, _service.DrawModeViewModel.LineRouterMode); ConnectionViewModel connector10 = new ConnectionViewModel(coend.BottomConnector, end.TopConnector, _service.DrawModeViewModel.LineDrawMode, _service.DrawModeViewModel.LineRouterMode);
DiagramViewModel.Add(connector10); DiagramViewModel.Add(connector10);
TextDesignerItemViewModel despcription = new TextDesignerItemViewModel()
{
Name = nameof(despcription),
Left = 260,
Top = 60,
ItemWidth = 300,
ItemHeight = 150,
Text = @"
一个简易的OA审批流程
1.主管审批为or审批任意一个审批即可
2.分管领导为and审批需要审批两次
3.财务审批为or审批任意一个审批即可
4.人力审批为or审批任意一个审批即可
注意:为了模拟审批,双击节点可以进行审批;请双击主管审批、分管领导、财务审批、人力审批、进行效果查看。"
};
despcription.FontViewModel.HorizontalAlignment = HorizontalAlignment.Left;
despcription.FontViewModel.VerticalAlignment = VerticalAlignment.Top;
despcription.FontViewModel.FontColor = Colors.Blue;
DiagramViewModel.Add(despcription);
FlowchartService.InitData(DiagramViewModel.Items.OfType<FlowNode>().ToList(), DiagramViewModel.Items.OfType<ConnectionViewModel>().ToList(), DiagramViewModel, true); FlowchartService.InitData(DiagramViewModel.Items.OfType<FlowNode>().ToList(), DiagramViewModel.Items.OfType<ConnectionViewModel>().ToList(), DiagramViewModel, true);
} }

View File

@@ -59,7 +59,14 @@ namespace AIStudio.Wpf.Flowchart
{ {
get get
{ {
return SubType.ToEnum<MindType>(); if (SubType == null)
{
return MindType.Mind;
}
else
{
return SubType.ToEnum<MindType>();
}
} }
} }

View File

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

View File

@@ -53,12 +53,12 @@ namespace AIStudio.Wpf.DiagramDesigner
var p0 = GetFirstSegment(source, sourceOrientation, gridCellSize, gridMargin); var p0 = GetFirstSegment(source, sourceOrientation, gridCellSize, gridMargin);
var p1 = GetFirstSegment(sink, sinkOrientation, gridCellSize, gridMargin); var p1 = GetFirstSegment(sink, sinkOrientation, gridCellSize, gridMargin);
if (p0 == p1) if (p0.Equals(p1))
return points; 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 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)); 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(p0);
points.Add(p2); points.Add(p2);
@@ -93,12 +93,12 @@ namespace AIStudio.Wpf.DiagramDesigner
public static double GetNearestCross(double a, double b, double cellSize, double margin) 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; return a;
else if (a < b) else if (a < b)
return Math.Ceiling((a - margin) / cellSize) * cellSize + margin; return Math.Ceiling(Math.Round((a - margin) / cellSize, 3)) * cellSize + margin;
else 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) public static PointBase SegmentMiddlePoint(PointBase p1, PointBase p2)

View File

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

View File

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