Add origin node to arc.
This commit is contained in:
parent
11b07b652b
commit
a6e8a22081
3 changed files with 20 additions and 11 deletions
|
@ -5,7 +5,7 @@ import java.util.ArrayList;
|
|||
public class Arc {
|
||||
|
||||
// Destination node.
|
||||
private Node dest;
|
||||
private Node origin, destination;
|
||||
|
||||
// Length of the road (in meters).
|
||||
private int length;
|
||||
|
@ -22,11 +22,13 @@ public class Arc {
|
|||
* @param roadInformation
|
||||
* @param points
|
||||
*/
|
||||
public Arc(Node dest, int length, RoadInformation roadInformation) {
|
||||
this.dest = dest;
|
||||
public Arc(Node origin, Node dest, int length, RoadInformation roadInformation) {
|
||||
this.origin = origin;
|
||||
this.destination = dest;
|
||||
this.length = length;
|
||||
this.info = roadInformation;
|
||||
this.points = new ArrayList<Point>();
|
||||
origin.addSuccessor(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,18 +37,27 @@ public class Arc {
|
|||
* @param roadInformation
|
||||
* @param points
|
||||
*/
|
||||
public Arc(Node dest, int length, RoadInformation roadInformation, ArrayList<Point> points) {
|
||||
this.dest = dest;
|
||||
public Arc(Node origin, Node dest, int length, RoadInformation roadInformation, ArrayList<Point> points) {
|
||||
this.origin = origin;
|
||||
this.destination = dest;
|
||||
this.length = length;
|
||||
this.info = roadInformation;
|
||||
this.points = points;
|
||||
origin.addSuccessor(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Origin node of this arc.
|
||||
*/
|
||||
public Node getOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Destination node of this arc.
|
||||
*/
|
||||
public Node getDestination() {
|
||||
return dest;
|
||||
return destination;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,7 @@ public class Node implements Comparable<Node> {
|
|||
*
|
||||
* @param arc Arc to the successor.
|
||||
*/
|
||||
public void addSuccessor(Arc arc) {
|
||||
protected void addSuccessor(Arc arc) {
|
||||
successors.add(arc);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,8 +5,6 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.sound.midi.ControllerEventListener;
|
||||
|
||||
import org.insa.graph.Arc;
|
||||
import org.insa.graph.Graph;
|
||||
import org.insa.graph.Node;
|
||||
|
@ -147,14 +145,14 @@ public class BinaryGraphReader extends BinaryReader implements AbstractGraphRead
|
|||
Node dest = nodes.get(destNode);
|
||||
|
||||
// Add successor to initial arc.
|
||||
orig.addSuccessor(new Arc(dest, length, info, points));
|
||||
new Arc(orig, dest, length, info, points);
|
||||
|
||||
// And reverse arc if its a two-way road.
|
||||
if (!info.isOneWay()) {
|
||||
// Add without segments.
|
||||
ArrayList<Point> rPoints = new ArrayList<Point>(points);
|
||||
Collections.reverse(rPoints);
|
||||
dest.addSuccessor(new Arc(orig, length, info, rPoints));
|
||||
new Arc(dest, orig, length, info, rPoints);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue