GEOS 3.14.0dev
TopologyLocation.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2005-2006 Refractions Research Inc.
7 * Copyright (C) 2001-2002 Vivid Solutions Inc.
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************
15 *
16 * Last port: geomgraph/TopologyLocation.java r428 (JTS-1.12+)
17 *
18 **********************************************************************/
19
20#pragma once
21
22#include <geos/export.h>
23#include <geos/geom/Location.h>
24#include <geos/geom/Position.h>
25
26#include <vector>
27#include <array>
28#include <string>
29#include <cassert>
30#include <cstdint>
31
32#ifdef _MSC_VER
33#pragma warning(push)
34#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
35#endif
36
37namespace geos {
38namespace geomgraph { // geos.geomgraph
39
60class GEOS_DLL TopologyLocation {
63
64public:
65
66 friend std::ostream& operator<< (std::ostream&, const TopologyLocation&);
67
68 TopologyLocation() = default;
69
82 : locationSize(3)
83 {
84 location[Position::ON] = on;
85 location[Position::LEFT] = left;
86 location[Position::RIGHT] = right;
87 }
88
89 TopologyLocation(Location on)
90 : locationSize(1)
91 {
92 location.fill(Location::NONE);
93 location[Position::ON] = on;
94 };
95
96 TopologyLocation(const TopologyLocation& gl)
97 : location(gl.location)
98 , locationSize(gl.locationSize)
99 {};
100
101 TopologyLocation& operator= (const TopologyLocation& gl)
102 {
103 location = gl.location;
104 locationSize = gl.locationSize;
105 return *this;
106 };
107
108 Location get(std::size_t posIndex) const
109 {
110 // should be an assert() instead ?
111 if(posIndex < locationSize) {
112 return location[posIndex];
113 }
114 return Location::NONE;
115 };
116
120 bool isNull() const
121 {
122 for(std::size_t i = 0; i < locationSize; ++i) {
123 if(location[i] != Location::NONE) {
124 return false;
125 }
126 }
127 return true;
128 };
129
133 bool isAnyNull() const
134 {
135 for(std::size_t i = 0; i < locationSize; ++i) {
136 if(location[i] == Location::NONE) {
137 return true;
138 }
139 }
140 return false;
141 };
142
143 bool isEqualOnSide(const TopologyLocation& le, uint32_t locIndex) const
144 {
145 return location[locIndex] == le.location[locIndex];
146 };
147
148 bool isArea() const
149 {
150 return locationSize > 1;
151 };
152
153 bool isLine() const
154 {
155 return locationSize == 1;
156 };
157
158 void flip()
159 {
160 if(locationSize <= 1) {
161 return;
162 }
163 std::swap(location[Position::LEFT], location[Position::RIGHT]);
164 };
165
166 void setAllLocations(Location locValue)
167 {
168 location.fill(locValue);
169 };
170
171
172 void setAllLocationsIfNull(Location locValue)
173 {
174 for(std::size_t i = 0; i < locationSize; ++i) {
175 if(location[i] == Location::NONE) {
176 location[i] = locValue;
177 }
178 }
179 };
180
181 void setLocation(std::size_t locIndex, Location locValue)
182 {
183 location[locIndex] = locValue;
184 };
185
186 void setLocation(Location locValue)
187 {
188 setLocation(Position::ON, locValue);
189 };
190
191 const std::array<Location, 3>& getLocations() const
192 {
193 return location;
194 };
195
196 void setLocations(Location on, Location left, Location right)
197 {
198 assert(locationSize >= 3);
199 location[Position::ON] = on;
200 location[Position::LEFT] = left;
201 location[Position::RIGHT] = right;
202 };
203
204 bool allPositionsEqual(Location loc) const
205 {
206 for(std::size_t i = 0; i < locationSize; ++i) {
207 if(location[i] != loc) {
208 return false;
209 }
210 }
211 return true;
212 };
213
218 void merge(const TopologyLocation& gl);
219
220 std::string toString() const;
221
222
223private:
224
225 std::array<geom::Location, 3> location;
226 std::uint8_t locationSize;
227
228};
229
230std::ostream& operator<< (std::ostream&, const TopologyLocation&);
231
232} // namespace geos.geomgraph
233} // namespace geos
234
235#ifdef _MSC_VER
236#pragma warning(pop)
237#endif
A Position indicates the position of a Location relative to a graph component (Node,...
Definition Position.h:37
A TopologyLocation is the labelling of a GraphComponent's topological relationship to a single Geomet...
Definition TopologyLocation.h:60
bool isNull() const
Definition TopologyLocation.h:120
TopologyLocation(Location on, Location left, Location right)
Constructs a TopologyLocation specifying how points on, to the left of, and to the right of some Grap...
Definition TopologyLocation.h:81
void merge(const TopologyLocation &gl)
merge updates only the UNDEF attributes of this object with the attributes of another.
bool isAnyNull() const
Definition TopologyLocation.h:133
Location
Constants representing the location of a point relative to a geometry.
Definition Location.h:32
Basic namespace for all GEOS functionalities.
Definition geos.h:39