File: EdgeList.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 (153 lines) | stat: -rw-r--r-- 3,686 bytes parent folder | download | duplicates (2)
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
/**********************************************************************
 * $Id: EdgeList.cpp,v 1.6 2004/11/22 11:34:49 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 Public Licence as published
 * by the Free Software Foundation. 
 * See the COPYING file for more information.
 *
 **********************************************************************/


#include <geos/geomgraph.h>
#include <geos/indexQuadtree.h>
#include <geos/profiler.h>

#ifndef DEBUG
#define DEBUG 0
#endif

namespace geos {

#if PROFILE
static Profiler *profiler = Profiler::instance();
#endif

EdgeList::EdgeList(){
	edges=new vector<Edge*>();
	index=new Quadtree();
}

EdgeList::~EdgeList(){
	delete edges;
	delete index;
}
/**
 * Insert an edge unless it is already in the list
 */
void EdgeList::add(Edge *e) {
	edges->push_back(e);
	index->insert(e->getEnvelope(),e);
}

void EdgeList::addAll(vector<Edge*> *edgeColl) {
	for (int i=0; i<(int)edgeColl->size();i++) {
		add((*edgeColl)[i]);
	}
}

vector<Edge*>* EdgeList::getEdges() {
	return edges;
}

// <FIX> fast lookup for edges
/**
 * If there is an edge equal to e already in the list, return it.
 * Otherwise return null.
 * @return  equal edge, if there is one already in the list
 *          null otherwise
 */
Edge *
EdgeList::findEqualEdge(Edge *e)
{
#if PROFILE
	profiler->start("Quadtree::query()");
#endif
	vector<void*> *testEdges=index->query(e->getEnvelope());
#if PROFILE
	profiler->stop("Quadtree::query()");
#endif

#if DEBUG
	cerr<<"EdgeList::findEqualEdge found "<<testEdges->size()<<" overlapping edges"<<endl;
#endif

	for (int i=0; i<(int)testEdges->size();i++) {
		Edge* testEdge=(Edge*) (*testEdges)[i];
		if (testEdge->equals(e))
		{
			delete testEdges;
			return testEdge;
		}
	}
	delete testEdges;
	return NULL;
}

Edge* EdgeList::get(int i) {
	return (*edges)[i];
}

/**
 * If the edge e is already in the list, return its index.
 * @return  index, if e is already in the list
 *          -1 otherwise
 */
int EdgeList::findEdgeIndex(Edge *e) {
	for (int i=0; i<(int)edges->size();i++) {
		if ( (*edges)[i]->equals(e) )
            return i;
	}
	return -1;
}

string EdgeList::print() {
	string out="EdgeList( ";
	for(unsigned int j=0; j<edges->size();j++)
	{
       		Edge *e=(*edges)[j];
		if (j) out+=",";
		out += e->print();
	}
	out+=")  ";
	return out;
}

} // namespace geos

/**********************************************************************
 * $Log: EdgeList.cpp,v $
 * Revision 1.6  2004/11/22 11:34:49  strk
 * More debugging lines and comments/indentation cleanups
 *
 * Revision 1.5  2004/11/01 16:43:04  strk
 * Added Profiler code.
 * Temporarly patched a bug in DoubleBits (must check drawbacks).
 * Various cleanups and speedups.
 *
 * Revision 1.4  2004/07/08 19:34:49  strk
 * Mirrored JTS interface of CoordinateSequence, factory and
 * default implementations.
 * Added DefaultCoordinateSequenceFactory::instance() function.
 *
 * Revision 1.3  2004/07/02 13:28:26  strk
 * Fixed all #include lines to reflect headers layout change.
 * Added client application build tips in README.
 *
 * Revision 1.2  2004/05/03 22:56:44  strk
 * leaks fixed, exception specification omitted.
 *
 * Revision 1.1  2004/03/19 09:48:45  ybychkov
 * "geomgraph" and "geomgraph/indexl" upgraded to JTS 1.4
 *
 * Revision 1.14  2003/11/07 01:23:42  pramsey
 * Add standard CVS headers licence notices and copyrights to all cpp and h
 * files.
 *
 *
 **********************************************************************/