Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / vividsolutions / jts / geomgraph / SnapDirectedEdge.java @ 9178

History | View | Annotate | Download (4.04 KB)

1
/*
2
 * Created on 02-oct-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: SnapDirectedEdge.java 9178 2006-12-04 19:30:23Z azabala $
47
* $Log$
48
* Revision 1.1  2006-12-04 19:30:23  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.1  2006/10/17 18:25:53  azabala
52
* *** empty log message ***
53
*
54
* Revision 1.2  2006/10/09 19:10:56  azabala
55
* First version in CVS
56
*
57
* Revision 1.1  2006/10/05 19:20:57  azabala
58
* first version in cvs
59
*
60
* Revision 1.1  2006/10/02 19:06:39  azabala
61
* *** empty log message ***
62
*
63
*
64
*/
65
package com.vividsolutions.jts.geomgraph;
66

    
67
import com.vividsolutions.jts.algorithms.SnapCGAlgorithms;
68
import com.vividsolutions.jts.geom.Coordinate;
69
import com.vividsolutions.jts.geomgraph.DirectedEdge;
70
import com.vividsolutions.jts.geomgraph.Edge;
71
import com.vividsolutions.jts.geomgraph.Quadrant;
72
import com.vividsolutions.jts.util.Assert;
73

    
74
public class SnapDirectedEdge extends DirectedEdge {
75

    
76
        private Coordinate p0;
77
        private Coordinate p1;
78
        private double dx, dy;
79
        int quadrant;
80
        
81
        public SnapDirectedEdge(Edge arg0, boolean arg1) {
82
                super(arg0, arg1);
83
        }
84
         
85
        public Coordinate getCoordinate() { return p0; }
86
          public Coordinate getDirectedCoordinate() { return p1; }
87
          public int getQuadrant() { return quadrant; }
88
          public double getDx() { return dx; }
89
          public double getDy() { return dy; }
90

    
91
 protected void init(Coordinate p0, Coordinate p1)
92
  {
93
    this.p0 = p0;
94
    this.p1 = p1;
95
    dx = p1.x - p0.x;
96
    dy = p1.y - p0.y;
97
    if(dx == 0 && dy == 0)
98
            System.out.println(p0.toString()+";"+p1.toString());
99
    quadrant = Quadrant.quadrant(dx, dy);
100
   
101
    Assert.isTrue(! (dx == 0 && dy == 0), "EdgeEnd with identical endpoints found");
102
  }
103
 
104
 public String toString(){
105
         return this.p0.toString() + "," + p1.toString();
106
 }
107
 
108
 public int compareTo(Object obj)
109
 {
110
     SnapDirectedEdge de = (SnapDirectedEdge) obj;
111
     return compareDirection(de);
112
 }
113

    
114
 /**
115
  * Returns 1 if this DirectedEdge has a greater angle with the
116
  * positive x-axis than b", 0 if the DirectedEdges are collinear, and -1 otherwise.
117
  * <p>
118
  * Using the obvious algorithm of simply computing the angle is not robust,
119
  * since the angle calculation is susceptible to roundoff. A robust algorithm
120
  * is:
121
  * <ul>
122
  * <li>first compare the quadrants. If the quadrants are different, it it
123
  * trivial to determine which vector is "greater".
124
  * <li>if the vectors lie in the same quadrant, the robust
125
  * {@link RobustCGAlgorithms#computeOrientation(Coordinate, Coordinate, Coordinate)}
126
  * function can be used to decide the relative orientation of the vectors.
127
  * </ul>
128
  */
129
 public int compareDirection(SnapDirectedEdge e)
130
 {
131
   // if the rays are in different quadrants, determining the ordering is trivial
132
   if (quadrant > e.quadrant) return 1;
133
   if (quadrant < e.quadrant) return -1;
134
   // vectors are in the same quadrant - check relative orientation of direction vectors
135
   // this is > e if it is CCW of e
136
   return SnapCGAlgorithms.computeOrientation(e.p0, e.p1, p1);
137
 }
138
 
139
   
140
}
141