File: planarDirectedEdgeStar.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 (201 lines) | stat: -rw-r--r-- 4,654 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
/**********************************************************************
 * $Id: planarDirectedEdgeStar.cpp,v 1.4 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>

namespace geos {
//namespace planargraph {

/*
 * Constructs a DirectedEdgeStar with no edges.
 */
planarDirectedEdgeStar::planarDirectedEdgeStar()
{
	outEdges = new vector<planarDirectedEdge*>();
	sorted=false;
}

planarDirectedEdgeStar::~planarDirectedEdgeStar()
{
	delete outEdges;
}

/*
 * Adds a new member to this DirectedEdgeStar.
 */
void
planarDirectedEdgeStar::add(planarDirectedEdge *de)
{
	outEdges->push_back(de);
	sorted=false;
}

/*
 * Drops a member of this DirectedEdgeStar.
 */
void
planarDirectedEdgeStar::remove(planarDirectedEdge *de)
{
	for(int i=0;i<(int)outEdges->size();i++) {
		if((*outEdges)[i]==de) {
			outEdges->erase(outEdges->begin()+i);
			i--;
		}
	}
}

/*
 * Returns an Iterator over the DirectedEdges, in ascending order
 * by angle with the positive x-axis.
 */
vector<planarDirectedEdge*>::iterator
planarDirectedEdgeStar::iterator()
{
	sortEdges();
	return outEdges->begin();
}

/*
 * Returns the number of edges around the Node associated with this
 * DirectedEdgeStar.
 */
int
planarDirectedEdgeStar::getDegree()
{ 
	return (int)outEdges->size();
}

/*
 * Returns the coordinate for the node at wich this star is based
 */
Coordinate&
planarDirectedEdgeStar::getCoordinate()
{
	if (outEdges->empty())
		return Coordinate::nullCoord;
	planarDirectedEdge *e=(*outEdges)[0];
	return e->getCoordinate();
}

/*
 * Returns the DirectedEdges, in ascending order by angle with
 * the positive x-axis.
 */
vector<planarDirectedEdge*>*
planarDirectedEdgeStar::getEdges()
{
	sortEdges();
	return outEdges;
}

bool
pdeLessThan(planarDirectedEdge *first, planarDirectedEdge * second)
{
	if (first->compareTo(second)<=0)
		return true;
	else
		return false;
}

void
planarDirectedEdgeStar::sortEdges()
{
	if (!sorted) {
		sort(outEdges->begin(),outEdges->end(),pdeLessThan);
		sorted=true;
	}
}

/*
 * Returns the zero-based index of the given Edge, after sorting in
 * ascending order by angle with the positive x-axis.
 */
int
planarDirectedEdgeStar::getIndex(planarEdge *edge)
{
	sortEdges();
	for (unsigned int i = 0; i<outEdges->size(); i++) {
		planarDirectedEdge *de =(*outEdges)[i];
		if (de->getEdge() == edge)
		return i;
	}
	return -1;
}

/*
 * Returns the zero-based index of the given DirectedEdge, after sorting
 * in ascending order by angle with the positive x-axis.
 */  
int
planarDirectedEdgeStar::getIndex(planarDirectedEdge *dirEdge)
{
	sortEdges();
	for (unsigned int i = 0; i <outEdges->size(); i++) {
		planarDirectedEdge *de =(*outEdges)[i];
		if (de == dirEdge)
		return i;
	}
	return -1;
}

/*
 * Returns the remainder when i is divided by the number of edges in this
 * DirectedEdgeStar. 
 */
int
planarDirectedEdgeStar::getIndex(int i)
{
	int modi = i % (int)outEdges->size();
	//I don't think modi can be 0 (assuming i is positive) [Jon Aquino 10/28/2003] 
	if (modi < 0) modi += (int)outEdges->size();
	return modi;
}

/*
 * Returns the DirectedEdge on the left-hand side of the given
 * DirectedEdge (which must be a member of this DirectedEdgeStar). 
 */
planarDirectedEdge*
planarDirectedEdgeStar::getNextEdge(planarDirectedEdge *dirEdge)
{
	int i = getIndex(dirEdge);
	return (*outEdges)[getIndex(i + 1)];
}

//} // namespace planargraph
} // namespace geos

/**********************************************************************
 * $Log: planarDirectedEdgeStar.cpp,v $
 * Revision 1.4  2004/12/14 10:35:44  strk
 * Comments cleanup. PolygonizeGraph keeps track of generated CoordinateSequence
 * for delayed destruction.
 *
 * Revision 1.3  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.2  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.1  2004/04/04 06:29:11  ybychkov
 * "planargraph" and "geom/utill" upgraded to JTS 1.4
 *
 *
 **********************************************************************/