Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Bad Routes (Read 1395 times)
38Mikes
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 8
Joined: Dec 8th, 2015
Bad Routes
Jul 17th, 2017 at 7:52pm
Print Post  
I'm having the problem that the auto-router is creating long and circular routes between nodes that are right next to each other. I have two square shaped nodes right next to each other, when I add a link between them instead of going straight as I would expect it to, it does a full loop around the origination node back to the destination.  The problem goes away if I put some separation between the nodes... but I don't want any separation...
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Bad Routes
Reply #1 - Jul 18th, 2017 at 7:59am
Print Post  
The router places links in areas unoccupied by nodes by design. You can handle LinkRouted event to replace the automatic route with your own when you detect such adjacent nodes -

Code
Select All
private void OnLinkRouted(object sender, LinkEventArgs e)
{
	var l = e.Link;
	var o = l.Origin.Bounds;
	var d = l.Destination.Bounds;
	if (
		CommonRange(o.Left, o.Right, d.Left, d.Right) &&
		(o.Top == d.Bottom || o.Bottom == d.Top) ||

		CommonRange(o.Top, o.Bottom, d.Top, d.Bottom) &&
		(o.Left == d.Right || o.Right == d.Left))
	{
		l.Shape = LinkShape.Polyline;
		l.SegmentCount = 1;
	}
}

bool CommonRange(float a1, float a2, float b1, float b2)
{
	float amin = Math.Min(a1, a2);
	float amax = Math.Max(a1, a2);
	float bmin = Math.Min(b1, b2);
	float bmax = Math.Max(b1, b2);
	if (amin >= bmax)
		return false;
	if (bmin >= amax)
		return false;
	return true;
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint