| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package org.locationtech.jts.geomgraph; |
| 16 |
|
| 17 |
import java.io.PrintStream; |
| 18 |
|
| 19 |
import org.locationtech.jts.geom.Coordinate; |
| 20 |
|
| 21 |
/** |
| 22 |
* Represents a point on an |
| 23 |
* edge which intersects with another edge. |
| 24 |
* <p> |
| 25 |
* The intersection may either be a single point, or a line segment |
| 26 |
* (in which case this point is the start of the line segment) |
| 27 |
* The intersection point must be precise. |
| 28 |
* |
| 29 |
* @version 1.7 |
| 30 |
*/ |
| 31 |
public class EdgeIntersection |
| 32 |
implements Comparable |
| 33 |
{ |
| 34 |
|
| 35 |
public Coordinate coord; |
| 36 |
public int segmentIndex; |
| 37 |
public double dist; |
| 38 |
|
| 39 |
public EdgeIntersection(Coordinate coord, int segmentIndex, double dist) { |
| 40 |
this.coord = new Coordinate(coord); |
| 41 |
this.segmentIndex = segmentIndex; |
| 42 |
this.dist = dist; |
| 43 |
} |
| 44 |
|
| 45 |
public Coordinate getCoordinate() { return coord; } |
| 46 |
|
| 47 |
public int getSegmentIndex() { return segmentIndex; } |
| 48 |
|
| 49 |
public double getDistance() { return dist; } |
| 50 |
|
| 51 |
public int compareTo(Object obj) |
| 52 |
{ |
| 53 |
EdgeIntersection other = (EdgeIntersection) obj; |
| 54 |
return compare(other.segmentIndex, other.dist); |
| 55 |
} |
| 56 |
/** |
| 57 |
* @return -1 this EdgeIntersection is located before the argument location |
| 58 |
* @return 0 this EdgeIntersection is at the argument location |
| 59 |
* @return 1 this EdgeIntersection is located after the argument location |
| 60 |
*/ |
| 61 |
public int compare(int segmentIndex, double dist) |
| 62 |
{ |
| 63 |
if (this.segmentIndex < segmentIndex) return -1; |
| 64 |
if (this.segmentIndex > segmentIndex) return 1; |
| 65 |
if (this.dist < dist) return -1; |
| 66 |
if (this.dist > dist) return 1; |
| 67 |
return 0; |
| 68 |
} |
| 69 |
|
| 70 |
public boolean isEndPoint(int maxSegmentIndex) |
| 71 |
{ |
| 72 |
if (segmentIndex == 0 && dist == 0.0) return true; |
| 73 |
if (segmentIndex == maxSegmentIndex) return true; |
| 74 |
return false; |
| 75 |
} |
| 76 |
|
| 77 |
public void print(PrintStream out) |
| 78 |
{ |
| 79 |
out.print(coord); |
| 80 |
out.print(" seg # = " + segmentIndex); |
| 81 |
out.println(" dist = " + dist); |
| 82 |
} |
| 83 |
public String toString() |
| 84 |
{ |
| 85 |
return coord + " seg # = " + segmentIndex + " dist = " + dist; |
| 86 |
} |
| 87 |
} |
| 88 |
|