Skip to content

Commit 71cbc38

Browse files
committed
add a test to SplineRouter
Signed-off-by: Lev Nachmanson <[email protected]>
1 parent 1b086ea commit 71cbc38

File tree

3 files changed

+100
-22
lines changed

3 files changed

+100
-22
lines changed

GraphLayout/MSAGL/Routing/Spline/ConeSpanner/LineSweeper.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ internal static PolylinePoint InsertPointIntoPolylineAfter(Polyline borderPolyli
280280
}
281281

282282
void ProcessEvent(SweepEvent p) {
283-
// if(debug && (p.Site-new Point(-313.122 ,-170.6)).Length<1)
284-
// Show( EllipseOnVert(p));
285283
var vertexEvent = p as VertexEvent;
284+
285+
286286
if (vertexEvent != null)
287287
ProcessVertexEvent(vertexEvent);
288288
else {
@@ -439,12 +439,7 @@ void CloseConesCoveredBySegment(Point leftPoint, Point rightPoint, RbTree<ConeSi
439439
}
440440

441441
void ProcessVertexEvent(VertexEvent vertexEvent) {
442-
// if (count == 872 && (vertexEvent.Site - new Point(-130.7368, -305.908)).Length < 1)
443-
// Show(EllipseOnVert(vertexEvent));
444-
445442
Z = GetZ(vertexEvent);
446-
//PrintOutLeftSegTree();
447-
//PrintOutRightSegTree();
448443
GoOverConesSeeingVertexEvent(vertexEvent);
449444
AddConeAndEnqueueEvents(vertexEvent);
450445
}
@@ -1058,11 +1053,10 @@ void GoOverConesSeeingVertexEvent(SweepEvent vertexEvent) {
10581053

10591054
if (rbNode == null) {//it is an emergency measure and should not happen
10601055
rbNode = GetRbNodeEmergency(rbNode, leftConeSide);
1056+
if (rbNode == null)
1057+
return; // the cone is not there! and it is a bug
10611058
}
10621059

1063-
if (rbNode == null)
1064-
return; // the cone is not there! and it is a bug
1065-
10661060
rbNode = leftConeSides.Next(rbNode);
10671061
while (rbNode != null && !VertexIsToTheLeftOfSegment(vertexEvent, rbNode.Item)) {
10681062
visibleCones.Add(rbNode.Item.Cone);

GraphLayout/MSAGL/Routing/SplineRouter.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -935,18 +935,18 @@ void FillVisibilityGraphUnderShape(Shape shape) {
935935

936936
#if TEST_MSAGL
937937
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
938-
static internal void ShowVisGraph(VisibilityGraph tmpVisGraph, IEnumerable<Polyline> obstacles, IEnumerable<ICurve> greenCurves, IEnumerable<ICurve> redCurves) {
939-
var l = new List<DebugCurve>(tmpVisGraph.Edges.Select(e => new DebugCurve(100, 1,
940-
e.IsPassable != null && e.IsPassable() ? "green" : "black"
941-
, new LineSegment(e.SourcePoint, e.TargetPoint))));
942-
if (obstacles != null)
943-
l.AddRange(obstacles.Select(p => new DebugCurve(100, 1, "brown", p)));
944-
if (greenCurves != null)
945-
l.AddRange(greenCurves.Select(p => new DebugCurve(100, 10, "navy", p)));
946-
if (redCurves != null)
947-
l.AddRange(redCurves.Select(p => new DebugCurve(100, 10, "red", p)));
948-
LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(l);
949-
}
938+
static internal void ShowVisGraph(VisibilityGraph tmpVisGraph, IEnumerable<Polyline> obstacles, IEnumerable<ICurve> greenCurves = null, IEnumerable<ICurve> redCurves = null) {
939+
var l = new List<DebugCurve>(tmpVisGraph.Edges.Select(e => new DebugCurve(100, 1,
940+
e.IsPassable != null && e.IsPassable() ? "green" : "black"
941+
, new LineSegment(e.SourcePoint, e.TargetPoint))));
942+
if (obstacles != null)
943+
l.AddRange(obstacles.Select(p => new DebugCurve(100, 1, "brown", p)));
944+
if (greenCurves != null)
945+
l.AddRange(greenCurves.Select(p => new DebugCurve(100, 10, "navy", p)));
946+
if (redCurves != null)
947+
l.AddRange(redCurves.Select(p => new DebugCurve(100, 10, "red", p)));
948+
LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(l);
949+
}
950950
#endif
951951
void TryToCreateNewEdgeAndSetIsPassable(VisibilityEdge edge, Shape looseShape) {
952952
var e = visGraph.FindEdge(edge.SourcePoint, edge.TargetPoint);

GraphLayout/Test/MSAGLTests/SplineRouterTests.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,90 @@ static Node SetNode(
203203
return geomNode;
204204
}
205205

206+
[TestMethod]
207+
public void OneEdgeWithObstacle() {
208+
GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions();
209+
var g = new GeometryGraph();
210+
var a = new Node {
211+
BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(
212+
20,
213+
20,
214+
3,
215+
3,
216+
new Point(0, 0))
217+
};
218+
g.Nodes.Add(a);
219+
var b = new Node {
220+
BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(
221+
20,
222+
20,
223+
3,
224+
3,
225+
new Point(0, 200))
226+
};
227+
g.Nodes.Add(b);
228+
var c = new Node {
229+
BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(
230+
20,
231+
20,
232+
3,
233+
3,
234+
new Point(0, 300))
235+
};
236+
g.Nodes.Add(c);
237+
var e = new Edge(a, c);
238+
g.Edges.Add(e);
239+
var sr = new SplineRouter(g, 2, 4, Math.PI / 6);
240+
sr.Run();
241+
// GraphViewerGdi.DisplayGeometryGraph.ShowGraph(g);
242+
}
243+
[TestMethod]
244+
public void OneEdgeWithTwoObstacles() {
245+
GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions();
246+
var g = new GeometryGraph();
247+
var a = new Node {
248+
BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(
249+
20,
250+
20,
251+
3,
252+
3,
253+
new Point(0, 0))
254+
};
255+
g.Nodes.Add(a);
256+
var b = new Node {
257+
BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(
258+
40,
259+
20,
260+
3,
261+
3,
262+
new Point(-10, 200))
263+
};
264+
g.Nodes.Add(b);
265+
var c = new Node {
266+
BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(
267+
60,
268+
20,
269+
3,
270+
3,
271+
new Point(35, 170))
272+
};
273+
g.Nodes.Add(c);
274+
var d = new Node {
275+
BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(
276+
20,
277+
20,
278+
3,
279+
3,
280+
new Point(0, 270))
281+
};
282+
g.Nodes.Add(d);
283+
var e = new Edge(a, d);
284+
g.Edges.Add(e);
285+
var sr = new SplineRouter(g, 2, 4, Math.PI / 6);
286+
sr.Run();
287+
GraphViewerGdi.DisplayGeometryGraph.ShowGraph(g);
288+
}
289+
206290
[TestMethod]
207291
public void SelfEdge() {
208292
var g = new GeometryGraph();

0 commit comments

Comments
 (0)