File: planarDirectedEdge.cpp

package info (click to toggle)
geos 2.1.1-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,784 kB
  • ctags: 3,505
  • sloc: cpp: 24,991; sh: 8,431; xml: 6,597; makefile: 401; python: 77
file content (265 lines) | stat: -rw-r--r-- 7,500 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/**********************************************************************
 * $Id: planarDirectedEdge.cpp,v 1.7 2004/12/14 10:35:44 strk Exp $
 *
 * GEOS - Geometry Engine Open Source
 * http://geos.refractions.net
 *
 * Copyright (C) 2001-2002 Vivid Solutions Inc.
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the GNU Lesser General Licence as published
 * by the Free Software Foundation. 
 * See the COPYING file for more information.
 *
 **********************************************************************/

#include <geos/planargraph.h>
#include <geos/geomgraph.h>
#include <math.h>
#include <typeinfo>
#include <stdio.h>

namespace geos {
//namespace planargraph {

/*
 * Returns a List containing the parent planarEdge (possibly null)
 * for each of the given planarDirectedEdges.
 */
vector<planarEdge*>*
planarDirectedEdge::toEdges(vector<planarDirectedEdge*> *dirEdges) 
{
	vector<planarEdge*> *edges=new vector<planarEdge*>();
	for (int i=0;i<(int)dirEdges->size();i++) {
		edges->push_back((*dirEdges)[i]->parentEdge);
	}
	return edges;
}

//const CGAlgorithms* planarDirectedEdge::cga=new CGAlgorithms();

/**
* Constructs a planarDirectedEdge connecting the <code>from</code> node to the
* <code>to</code> node.
*
* @param directionPt
*                  specifies this planarDirectedEdge's direction (given by an imaginary
*                  line from the <code>from</code> node to <code>directionPt</code>)
* @param edgeDirection
*                  whether this planarDirectedEdge's direction is the same as or
*                  opposite to that of the parent planarEdge (if any)
*/
planarDirectedEdge::planarDirectedEdge(planarNode* newFrom, planarNode* newTo,
	const Coordinate &directionPt, bool newEdgeDirection)
{
	from=newFrom;
	to=newTo;
	edgeDirection=newEdgeDirection;
	p0=from->getCoordinate();
	p1=directionPt;
	double dx = p1.x - p0.x;
	double dy = p1.y - p0.y;
	quadrant = Quadrant::quadrant(dx, dy);
	angle=atan2(dy, dx);
	//Assert.isTrue(! (dx == 0 && dy == 0), "EdgeEnd with identical endpoints found");
}

/*
 * Returns this planarDirectedEdge's parent planarEdge,
 * or null if it has none.
 */
planarEdge*
planarDirectedEdge::getEdge() const
{
	return parentEdge;
}
/*
 * Associates this planarDirectedEdge with an planarEdge
 * (possibly null, indicating no associated planarEdge).
 */
void
planarDirectedEdge::setEdge(planarEdge* newParentEdge)
{ 
	parentEdge=newParentEdge;
}

/**
* Returns 0, 1, 2, or 3, indicating the quadrant in which this planarDirectedEdge's
* orientation lies.
*/
int
planarDirectedEdge::getQuadrant() const
{
	return quadrant;
}
/**
* Returns a point to which an imaginary line is drawn from the from-node to
* specify this planarDirectedEdge's orientation.
*/
const Coordinate&
planarDirectedEdge::getDirectionPt() const
{
	return p1;
}
/**
* Returns whether the direction of the parent planarEdge (if any) is the same as that
* of this Directed planarEdge.
*/
bool planarDirectedEdge::getEdgeDirection() const { 
	return edgeDirection;
}
/**
* Returns the node from which this planarDirectedEdge leaves.
*/
planarNode*
planarDirectedEdge::getFromNode() const
{
	return from;
}
/**
* Returns the node to which this planarDirectedEdge goes.
*/
planarNode*
planarDirectedEdge::getToNode() const
{ 
	return to;
}
/**
* Returns the coordinate of the from-node.
*/
Coordinate&
planarDirectedEdge::getCoordinate() const
{ 
	return from->getCoordinate();
}
/**
* Returns the angle that the start of this planarDirectedEdge makes with the
* positive x-axis, in radians.
*/
double
planarDirectedEdge::getAngle() const
{ 
	return angle;
}
/**
* Returns the symmetric planarDirectedEdge -- the other planarDirectedEdge associated with
* this planarDirectedEdge's parent planarEdge.
*/
planarDirectedEdge*
planarDirectedEdge::getSym() const
{ 
	return sym;
}

/*
 * Sets this planarDirectedEdge's symmetric planarDirectedEdge,
 * which runs in the opposite direction.
 */
void
planarDirectedEdge::setSym(planarDirectedEdge *newSym)
{ 
	sym = newSym;
}

/**
 * Returns 1 if this planarDirectedEdge has a greater angle with the
 * positive x-axis than b", 0 if the planarDirectedEdges are collinear, and -1 otherwise.
 * <p>
 * Using the obvious algorithm of simply computing the angle is not robust,
 * since the angle calculation is susceptible to roundoff. A robust algorithm
 * is:
 * <ul>
 * <li>first compare the quadrants. If the quadrants are different, it it
 * trivial to determine which vector is "greater".
 * <li>if the vectors lie in the same quadrant, the robust
 * {@link RobustCGAlgorithms#computeOrientation(Coordinate, Coordinate, Coordinate)}
 * function can be used to decide the relative orientation of the vectors.
 * </ul>
 */
int
planarDirectedEdge::compareTo(const planarDirectedEdge* de) const
{
	return compareDirection(de);
}

/**
* Returns 1 if this planarDirectedEdge has a greater angle with the
* positive x-axis than b", 0 if the planarDirectedEdges are collinear, and -1 otherwise.
* <p>
* Using the obvious algorithm of simply computing the angle is not robust,
* since the angle calculation is susceptible to roundoff. A robust algorithm
* is:
* <ul>
* <li>first compare the quadrants. If the quadrants are different, it it
* trivial to determine which vector is "greater".
* <li>if the vectors lie in the same quadrant, the robust
* {@link RobustCGAlgorithms#computeOrientation(Coordinate, Coordinate, Coordinate)}
* function can be used to decide the relative orientation of the vectors.
* </ul>
*/
int
planarDirectedEdge::compareDirection(const planarDirectedEdge *e) const
{
// if the rays are in different quadrants, determining the ordering is trivial
	if (quadrant > e->quadrant) return 1;
	if (quadrant < e->quadrant) return -1;
	// vectors are in the same quadrant - check relative orientation of direction vectors
	// this is > e if it is CCW of e
	return cga.computeOrientation(e->p0,e->p1,p1);
}

/**
* Prints a detailed string representation of this planarDirectedEdge to the given PrintStream.
*/
string
planarDirectedEdge::print() const
{
	string out=typeid(*this).name();
	out+=" : ";
	out+=p0.toString();
	out+=" - ";
	out+=p1.toString();
	char buffer[255];
	sprintf(buffer," %i:%g) ",quadrant,angle);
	out.append(buffer);
	out.append("");
	return out;
}


//} // namespace planargraph

} // namespace geos

/**********************************************************************
 * $Log: planarDirectedEdge.cpp,v $
 * Revision 1.7  2004/12/14 10:35:44  strk
 * Comments cleanup. PolygonizeGraph keeps track of generated CoordinateSequence
 * for delayed destruction.
 *
 * Revision 1.6  2004/10/19 19:51:14  strk
 * Fixed many leaks and bugs in Polygonizer.
 * Output still bogus.
 *
 * Revision 1.5  2004/10/13 10:03:02  strk
 * Added missing linemerge and polygonize operation.
 * Bug fixes and leaks removal from the newly added modules and
 * planargraph (used by them).
 * Some comments and indentation changes.
 *
 * Revision 1.4  2004/07/02 13:28:29  strk
 * Fixed all #include lines to reflect headers layout change.
 * Added client application build tips in README.
 *
 * Revision 1.3  2004/06/15 07:40:30  strk
 * Added missing <stdio.h> include
 *
 * Revision 1.2  2004/05/03 10:43:43  strk
 * Exception specification considered harmful - left as comment.
 *
 * Revision 1.1  2004/04/04 06:29:11  ybychkov
 * "planargraph" and "geom/utill" upgraded to JTS 1.4
 *
 *
 **********************************************************************/