001:
002: /*
003: * The JTS Topology Suite is a collection of Java classes that
004: * implement the fundamental operations required to validate a given
005: * geo-spatial data set to a known topological specification.
006: *
007: * Copyright (C) 2001 Vivid Solutions
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: *
023: * For more information, contact:
024: *
025: * Vivid Solutions
026: * Suite #1A
027: * 2328 Government Street
028: * Victoria BC V8T 5G5
029: * Canada
030: *
031: * (250)385-6040
032: * www.vividsolutions.com
033: */
034: package com.vividsolutions.jts.geomgraph;
035:
036: import java.io.PrintStream;
037: import com.vividsolutions.jts.geom.Coordinate;
038:
039: /**
040: * Represents a point on an
041: * edge which intersects with another edge.
042: * <p>
043: * The intersection may either be a single point, or a line segment
044: * (in which case this point is the start of the line segment)
045: * The intersection point must be precise.
046: *
047: * @version 1.7
048: */
049: public class EdgeIntersection implements Comparable {
050:
051: public Coordinate coord; // the point of intersection
052: public int segmentIndex; // the index of the containing line segment in the parent edge
053: public double dist; // the edge distance of this point along the containing line segment
054:
055: public EdgeIntersection(Coordinate coord, int segmentIndex,
056: double dist) {
057: this .coord = new Coordinate(coord);
058: this .segmentIndex = segmentIndex;
059: this .dist = dist;
060: }
061:
062: public Coordinate getCoordinate() {
063: return coord;
064: }
065:
066: public int getSegmentIndex() {
067: return segmentIndex;
068: }
069:
070: public double getDistance() {
071: return dist;
072: }
073:
074: public int compareTo(Object obj) {
075: EdgeIntersection other = (EdgeIntersection) obj;
076: return compare(other.segmentIndex, other.dist);
077: }
078:
079: /**
080: * @return -1 this EdgeIntersection is located before the argument location
081: * @return 0 this EdgeIntersection is at the argument location
082: * @return 1 this EdgeIntersection is located after the argument location
083: */
084: public int compare(int segmentIndex, double dist) {
085: if (this .segmentIndex < segmentIndex)
086: return -1;
087: if (this .segmentIndex > segmentIndex)
088: return 1;
089: if (this .dist < dist)
090: return -1;
091: if (this .dist > dist)
092: return 1;
093: return 0;
094: }
095:
096: public boolean isEndPoint(int maxSegmentIndex) {
097: if (segmentIndex == 0 && dist == 0.0)
098: return true;
099: if (segmentIndex == maxSegmentIndex)
100: return true;
101: return false;
102: }
103:
104: public void print(PrintStream out) {
105: out.print(coord);
106: out.print(" seg # = " + segmentIndex);
107: out.println(" dist = " + dist);
108: }
109: }
|