Eclipse Draw2d
3.3

org.eclipse.draw2d.graph
Class ShortestPathRouter

java.lang.Object
  extended by org.eclipse.draw2d.graph.ShortestPathRouter

public class ShortestPathRouter
extends Object

Bends a collection of Paths around rectangular obstacles. This class maintains a list of paths and obstacles. Updates can be made to the paths and/or obstacles, and then an incremental solve can be invoked.

The algorithm will attempt to find the shortest non-intersecting path between each path's start and end points. Once all paths have been found, they will be offset based on how many paths bend around the same corner of each obstacle.

The worst-case performance of this algorithm is p * s * n^2, where p is the number of paths, n is the number of obstacles, and s is the average number of segments in each path's final solution.

This class is not intended to be subclassed.

Since:
3.0

Constructor Summary
ShortestPathRouter()
          Creates a new shortest path routing.
 
Method Summary
 boolean addObstacle(Rectangle rect)
          Adds an obstacle with the given bounds to the obstacles.
 void addPath(Path path)
          Adds a path to the routing.
 int getSpacing()
          Returns the spacing maintained between paths.
 boolean removeObstacle(Rectangle rect)
          Removes the obstacle with the rectangle's bounds from the routing.
 boolean removePath(Path path)
          Removes the given path from the routing.
 void setSpacing(int spacing)
          Sets the default spacing between paths.
 List solve()
          Updates the points in the paths in order to represent the current solution with the given paths and obstacles.
 boolean updateObstacle(Rectangle oldBounds, Rectangle newBounds)
          Updates the position of an existing obstacle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShortestPathRouter

public ShortestPathRouter()
Creates a new shortest path routing.

Method Detail

addObstacle

public boolean addObstacle(Rectangle rect)
Adds an obstacle with the given bounds to the obstacles.

Parameters:
rect - the bounds of this obstacle
Returns:
true if the added obstacle has dirtied one or more paths

addPath

public void addPath(Path path)
Adds a path to the routing.

Parameters:
path - the path to add.

getSpacing

public int getSpacing()
Returns the spacing maintained between paths.

Returns:
the default path spacing
Since:
3.2
See Also:
setSpacing(int)

removeObstacle

public boolean removeObstacle(Rectangle rect)
Removes the obstacle with the rectangle's bounds from the routing.

Parameters:
rect - the bounds of the obstacle to remove
Returns:
true if the removal has dirtied one or more paths

removePath

public boolean removePath(Path path)
Removes the given path from the routing.

Parameters:
path - the path to remove.
Returns:
true if the removal may have affected one of the remaining paths

setSpacing

public void setSpacing(int spacing)
Sets the default spacing between paths. The spacing is the minimum distance that path should be offset from other paths or obstacles. The default value is 4. When this value can not be satisfied, paths will be squeezed together uniformly.

Parameters:
spacing - the path spacing
Since:
3.2

solve

public List solve()
Updates the points in the paths in order to represent the current solution with the given paths and obstacles.

Returns:
returns the list of paths which were updated.

updateObstacle

public boolean updateObstacle(Rectangle oldBounds,
                              Rectangle newBounds)
Updates the position of an existing obstacle.

Parameters:
oldBounds - the old bounds(used to find the obstacle)
newBounds - the new bounds
Returns:
true if the change the current results to become stale

Eclipse Draw2d
3.3

Copyright (c) IBM Corp. and others 2000, 2007. All Rights Reserved.