Package org.eclipse.draw2d.graph
Class ShortestPathRouter
java.lang.Object
org.eclipse.draw2d.graph.ShortestPathRouter
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
addObstacle
(Rectangle rect) Adds an obstacle with the given bounds to the obstacles.void
Adds a path to the routing.int
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.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.
-
Constructor Details
-
ShortestPathRouter
public ShortestPathRouter()Creates a new shortest path routing.
-
-
Method Details
-
addObstacle
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
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:
-
removeObstacle
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
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
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
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
-