void CreatePortObstacles(Node node, Port port, out LineSegment filterLine) { var bp = port as CurvePort; if (bp != null) { var padding = router.Padding; var closedCurve = node.BoundaryCurve; Curve paddingCurve = GetPaddedPolyline(closedCurve, padding).ToCurve(); Point portPoint = node.BoundaryCurve[bp.Parameter]; double length = node.BoundaryCurve.BoundingBox.Width + node.BoundaryCurve.BoundingBox.Height; double leftTipPar = GetLeftTipParam(bp.Parameter, portPoint, paddingCurve, node, length); double rightTipPar = GetRightTipParam(bp.Parameter, portPoint, paddingCurve, node, length); paddingCurve = TrimCurve(paddingCurve, rightTipPar, leftTipPar); //a simplifying hack here. I know that the parameter start from 0 and advances by 1 on every segment int n = paddingCurve.Segments.Count / 2; Debug.Assert(n > 0); Curve rightChunk = TrimCurve(paddingCurve, 0, n); Curve leftChunk = TrimCurve(paddingCurve, n + 0.8, paddingCurve.ParEnd); filterLine = new LineSegment(0.5 * (leftChunk.Start + leftChunk.End), 0.5 * (rightChunk.Start + rightChunk.End)); Polyline pol = Polyline.PolylineFromCurve(leftChunk); pol.Closed = true; portObstacles.Insert(pol); TightObstacles.Insert(pol); pol = Polyline.PolylineFromCurve(rightChunk); pol.Closed = true; portObstacles.Insert(pol); TightObstacles.Insert(pol); /* * Polyline padded = CreatePaddedCurve(Anchor.PolylineAroundClosedCurve(node.BoundaryCurve), this.router.MinimalPadding); * * * * * PolylinePoint polyRightBottomPoint = FindPolyPointToCutAt(node, bp.Parameter, padded); * PolylinePoint nextToRightTopTip; * Point rightTopTip = GetRightTopTip(node, bp.Parameter, padded, out nextToRightTopTip); * * PolylinePoint prevToLeftTopTip; * Point leftTopTip = GetLeftTopTip(node, bp.Parameter, padded, out prevToLeftTopTip); * double al = 0.25; * Point rightLow = (1 - al) * polyRightBottomPoint.Point + al * polyRightBottomPoint.NextOnPolyline.Point; * Point leftLow = al * polyRightBottomPoint.Point + (1 - al) * polyRightBottomPoint.NextOnPolyline.Point; * filterLine = new LineSegment(0.5 * (rightTopTip + rightLow), 0.5 * (leftTopTip + leftLow)); * AddRightObstacle(rightTopTip, nextToRightTopTip, polyRightBottomPoint, rightLow); * AddLeftObstacle(leftLow, polyRightBottomPoint.NextOnPolyline, prevToLeftTopTip, leftTopTip); */ } else { filterLine = null; portObstacles.Insert(node.BoundaryCurve); } }
/// <summary> /// /// </summary> void CreateInitialTightObstacles() { tightObstacles = new Set <Polyline>(); foreach (Node node in router.Graph.Nodes) { if (node == router.Source) { CreatePortObstacles(router.Source, router.SourcePort, out sourceFilterLine); } else if (node == router.Target) { CreatePortObstacles(router.Target, router.TargetPort, out targetFilterLine); } else { TightObstacles.Insert(PaddedPolylineBoundaryOfNode(node, router.Padding)); } } }
void CreatePortObstacles(Node node, Port port, out LineSegment filterLine) { var bp = port as CurvePort; if (bp != null) { var padding = router.Padding; var closedCurve = node.BoundaryCurve; Curve paddingCurve = GetPaddedPolyline(closedCurve, padding).ToCurve(); Point portPoint = node.BoundaryCurve[bp.Parameter]; double length = node.BoundaryCurve.BoundingBox.Width + node.BoundaryCurve.BoundingBox.Height; double leftTipPar = GetLeftTipParam(bp.Parameter, portPoint, paddingCurve, node, length); double rightTipPar = GetRightTipParam(bp.Parameter, portPoint, paddingCurve, node, length); paddingCurve = TrimCurve(paddingCurve, rightTipPar, leftTipPar); //a simplifying hack here. I know that the parameter start from 0 and advances by 1 on every segment int n = paddingCurve.Segments.Count / 2; Debug.Assert(n > 0); Curve rightChunk = TrimCurve(paddingCurve, 0, n); Curve leftChunk = TrimCurve(paddingCurve, n + 0.8, paddingCurve.ParEnd); filterLine = new LineSegment(0.5 * (leftChunk.Start + leftChunk.End), 0.5 * (rightChunk.Start + rightChunk.End)); Polyline pol = Polyline.PolylineFromCurve(leftChunk); pol.Closed = true; portObstacles.Insert(pol); TightObstacles.Insert(pol); pol = Polyline.PolylineFromCurve(rightChunk); pol.Closed = true; portObstacles.Insert(pol); TightObstacles.Insert(pol); } else { filterLine = null; portObstacles.Insert(node.BoundaryCurve); } }