| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
package org.locationtech.jts.noding; |
| 13 |
|
| 14 |
import java.io.PrintStream; |
| 15 |
|
| 16 |
import org.locationtech.jts.geom.Coordinate; |
| 17 |
|
| 18 |
/** |
| 19 |
* Represents an intersection point between two {@link SegmentString}s. |
| 20 |
* |
| 21 |
* @version 1.7 |
| 22 |
*/ |
| 23 |
public class SegmentNode |
| 24 |
implements Comparable |
| 25 |
{ |
| 26 |
private final NodedSegmentString segString; |
| 27 |
public final Coordinate coord; |
| 28 |
public final int segmentIndex; |
| 29 |
private final int segmentOctant; |
| 30 |
private final boolean isInterior; |
| 31 |
|
| 32 |
public SegmentNode(NodedSegmentString segString, Coordinate coord, int segmentIndex, int segmentOctant) { |
| 33 |
this.segString = segString; |
| 34 |
this.coord = new Coordinate(coord); |
| 35 |
this.segmentIndex = segmentIndex; |
| 36 |
this.segmentOctant = segmentOctant; |
| 37 |
isInterior = ! coord.equals2D(segString.getCoordinate(segmentIndex)); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Gets the {@link Coordinate} giving the location of this node. |
| 42 |
* |
| 43 |
* @return the coordinate of the node |
| 44 |
*/ |
| 45 |
public Coordinate getCoordinate() |
| 46 |
{ |
| 47 |
return coord; |
| 48 |
} |
| 49 |
|
| 50 |
public boolean isInterior() { return isInterior; } |
| 51 |
|
| 52 |
public boolean isEndPoint(int maxSegmentIndex) |
| 53 |
{ |
| 54 |
if (segmentIndex == 0 && ! isInterior) return true; |
| 55 |
if (segmentIndex == maxSegmentIndex) return true; |
| 56 |
return false; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* @return -1 this SegmentNode is located before the argument location; |
| 61 |
* 0 this SegmentNode is at the argument location; |
| 62 |
* 1 this SegmentNode is located after the argument location |
| 63 |
*/ |
| 64 |
public int compareTo(Object obj) |
| 65 |
{ |
| 66 |
SegmentNode other = (SegmentNode) obj; |
| 67 |
|
| 68 |
if (segmentIndex < other.segmentIndex) return -1; |
| 69 |
if (segmentIndex > other.segmentIndex) return 1; |
| 70 |
|
| 71 |
if (coord.equals2D(other.coord)) return 0; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
if (! isInterior) return -1; |
| 76 |
if (! other.isInterior) return 1; |
| 77 |
|
| 78 |
return SegmentPointComparator.compare(segmentOctant, coord, other.coord); |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
public void print(PrintStream out) |
| 83 |
{ |
| 84 |
out.print(coord); |
| 85 |
out.print(" seg # = " + segmentIndex); |
| 86 |
} |
| 87 |
|
| 88 |
public String toString() { |
| 89 |
return segmentIndex + ":" + coord.toString(); |
| 90 |
} |
| 91 |
} |
| 92 |
|