File: TopologyLocation.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 (196 lines) | stat: -rw-r--r-- 5,392 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
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
/**********************************************************************
 * $Id: TopologyLocation.cpp,v 1.2 2004/07/02 13:28:26 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.
 *
 **********************************************************************
 * $Log: TopologyLocation.cpp,v $
 * Revision 1.2  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.1  2004/03/19 09:48:45  ybychkov
 * "geomgraph" and "geomgraph/indexl" upgraded to JTS 1.4
 *
 * Revision 1.8  2003/11/07 01:23:42  pramsey
 * Add standard CVS headers licence notices and copyrights to all cpp and h
 * files.
 *
 *
 **********************************************************************/


#include <geos/geomgraph.h>

namespace geos {

TopologyLocation::TopologyLocation(const vector<int>* newLocation){
	location=new vector<int>();
	init((int)newLocation->size());
}

TopologyLocation::TopologyLocation(){
	location=NULL;
}

TopologyLocation::~TopologyLocation(){
	if ( location )
	{
		location->clear();
		delete location;
	}
}

/**
* Constructs a TopologyLocation specifying how points on, to the left of, and to the
* right of some GraphComponent relate to some Geometry. Possible values for the
* parameters are Location.NULL, Location.EXTERIOR, Location.BOUNDARY, 
* and Location.INTERIOR.
* @see Location
*/
TopologyLocation::TopologyLocation(int on, int left, int right) {
	location=new vector<int>();
	init(3);
	(*location)[Position::ON]=on;
	(*location)[Position::LEFT]=left;
	(*location)[Position::RIGHT]=right;
}

TopologyLocation::TopologyLocation(int on) {
	location=new vector<int>();
	init(1);
	(*location)[Position::ON]=on;
}

TopologyLocation::TopologyLocation(const TopologyLocation *gl) {
	location=new vector<int>(gl->location->begin(),gl->location->end());
}

void TopologyLocation::init(int size){
	location->resize(size);
	setAllLocations(Location::UNDEF);
}

int TopologyLocation::get(int posIndex) const {
	if (posIndex< (int)location->size()) return (*location)[posIndex];
	return Location::UNDEF;
}

/**
 * @return true if all locations are NULL
 */
bool TopologyLocation::isNull() const {
	for (unsigned int i=0; i<location->size(); i++) {
		if ((*location)[i]!=Location::UNDEF) return false;
	}
	return true;
}

/**
 * @return true if any locations are NULL
 */
bool TopologyLocation::isAnyNull() const {
	for (unsigned int i=0; i<location->size(); i++) {
		if ((*location)[i]==Location::UNDEF) return true;
	}
	return false;
}

bool TopologyLocation::isEqualOnSide(const TopologyLocation &le, int locIndex) const {
	return (*location)[locIndex]==(*(le.location))[locIndex];
}

bool TopologyLocation::isArea() const {
	return location->size()>1;
}

bool TopologyLocation::isLine() const {
	return location->size()==1;
}

void TopologyLocation::flip() {
	if (location->size()<=1) return;
	int temp=(*location)[Position::LEFT];
	(*location)[Position::LEFT]=(*location)[Position::RIGHT];
	(*location)[Position::RIGHT] = temp;
}

void TopologyLocation::setAllLocations(int locValue){
	for (unsigned int i=0; i<location->size(); i++) {
		(*location)[i]=locValue;
	}
}

void TopologyLocation::setAllLocationsIfNull(int locValue){
	for (unsigned int i=0; i<location->size(); i++) {
		if ((*location)[i]==Location::UNDEF) (*location)[i]=locValue;
	}
}

void TopologyLocation::setLocation(int locIndex, int locValue){
	(*location)[locIndex]=locValue;
}

void TopologyLocation::setLocation(int locValue){
	setLocation(Position::ON, locValue);
}

const vector<int>* TopologyLocation::getLocations() const {
	return location;
}

void TopologyLocation::setLocations(int on, int left, int right) {
	(*location)[Position::ON]=on;
	(*location)[Position::LEFT]=left;
	(*location)[Position::RIGHT]=right;
}

void TopologyLocation::setLocations(const TopologyLocation& gl){
	for (unsigned int i=0; i<gl.location->size(); i++) {
		(*location)[i]=(*(gl.location))[i];
	}
}

bool TopologyLocation::allPositionsEqual(int loc) const {
	for (unsigned int i=0; i<location->size(); i++) {
		if ((*location)[i]!=loc) return false;
	}
	return true;
}

/**
 * merge updates only the NULL attributes of this object
 * with the attributes of another.
 */
void TopologyLocation::merge(const TopologyLocation* gl){
	// if the src is an Area label & and the dest is not, increase the dest to be an Area
	if (gl->location->size()>location->size()) {
		vector<int> newLoc(3);
		newLoc[Position::ON]=(*location)[Position::ON];
		newLoc[Position::LEFT]=Location::UNDEF;
		newLoc[Position::RIGHT]=Location::UNDEF;
		location->swap(newLoc);
	}
	for (unsigned int i=0; i<location->size(); i++) {
		if ((*location)[i]==Location::UNDEF && i<gl->location->size())
			(*location)[i]=(*(gl->location))[i];
	}
}

string TopologyLocation::toString() const {
	string buf="";
	if (location->size()>1) buf+=Location::toLocationSymbol((*location)[Position::LEFT]);
	buf+=Location::toLocationSymbol((*location)[Position::ON]);
	if (location->size()>1) buf+=Location::toLocationSymbol((*location)[Position::RIGHT]);
	return buf;
}
}