| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package org.locationtech.jts.operation.relate; |
| 16 |
|
| 17 |
/** |
| 18 |
* An EdgeEndBuilder creates EdgeEnds for all the "split edges" |
| 19 |
* created by the |
| 20 |
* intersections determined for an Edge. |
| 21 |
* |
| 22 |
* @version 1.7 |
| 23 |
*/ |
| 24 |
import java.util.ArrayList; |
| 25 |
import java.util.Iterator; |
| 26 |
import java.util.List; |
| 27 |
|
| 28 |
import org.locationtech.jts.geom.Coordinate; |
| 29 |
import org.locationtech.jts.geomgraph.Edge; |
| 30 |
import org.locationtech.jts.geomgraph.EdgeEnd; |
| 31 |
import org.locationtech.jts.geomgraph.EdgeIntersection; |
| 32 |
import org.locationtech.jts.geomgraph.EdgeIntersectionList; |
| 33 |
import org.locationtech.jts.geomgraph.Label; |
| 34 |
|
| 35 |
/** |
| 36 |
* Computes the {@link EdgeEnd}s which arise from a noded {@link Edge}. |
| 37 |
* |
| 38 |
* @version 1.7 |
| 39 |
*/ |
| 40 |
public class EdgeEndBuilder { |
| 41 |
|
| 42 |
public EdgeEndBuilder() { |
| 43 |
} |
| 44 |
|
| 45 |
public List computeEdgeEnds(Iterator edges) |
| 46 |
{ |
| 47 |
List l = new ArrayList(); |
| 48 |
for (Iterator i = edges; i.hasNext(); ) { |
| 49 |
Edge e = (Edge) i.next(); |
| 50 |
computeEdgeEnds(e, l); |
| 51 |
} |
| 52 |
return l; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Creates stub edges for all the intersections in this |
| 57 |
* Edge (if any) and inserts them into the graph. |
| 58 |
*/ |
| 59 |
public void computeEdgeEnds(Edge edge, List l) |
| 60 |
{ |
| 61 |
EdgeIntersectionList eiList = edge.getEdgeIntersectionList(); |
| 62 |
|
| 63 |
|
| 64 |
eiList.addEndpoints(); |
| 65 |
|
| 66 |
Iterator it = eiList.iterator(); |
| 67 |
EdgeIntersection eiPrev = null; |
| 68 |
EdgeIntersection eiCurr = null; |
| 69 |
|
| 70 |
if (! it.hasNext()) return; |
| 71 |
EdgeIntersection eiNext = (EdgeIntersection) it.next(); |
| 72 |
do { |
| 73 |
eiPrev = eiCurr; |
| 74 |
eiCurr = eiNext; |
| 75 |
eiNext = null; |
| 76 |
if (it.hasNext()) eiNext = (EdgeIntersection) it.next(); |
| 77 |
|
| 78 |
if (eiCurr != null) { |
| 79 |
createEdgeEndForPrev(edge, l, eiCurr, eiPrev); |
| 80 |
createEdgeEndForNext(edge, l, eiCurr, eiNext); |
| 81 |
} |
| 82 |
|
| 83 |
} while (eiCurr != null); |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Create a EdgeStub for the edge before the intersection eiCurr. |
| 89 |
* The previous intersection is provided |
| 90 |
* in case it is the endpoint for the stub edge. |
| 91 |
* Otherwise, the previous point from the parent edge will be the endpoint. |
| 92 |
* <br> |
| 93 |
* eiCurr will always be an EdgeIntersection, but eiPrev may be null. |
| 94 |
*/ |
| 95 |
void createEdgeEndForPrev( |
| 96 |
Edge edge, |
| 97 |
List l, |
| 98 |
EdgeIntersection eiCurr, |
| 99 |
EdgeIntersection eiPrev) |
| 100 |
{ |
| 101 |
|
| 102 |
int iPrev = eiCurr.segmentIndex; |
| 103 |
if (eiCurr.dist == 0.0) { |
| 104 |
|
| 105 |
if (iPrev == 0) return; |
| 106 |
iPrev--; |
| 107 |
} |
| 108 |
Coordinate pPrev = edge.getCoordinate(iPrev); |
| 109 |
|
| 110 |
if (eiPrev != null && eiPrev.segmentIndex >= iPrev) |
| 111 |
pPrev = eiPrev.coord; |
| 112 |
|
| 113 |
Label label = new Label(edge.getLabel()); |
| 114 |
|
| 115 |
label.flip(); |
| 116 |
EdgeEnd e = new EdgeEnd(edge, eiCurr.coord, pPrev, label); |
| 117 |
|
| 118 |
l.add(e); |
| 119 |
} |
| 120 |
/** |
| 121 |
* Create a StubEdge for the edge after the intersection eiCurr. |
| 122 |
* The next intersection is provided |
| 123 |
* in case it is the endpoint for the stub edge. |
| 124 |
* Otherwise, the next point from the parent edge will be the endpoint. |
| 125 |
* <br> |
| 126 |
* eiCurr will always be an EdgeIntersection, but eiNext may be null. |
| 127 |
*/ |
| 128 |
void createEdgeEndForNext( |
| 129 |
Edge edge, |
| 130 |
List l, |
| 131 |
EdgeIntersection eiCurr, |
| 132 |
EdgeIntersection eiNext) |
| 133 |
{ |
| 134 |
|
| 135 |
int iNext = eiCurr.segmentIndex + 1; |
| 136 |
|
| 137 |
if (iNext >= edge.getNumPoints() && eiNext == null) return; |
| 138 |
|
| 139 |
Coordinate pNext = edge.getCoordinate(iNext); |
| 140 |
|
| 141 |
|
| 142 |
if (eiNext != null && eiNext.segmentIndex == eiCurr.segmentIndex) |
| 143 |
pNext = eiNext.coord; |
| 144 |
|
| 145 |
EdgeEnd e = new EdgeEnd(edge, eiCurr.coord, pNext, new Label(edge.getLabel())); |
| 146 |
|
| 147 |
l.add(e); |
| 148 |
} |
| 149 |
|
| 150 |
} |
| 151 |
|