/// <summary> /// direction to push a bundle away from obstacle /// </summary> Point BuildForceForBundle(Station node) { var direction = new Point(); foreach (var adj in node.Neighbors) { double idealWidth = metroGraphData.GetWidth(node, adj, bundlingSettings.EdgeSeparation); List <Tuple <Point, Point> > closestPoints; bool res = metroGraphData.cdtIntersections.BundleAvoidsObstacles(node, adj, node.Position, adj.Position, idealWidth / 2, out closestPoints); if (!res) { #if DEBUG && TEST_MSAGL HubDebugger.ShowHubs(metroGraphData, bundlingSettings, new LineSegment(node.Position, adj.Position)); #endif } //Debug.Assert(res); //todo : still unsolved foreach (var d in closestPoints) { double dist = (d.Item1 - d.Item2).Length; Debug.Assert(ApproximateComparer.LessOrEqual(dist, idealWidth / 2)); double lforce = 2.0 * (1.0 - dist / (idealWidth / 2)); Point dir = -(d.Item1 - d.Item2).Normalize(); direction += dir * lforce; } } //derivative Point force = direction * bundlingSettings.BundleRepulsionImportance; return(force); }
static internal void ShowHubs(MetroGraphData mgd, BundlingSettings bundlingSettings, params ICurve[] iCurves ) { HubDebugger hd = new HubDebugger(mgd, bundlingSettings); if (iCurves != null) { var dc = hd.CreateDebugCurves(iCurves); LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(dc); } }
static internal void ShowHubs(MetroGraphData mgd, BundlingSettings bundlingSettings, Station highlightedNode) { HubDebugger hd = new HubDebugger(mgd, bundlingSettings); List <DebugCurve> debugCurves = hd.CreateDebugCurves(); debugCurves.Add(new DebugCurve(100, 1, "magenta", CurveFactory.CreateCircle(3, highlightedNode.Position))); debugCurves.Add(new DebugCurve(100, 0.1, "green", highlightedNode.BoundaryCurve)); LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(debugCurves); }
static internal void ShowHubs(MetroGraphData mgd, BundlingSettings bundlingSettings, Station highlightedNode) { HubDebugger hd = new HubDebugger(mgd, bundlingSettings); List<DebugCurve> debugCurves = hd.CreateDebugCurves(); debugCurves.Add(new DebugCurve(100,1, "magenta", CurveFactory.CreateCircle(3, highlightedNode.Position))); debugCurves.Add(new DebugCurve(100, 0.1, "green", highlightedNode.BoundaryCurve)); Console.WriteLine(highlightedNode.SerialNumber); LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(debugCurves); }
/// <summary> /// check the validness of the drawing: /// 1. hubs are not inside loose obstacles /// 2. bundles do not cross loose obstacles /// </summary> internal bool HubPositionsAreOK() { //check polylines foreach (var line in metroGraphData.Metrolines) { var poly = line.Polyline; foreach (var p in poly.PolylinePoints) { Debug.Assert(metroGraphData.PointToStations.ContainsKey(p.Point)); } } foreach (var station in metroGraphData.Stations) { if (!station.IsRealNode && !HubAvoidsObstacles(station.Position, 0, obstaclesToIgnore(station))) { if (LayoutAlgorithmSettings.ShowDebugCurvesEnumeration != null) { HubDebugger.ShowHubsWithHighligtedStation(metroGraphData, bundlingSettings, station); ShowStationWithObstaclesToIgnore(station, obstacleTree.AllHitItems(station.Position)); } return(false); } //bundles foreach (var adj in station.Neighbors) { if (ApproximateComparer.Close(adj.Position, station.Position)) { return(false); } if (!EdgeIsLegal(station, adj, station.Position, adj.Position)) { if (LayoutAlgorithmSettings.ShowDebugCurvesEnumeration != null) { //debug visualization var l = new List <DebugCurve>(); //foreach (var st in metroGraphData.Stations) { // l.Add(new DebugCurve(100, 0.5, "grey", st.BoundaryCurve)); //} foreach (var poly in obstaclesToIgnore(station)) { l.Add(new DebugCurve(100, 5, "green", poly)); } foreach (var obstacle in obstacleTree.GetAllLeaves()) { l.Add(new DebugCurve(100, 1, "red", obstacle)); } l.Add(new DebugCurve(1, "blue", station.BoundaryCurve)); l.Add(new DebugCurve(1, "blue", adj.BoundaryCurve)); l.Add(new DebugCurve(1, "blue", new LineSegment(adj.Position, adj.Neighbors.First().Position))); l.Add(new DebugCurve(1, "blue", new LineSegment(station.Position, adj.Position))); LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(l); //end debug visualization return(false); } } } } return(true); }