Class EdgeIntersection

 1  
 2  
 3  
 4 /*
 5  * Copyright (c) 2016 Vivid Solutions.
 6  *
 7  * All rights reserved. This program and the accompanying materials
 8  * are made available under the terms of the Eclipse Public License 2.0
 9  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
10  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
11  * and the Eclipse Distribution License is available at
12  *
13  * http://www.eclipse.org/org/documents/edl-v10.php.
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;   // the point of intersection
36   public int segmentIndex;   // the index of the containing line segment in the parent edge
37   public double dist;        // the edge distance of this point along the containing line segment
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.0return 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