public class ManhattanRouter extends Object
Each segment has a "direction." This is specified as a constant from SwingUtilities, such as SwingUtilities.SOUTH, and indicates the direction of the segment when proceeding from the start to the end of the route.
Each segment in a route can be "pinned." This means that the position of the segment (perpendicular to its direction) will not be changed by any of the routing methods. Typically, if an interactor moves a segment, it will then pin it so that it appears to "stay put." The result is a reasonable compromise between automatic routing and manual control.
Modifier and Type | Class and Description |
---|---|
static class |
ManhattanRouter.Segment
Inner class representing a segment of the route.
|
static class |
ManhattanRouter.SegmentList
Inner class for a list of segments.
|
Constructor and Description |
---|
ManhattanRouter()
Create a new empty router.
|
Modifier and Type | Method and Description |
---|---|
void |
addSegment(int direction)
Add a new segment to the route.
|
Polyline2D |
createShape()
Create a Polyline2D that represents the shape of the current
route.
|
void |
deleteSegment(int segment)
Delete a segment.
|
Rectangle2D |
getRegion(int first,
int last)
Get the region covered by some number of segments.
|
ManhattanRouter.Segment |
getSegment(int segment)
Get the segment with the given index
|
int |
getSegmentCount()
Get the number of segments
|
Point2D |
getStart()
Get the starting point
|
static void |
main(String[] argv)
Test this thing...
|
void |
route(Point2D start,
int startDir,
Point2D end,
int endDir)
Create a route based on the given start and end points, and the direction
leaving and arriving at those points.
|
void |
setSegments(ManhattanRouter.SegmentList segments)
Set all segments of the route.
|
void |
splitSegment(int segment)
Split a segment.
|
String |
toString()
Print the route
|
void |
translateEnd(double dx,
double dy)
Reroute the end section of the route.
|
int |
translateSegment(int segment,
double x,
double y)
Translate a segment by the given distance.
|
void |
translateStart(double dx,
double dy)
Translate and reroute the start section of the
route.
|
public void addSegment(int direction)
public Polyline2D createShape()
public void deleteSegment(int segment)
public Rectangle2D getRegion(int first, int last)
public ManhattanRouter.Segment getSegment(int segment)
public int getSegmentCount()
public Point2D getStart()
public void translateEnd(double dx, double dy)
public void translateStart(double dx, double dy)
public void route(Point2D start, int startDir, Point2D end, int endDir)
public void setSegments(ManhattanRouter.SegmentList segments)
public void splitSegment(int segment)
public int translateSegment(int segment, double x, double y)
Often, an interactor that calls this method will also pin the segment so that further calls to translateStart() or translateEnd() do not overwrite the new segment location.
public static void main(String[] argv)
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.