private static Point?EscapeProcessI(CoverSet coverSet, Point Z, ConnectorSegment escapeLine, Orientation orientation, Size margin) { List <DistanceFromPoint> extremitiesList = new List <DistanceFromPoint>(4); ConnectorSegment cover = coverSet.GetCover(Z, (orientation == Orientation.Horizontal) ? DesignerEdges.Left : DesignerEdges.Bottom); if (cover != null) { AddBoundPoint(ref extremitiesList, cover.A, cover, Z); AddBoundPoint(ref extremitiesList, cover.B, cover, Z); } ConnectorSegment segment = coverSet.GetCover(Z, (orientation == Orientation.Horizontal) ? DesignerEdges.Right : DesignerEdges.Top); if (segment != null) { AddBoundPoint(ref extremitiesList, segment.A, segment, Z); AddBoundPoint(ref extremitiesList, segment.B, segment, Z); } if (extremitiesList.Count != 0) { DistanceSorter.Sort(ref extremitiesList); for (int i = 0; i < extremitiesList.Count; i++) { DesignerEdges edges; Point point3; Point p = extremitiesList[i].P; int x = Math.Sign((int)(p.X - Z.X)); Point point2 = new Point(x, Math.Sign((int)(p.Y - Z.Y))); if (((orientation == Orientation.Vertical) ? point2.X : point2.Y) == 0) { p = extremitiesList[i].ConnectorSegment.ExtendPointOutwards(p); int introduced13 = Math.Sign((int)(p.X - Z.X)); point2 = new Point(introduced13, Math.Sign((int)(p.Y - Z.Y))); p = extremitiesList[i].P; } if (orientation == Orientation.Vertical) { edges = (point2.Y < 0) ? DesignerEdges.Bottom : DesignerEdges.Top; } else { edges = (point2.X < 0) ? DesignerEdges.Left : DesignerEdges.Right; } if (orientation == Orientation.Vertical) { point3 = new Point(p.X + (point2.X * margin.Width), Z.Y); } else { point3 = new Point(Z.X, p.Y + (point2.Y * margin.Height)); } ConnectorSegment segment4 = new ConnectorSegment(Z, point3); if (((!coverSet.EscapeLineHasBeenUsed(segment4, point3) && escapeLine.IsPointOnSegment(point3)) && ((escapeLine.A != point3) && (escapeLine.B != point3))) && coverSet.IsEscapePoint(Z, point3, edges)) { coverSet.AddUsedEscapeLine(segment4); return(new Point?(point3)); } } } return(null); }
private static void SecondRefinementAlgorithm(CoverSet coverSet, ref List <Point> refinedPath, Size margin) { int num; List <Point> list = new List <Point>(); for (num = 0; num < (refinedPath.Count - 1); num++) { Point a = refinedPath[num]; Point b = refinedPath[num + 1]; ConnectorSegment segment = ConnectorSegment.ConstructBoundSegment(coverSet, a, b); int num2 = num + 2; while (num2 < (refinedPath.Count - 1)) { Point point3 = refinedPath[num2]; Point point4 = refinedPath[num2 + 1]; ConnectorSegment segment2 = ConnectorSegment.ConstructBoundSegment(coverSet, point3, point4); Point? nullable = segment.Intersect(segment2); if (nullable.HasValue) { list.Clear(); for (int i = 0; i <= num; i++) { list.Add(refinedPath[i]); } list.Add(nullable.Value); for (int j = num2 + 1; j < refinedPath.Count; j++) { list.Add(refinedPath[j]); } List <Point> list2 = refinedPath; refinedPath = list; list = list2; list.Clear(); num2 = num + 2; } else { num2++; } } } num = 0; while (num < (refinedPath.Count - 1)) { Point point5 = refinedPath[num]; Point point6 = refinedPath[num + 1]; bool flag = false; ConnectorSegment segment3 = ConnectorSegment.ConstructBoundSegment(coverSet, point5, point6); if (segment3 != null) { Point point7 = new Point(point6.X - point5.X, point6.Y - point5.Y); int introduced30 = Math.Abs((int)(point7.X / margin.Width)); int num5 = Math.Max(introduced30, Math.Abs((int)(point7.Y / margin.Height))); point7.X = Math.Sign(point7.X); point7.Y = Math.Sign(point7.Y); for (int k = 1; k <= num5; k++) { Point point8 = new Point(point5.X + ((k * margin.Width) * point7.X), point5.Y + ((k * margin.Height) * point7.Y)); if (point8 == point6) { break; } ConnectorSegment segment4 = ConnectorSegment.ConstructBoundSegment(coverSet, point8, (segment3.Orientation == Orientation.Horizontal) ? Orientation.Vertical : Orientation.Horizontal); for (int m = num + 2; (m < (refinedPath.Count - 1)) && !flag; m++) { Point point9 = refinedPath[m]; Point point10 = refinedPath[m + 1]; ConnectorSegment segment5 = new ConnectorSegment(point9, point10); Point? nullable2 = segment4.Intersect(segment5); if (nullable2.HasValue && segment5.IsPointOnSegment(nullable2.Value)) { flag = true; list.Clear(); for (int n = 0; n <= num; n++) { list.Add(refinedPath[n]); } list.Add(point8); list.Add(nullable2.Value); for (int num9 = m + 1; num9 < refinedPath.Count; num9++) { list.Add(refinedPath[num9]); } List <Point> list3 = refinedPath; refinedPath = list; list3.Clear(); break; } } if (flag) { break; } } } if (!flag) { num++; } } }
private static Point[] GetRoutedLineSegments(Point begin, Point end, Size margin, Rectangle[] rectanglesToExclude, Point[] linesToExclude) { if (rectanglesToExclude == null) { throw new ArgumentNullException("rectanglesToExclude"); } if (linesToExclude == null) { throw new ArgumentNullException("linesToExclude"); } if ((linesToExclude.Length % 2) > 0) { throw new ArgumentException(DR.GetString("Error_Connector2", new object[0])); } CoverSet coverSet = new CoverSet(rectanglesToExclude, linesToExclude); coverSet.ClearUsedLines(); Point point = begin; Point point2 = end; List <Point> leA = new List <Point>(); List <Point> le = new List <Point>(); List <ConnectorSegment> lhA = new List <ConnectorSegment>(); List <ConnectorSegment> lvA = new List <ConnectorSegment>(); List <ConnectorSegment> lhB = new List <ConnectorSegment>(); List <ConnectorSegment> lvB = new List <ConnectorSegment>(); Orientation horizontal = Orientation.Horizontal; Orientation orientation2 = Orientation.Horizontal; leA.Add(begin); le.Add(end); bool noEscapeA = false; bool flag2 = false; Point? nullable = null; ConnectorSegment intersectionSegmentA = null; ConnectorSegment intersectionSegmentB = null; try { Label_00A1: while (noEscapeA) { if (flag2) { goto Label_0172; } List <Point> list7 = leA; leA = le; le = list7; Point point3 = point; point = point2; point2 = point3; bool flag3 = noEscapeA; noEscapeA = flag2; flag2 = flag3; Orientation orientation3 = horizontal; horizontal = orientation2; orientation2 = orientation3; List <ConnectorSegment> list8 = lhA; lhA = lhB; lhB = list8; list8 = lvA; lvA = lvB; lvB = list8; } Point z = leA[leA.Count - 1]; Point targetPoint = point2; nullable = EscapeAlgorithm(coverSet, z, targetPoint, ref leA, ref lhA, ref lvA, ref lhB, ref lvB, ref horizontal, out intersectionSegmentA, out intersectionSegmentB, margin, ref noEscapeA); if (!nullable.HasValue) { List <Point> list9 = leA; leA = le; le = list9; Point point6 = point; point = point2; point2 = point6; bool flag4 = noEscapeA; noEscapeA = flag2; flag2 = flag4; Orientation orientation4 = horizontal; horizontal = orientation2; orientation2 = orientation4; List <ConnectorSegment> list10 = lhA; lhA = lhB; lhB = list10; list10 = lvA; lvA = lvB; lvB = list10; goto Label_00A1; } Label_0172: if (!nullable.HasValue) { return(null); } List <Point> refinedPath = new List <Point>(); leA = FirstRefinementAlgorithm(leA, nullable.Value, intersectionSegmentA); le = FirstRefinementAlgorithm(le, nullable.Value, intersectionSegmentB); for (int i = leA.Count - 1; i >= 0; i--) { refinedPath.Add(leA[i]); } refinedPath.Add(nullable.Value); for (int j = 0; j < le.Count; j++) { refinedPath.Add(le[j]); } SecondRefinementAlgorithm(coverSet, ref refinedPath, margin); if ((refinedPath.Count > 1) && (refinedPath[refinedPath.Count - 1] == begin)) { refinedPath.Reverse(); } return(refinedPath.ToArray()); } catch { return(null); } }
private static Point?EscapeProcessII(CoverSet coverSet, Orientation orientation, ref List <Point> LeA, ref List <ConnectorSegment> LhA, ref List <ConnectorSegment> LvA, ref List <ConnectorSegment> LhB, ref List <ConnectorSegment> LvB, Point Z, Point R, Size margin, out bool intersectionFlag, out ConnectorSegment intersectionSegmentA, out ConnectorSegment intersectionSegmentB) { intersectionFlag = false; intersectionSegmentA = null; intersectionSegmentB = null; ConnectorSegment escapeLine = ConnectorSegment.SegmentFromLeftToRightCover(coverSet, R); ConnectorSegment segment2 = ConnectorSegment.SegmentFromBottomToTopCover(coverSet, R); for (int i = 0; i < LvB.Count; i++) { ConnectorSegment segment = LvB[i]; Point? nullable = escapeLine.Intersect(segment); if (nullable.HasValue) { intersectionFlag = true; intersectionSegmentA = escapeLine; intersectionSegmentB = segment; LeA.Add(R); return(nullable); } } for (int j = 0; j < LhB.Count; j++) { ConnectorSegment segment4 = LhB[j]; Point? nullable2 = segment2.Intersect(segment4); if (nullable2.HasValue) { intersectionFlag = true; intersectionSegmentA = segment2; intersectionSegmentB = segment4; LeA.Add(R); return(nullable2); } } Point?nullable3 = null; if (orientation == Orientation.Horizontal) { nullable3 = EscapeProcessI(coverSet, R, segment2, Orientation.Horizontal, margin); if (nullable3.HasValue) { LvA.Add(segment2); LeA.Add(R); return(nullable3); } nullable3 = EscapeProcessI(coverSet, R, escapeLine, Orientation.Vertical, margin); if (nullable3.HasValue) { LhA.Add(escapeLine); LeA.Add(R); return(nullable3); } } else { nullable3 = EscapeProcessI(coverSet, R, escapeLine, Orientation.Vertical, margin); if (nullable3.HasValue) { LhA.Add(escapeLine); LeA.Add(R); return(nullable3); } nullable3 = EscapeProcessI(coverSet, R, segment2, Orientation.Horizontal, margin); if (nullable3.HasValue) { LvA.Add(segment2); LeA.Add(R); return(nullable3); } } return(null); }
private static Point?EscapeAlgorithm(CoverSet coverSet, Point Z, Point targetPoint, ref List <Point> LeA, ref List <ConnectorSegment> LhA, ref List <ConnectorSegment> LvA, ref List <ConnectorSegment> LhB, ref List <ConnectorSegment> LvB, ref Orientation orientationA, out ConnectorSegment intersectionSegmentA, out ConnectorSegment intersectionSegmentB, Size margin, ref bool noEscapeA) { bool flag2; bool flag3; bool flag4; bool flag5; Point?nullable = null; intersectionSegmentA = null; intersectionSegmentB = null; ConnectorSegment cover = coverSet.GetCover(Z, DesignerEdges.Left); ConnectorSegment segment2 = coverSet.GetCover(Z, DesignerEdges.Right); ConnectorSegment segment3 = coverSet.GetCover(Z, DesignerEdges.Bottom); ConnectorSegment segment4 = coverSet.GetCover(Z, DesignerEdges.Top); ConnectorSegment item = ConnectorSegment.SegmentFromLeftToRightCover(coverSet, Z); LhA.Add(item); ConnectorSegment segment6 = ConnectorSegment.SegmentFromBottomToTopCover(coverSet, Z); LvA.Add(segment6); for (int i = 0; i < LvB.Count; i++) { ConnectorSegment segment = LvB[i]; nullable = item.Intersect(segment); if (nullable.HasValue) { intersectionSegmentA = item; intersectionSegmentB = segment; return(nullable); } } for (int j = 0; j < LhB.Count; j++) { ConnectorSegment segment8 = LhB[j]; nullable = segment6.Intersect(segment8); if (nullable.HasValue) { intersectionSegmentA = segment6; intersectionSegmentB = segment8; return(nullable); } } Point?nullable2 = EscapeProcessI(coverSet, Z, segment6, Orientation.Horizontal, margin); if (nullable2.HasValue) { orientationA = Orientation.Vertical; LeA.Add(nullable2.Value); return(null); } nullable2 = EscapeProcessI(coverSet, Z, item, Orientation.Vertical, margin); if (nullable2.HasValue) { orientationA = Orientation.Horizontal; LeA.Add(nullable2.Value); return(null); } bool intersectionFlag = false; Point empty = Point.Empty; Point r = Point.Empty; Point point3 = Point.Empty; Point point4 = Point.Empty; if (segment4 != null) { empty = new Point(Z.X, segment4.A.Y); } if (segment2 != null) { r = new Point(segment2.A.X, Z.Y); } if (segment3 != null) { point3 = new Point(Z.X, segment3.A.Y); } if (cover != null) { point4 = new Point(cover.A.X, Z.Y); } do { flag2 = flag3 = flag4 = flag5 = false; if (segment4 != null) { empty.Y -= margin.Height; if (empty.Y > Z.Y) { flag2 = true; Point?nullable3 = EscapeProcessII(coverSet, Orientation.Vertical, ref LeA, ref LhA, ref LvA, ref LhB, ref LvB, Z, empty, margin, out intersectionFlag, out intersectionSegmentA, out intersectionSegmentB); if (nullable3.HasValue) { LvA.Add(segment6); if (intersectionFlag) { return(nullable3); } orientationA = Orientation.Horizontal; coverSet.AddUsedEscapeLine(new ConnectorSegment(Z, empty)); coverSet.AddUsedEscapeLine(new ConnectorSegment(empty, nullable3.Value)); LeA.Add(nullable3.Value); return(null); } } } if (segment2 != null) { r.X -= margin.Width; if (r.X > Z.X) { flag3 = true; Point?nullable4 = EscapeProcessII(coverSet, Orientation.Horizontal, ref LeA, ref LhA, ref LvA, ref LhB, ref LvB, Z, r, margin, out intersectionFlag, out intersectionSegmentA, out intersectionSegmentB); if (nullable4.HasValue) { LhA.Add(item); if (intersectionFlag) { return(nullable4); } orientationA = Orientation.Vertical; coverSet.AddUsedEscapeLine(new ConnectorSegment(Z, r)); coverSet.AddUsedEscapeLine(new ConnectorSegment(r, nullable4.Value)); LeA.Add(nullable4.Value); return(null); } } } if (segment3 != null) { point3.Y += margin.Height; if (point3.Y < Z.Y) { flag4 = true; Point?nullable5 = EscapeProcessII(coverSet, Orientation.Vertical, ref LeA, ref LhA, ref LvA, ref LhB, ref LvB, Z, point3, margin, out intersectionFlag, out intersectionSegmentA, out intersectionSegmentB); if (nullable5.HasValue) { LvA.Add(segment6); if (intersectionFlag) { return(nullable5); } orientationA = Orientation.Horizontal; coverSet.AddUsedEscapeLine(new ConnectorSegment(Z, point3)); coverSet.AddUsedEscapeLine(new ConnectorSegment(point3, nullable5.Value)); LeA.Add(nullable5.Value); return(null); } } } if (cover != null) { point4.X += margin.Width; if (point4.X < Z.X) { flag5 = true; Point?nullable6 = EscapeProcessII(coverSet, Orientation.Horizontal, ref LeA, ref LhA, ref LvA, ref LhB, ref LvB, Z, point4, margin, out intersectionFlag, out intersectionSegmentA, out intersectionSegmentB); if (nullable6.HasValue) { LhA.Add(item); if (intersectionFlag) { return(nullable6); } orientationA = Orientation.Vertical; coverSet.AddUsedEscapeLine(new ConnectorSegment(Z, point4)); coverSet.AddUsedEscapeLine(new ConnectorSegment(point4, nullable6.Value)); LeA.Add(nullable6.Value); return(null); } } } }while ((flag2 || flag3) || (flag4 || flag5)); noEscapeA = true; return(null); }