File: DirectedEdge.cpp

package info (click to toggle)
geos 3.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 10,060 kB
  • ctags: 8,674
  • sloc: cpp: 64,513; xml: 23,384; sh: 8,965; ruby: 1,295; makefile: 1,124; python: 824; ansic: 289
file content (188 lines) | stat: -rw-r--r-- 3,762 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
/**********************************************************************
 * $Id: DirectedEdge.cpp 1820 2006-09-06 16:54:23Z mloskot $
 *
 * 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/DirectedEdge.h>
#include <geos/planargraph/Node.h>
#include <geos/geomgraph/Quadrant.h>
#include <geos/algorithm/CGAlgorithms.h>

#include <cmath>
#include <sstream>
#include <vector>

using namespace std;
using namespace geos::geom;

namespace geos {
namespace planargraph {

/*public*/
void
DirectedEdge::toEdges(vector<DirectedEdge*>& dirEdges, vector<Edge*>& edges)
{
	for (size_t i=0, n=dirEdges.size(); i<n; ++i)
	{
		edges.push_back(dirEdges[i]->parentEdge);
	}
}

/*public*/
vector<Edge*>*
DirectedEdge::toEdges(vector<DirectedEdge*>& dirEdges) 
{
	vector<Edge*> *edges=new vector<Edge*>();
	toEdges(dirEdges, *edges);
	return edges;
}

/*public*/
DirectedEdge::DirectedEdge(Node* newFrom, Node* 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 = geomgraph::Quadrant::quadrant(dx, dy);
	angle=atan2(dy, dx);
	//Assert.isTrue(! (dx == 0 && dy == 0), "EdgeEnd with identical endpoints found");
}

/*public*/
Edge*
DirectedEdge::getEdge() const
{
	return parentEdge;
}

/*public*/
void
DirectedEdge::setEdge(Edge* newParentEdge)
{ 
	parentEdge=newParentEdge;
}

/*public*/
int
DirectedEdge::getQuadrant() const
{
	return quadrant;
}

/*public*/
const Coordinate&
DirectedEdge::getDirectionPt() const
{
	return p1;
}

/*public*/
bool
DirectedEdge::getEdgeDirection() const
{ 
	return edgeDirection;
}

/*public*/
Node*
DirectedEdge::getFromNode() const
{
	return from;
}

/*public*/
Node*
DirectedEdge::getToNode() const
{ 
	return to;
}

/*public*/
Coordinate&
DirectedEdge::getCoordinate() const
{ 
	return from->getCoordinate();
}

/*public*/
double
DirectedEdge::getAngle() const
{ 
	return angle;
}

/*public*/
DirectedEdge*
DirectedEdge::getSym() const
{ 
	return sym;
}

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

/*public*/
int
DirectedEdge::compareTo(const DirectedEdge* de) const
{
	return compareDirection(de);
}

/*public*/
int
DirectedEdge::compareDirection(const DirectedEdge *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 algorithm::CGAlgorithms::computeOrientation(e->p0,e->p1,p1);
}

/*public*/
string
DirectedEdge::print() const
{
	ostringstream s;
	s<<typeid(*this).name()<<": "<<p0.toString()<<" - "<<p1.toString();
	s<<" "<<quadrant<<":"<<angle;
	return s.str();
}


} // namespace planargraph
} // namespace geos

/**********************************************************************
 * $Log$
 * Revision 1.2  2006/06/12 15:46:09  strk
 * provided a memory friendly version of toEdges() method.
 *
 * Revision 1.1  2006/03/21 21:42:54  strk
 * planargraph.h header split, planargraph:: classes renamed to match JTS symbols
 *
 **********************************************************************/