~ubuntu-branches/ubuntu/natty/jts/natty

« back to all changes in this revision

Viewing changes to src/com/vividsolutions/jts/noding/SegmentNode.java

  • Committer: Bazaar Package Importer
  • Author(s): Wolfgang Baer
  • Date: 2005-08-07 14:12:35 UTC
  • Revision ID: james.westby@ubuntu.com-20050807141235-7hy3ll3xpq79djcb
Tags: upstream-1.6
ImportĀ upstreamĀ versionĀ 1.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
 
 
4
/*
 
5
 * The JTS Topology Suite is a collection of Java classes that
 
6
 * implement the fundamental operations required to validate a given
 
7
 * geo-spatial data set to a known topological specification.
 
8
 *
 
9
 * Copyright (C) 2001 Vivid Solutions
 
10
 *
 
11
 * This library is free software; you can redistribute it and/or
 
12
 * modify it under the terms of the GNU Lesser General Public
 
13
 * License as published by the Free Software Foundation; either
 
14
 * version 2.1 of the License, or (at your option) any later version.
 
15
 *
 
16
 * This library is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
19
 * Lesser General Public License for more details.
 
20
 *
 
21
 * You should have received a copy of the GNU Lesser General Public
 
22
 * License along with this library; if not, write to the Free Software
 
23
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
24
 *
 
25
 * For more information, contact:
 
26
 *
 
27
 *     Vivid Solutions
 
28
 *     Suite #1A
 
29
 *     2328 Government Street
 
30
 *     Victoria BC  V8T 5G5
 
31
 *     Canada
 
32
 *
 
33
 *     (250)385-6040
 
34
 *     www.vividsolutions.com
 
35
 */
 
36
package com.vividsolutions.jts.noding;
 
37
 
 
38
/**
 
39
 * Represents a point on an
 
40
 * edge which intersects with another edge.
 
41
 * <br>
 
42
 * The intersection may either be a single point, or a line segment
 
43
 * (in which case this point is the start of the line segment)
 
44
 * The label attached to this intersection point applies to
 
45
 * the edge from this point forwards, until the next
 
46
 * intersection or the end of the edge.
 
47
 * The intersection point must be precise.
 
48
 * @version 1.6
 
49
 */
 
50
import java.io.PrintStream;
 
51
import com.vividsolutions.jts.geom.Coordinate;
 
52
 
 
53
/**
 
54
 * Represents an intersection point between two {@link SegmentString}s.
 
55
 *
 
56
 * @version 1.6
 
57
 */
 
58
public class SegmentNode
 
59
    implements Comparable
 
60
{
 
61
 
 
62
  public Coordinate coord;   // the point of intersection
 
63
  public int segmentIndex;   // the index of the containing line segment in the parent edge
 
64
  public double dist;        // the edge distance of this point along the containing line segment
 
65
  //Label label;
 
66
 
 
67
  public SegmentNode(Coordinate coord, int segmentIndex, double dist) {
 
68
    //this.edge = edge;
 
69
    this.coord = new Coordinate(coord);
 
70
    this.segmentIndex = segmentIndex;
 
71
    this.dist = dist;
 
72
    //label = new Label();
 
73
  }
 
74
 
 
75
  /**
 
76
   * @return -1 this EdgeIntersection is located before the argument location
 
77
   * @return 0 this EdgeIntersection is at the argument location
 
78
   * @return 1 this EdgeIntersection is located after the argument location
 
79
   */
 
80
  public int compare(int segmentIndex, double dist)
 
81
  {
 
82
    if (this.segmentIndex < segmentIndex) return -1;
 
83
    if (this.segmentIndex > segmentIndex) return 1;
 
84
    if (this.dist < dist) return -1;
 
85
    if (this.dist > dist) return 1;
 
86
    return 0;
 
87
  }
 
88
 
 
89
  public boolean isEndPoint(int maxSegmentIndex)
 
90
  {
 
91
    if (segmentIndex == 0 && dist == 0.0) return true;
 
92
    if (segmentIndex == maxSegmentIndex) return true;
 
93
    return false;
 
94
  }
 
95
 
 
96
  public int compareTo(Object obj)
 
97
  {
 
98
    SegmentNode other = (SegmentNode) obj;
 
99
    return compare(other.segmentIndex, other.dist);
 
100
  }
 
101
 
 
102
  public void print(PrintStream out)
 
103
  {
 
104
    out.print(coord);
 
105
    out.print(" seg # = " + segmentIndex);
 
106
    out.println(" dist = " + dist);
 
107
  }
 
108
}