Class LineMergeDirectedEdge

 1  
 2 /*
 3  * Copyright (c) 2016 Vivid Solutions.
 4  *
 5  * All rights reserved. This program and the accompanying materials
 6  * are made available under the terms of the Eclipse Public License 2.0
 7  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 8  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
 9  * and the Eclipse Distribution License is available at
10  *
11  * http://www.eclipse.org/org/documents/edl-v10.php.
12  */
13 package org.locationtech.jts.operation.linemerge;
14  
15 import org.locationtech.jts.geom.Coordinate;
16 import org.locationtech.jts.planargraph.DirectedEdge;
17 import org.locationtech.jts.planargraph.Node;
18 import org.locationtech.jts.util.Assert;
19  
20 /**
21  * A {@link org.locationtech.jts.planargraph.DirectedEdge} of a 
22  * {@link LineMergeGraph}. 
23  *
24  * @version 1.7
25  */
26 public class LineMergeDirectedEdge extends DirectedEdge {
27   /**
28    * Constructs a LineMergeDirectedEdge connecting the <code>from</code> node to the
29    * <code>to</code> node.
30    *
31    * @param directionPt
32    *                  specifies this DirectedEdge's direction (given by an imaginary
33    *                  line from the <code>from</code> node to <code>directionPt</code>)
34    * @param edgeDirection
35    *                  whether this DirectedEdge's direction is the same as or
36    *                  opposite to that of the parent Edge (if any)
37    */  
38   public LineMergeDirectedEdge(Node from, Node to, Coordinate directionPt,
39     boolean edgeDirection) {
40     super(from, to, directionPt, edgeDirection);
41   }
42  
43   /**
44    * Returns the directed edge that starts at this directed edge's end point, or null
45    * if there are zero or multiple directed edges starting there.  
46    * @return the directed edge
47    */
48   public LineMergeDirectedEdge getNext() {
49     if (getToNode().getDegree() != 2) {
50       return null;
51     }
52     if (getToNode().getOutEdges().getEdges().get(0) == getSym()) {
53       return (LineMergeDirectedEdge) getToNode().getOutEdges().getEdges().get(1);
54     }
55     Assert.isTrue(getToNode().getOutEdges().getEdges().get(1) == getSym());
56  
57     return (LineMergeDirectedEdge) getToNode().getOutEdges().getEdges().get(0);
58   }
59 }
60