GEOS 3.11.1
Label.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/Label.java r428 (JTS-1.12+)
17 *
18 **********************************************************************/
19
20
21#pragma once
22
23#include <geos/export.h>
24#include <geos/geom/Location.h>
25#include <geos/geomgraph/TopologyLocation.h>
26
27#include <iosfwd> // for operator<<
28#include <cassert>
29
30namespace geos {
31namespace geomgraph { // geos.geomgraph
32
57class GEOS_DLL Label {
58
59public:
60
61 friend std::ostream& operator<< (std::ostream&, const Label&);
62
68 static Label toLineLabel(const Label& label)
69 {
70 Label lineLabel(geom::Location::NONE);
71 for(uint32_t i = 0; i < 2; i++) {
72 lineLabel.setLocation(i, label.getLocation(i));
73 }
74 return lineLabel;
75 };
76
81 : elt{TopologyLocation(onLoc)
82 , TopologyLocation(onLoc)}
83 {};
84
92 Label(uint32_t geomIndex, geom::Location onLoc)
93 : elt{TopologyLocation(geom::Location::NONE)
94 , TopologyLocation(geom::Location::NONE)}
95 {
96 assert(geomIndex < 2);
97 elt[geomIndex].setLocation(onLoc);
98 };
99
106 : elt {TopologyLocation(onLoc, leftLoc, rightLoc)
107 , TopologyLocation(onLoc, leftLoc, rightLoc)}
108 {};
109
111 Label(const Label& l)
112 : elt{TopologyLocation(l.elt[0])
113 , TopologyLocation(l.elt[1])}
114 {};
115
122 : elt{TopologyLocation(geom::Location::NONE)
123 , TopologyLocation(geom::Location::NONE)}
124 {};
125
132 Label(uint32_t geomIndex, geom::Location onLoc, geom::Location leftLoc, geom::Location rightLoc)
133 {
136 elt[geomIndex].setLocations(onLoc, leftLoc, rightLoc);
137 };
138
139 Label&
140 operator=(const Label& l)
141 {
142 elt[0] = TopologyLocation(l.elt[0]);
143 elt[1] = TopologyLocation(l.elt[1]);
144 return *this;
145 };
146
147 void flip()
148 {
149 elt[0].flip();
150 elt[1].flip();
151 };
152
159 void merge(const Label& lbl)
160 {
161 for(int i = 0; i < 2; i++) {
162 elt[i].merge(lbl.elt[i]);
163 }
164 };
165
166 int getGeometryCount() const
167 {
168 int count = 0;
169 if(!elt[0].isNull()) {
170 count++;
171 }
172 if(!elt[1].isNull()) {
173 count++;
174 }
175 return count;
176 };
177
178 geom::Location getLocation(uint32_t geomIndex, uint32_t posIndex) const
179 {
180 assert(geomIndex < 2);
181 return elt[geomIndex].get(posIndex);
182 };
183
184 geom::Location getLocation(uint32_t geomIndex) const
185 {
186 assert(geomIndex < 2);
187 return elt[geomIndex].get(Position::ON);
188 };
189
190 void setLocation(uint32_t geomIndex, uint32_t posIndex, geom::Location location)
191 {
192 assert(geomIndex < 2);
193 elt[geomIndex].setLocation(posIndex, location);
194 };
195
196 void setLocation(uint32_t geomIndex, geom::Location location)
197 {
198 assert(geomIndex < 2);
199 elt[geomIndex].setLocation(Position::ON, location);
200 };
201
202 void setAllLocations(uint32_t geomIndex, geom::Location location)
203 {
204 assert(geomIndex < 2);
205 elt[geomIndex].setAllLocations(location);
206 };
207
208 void setAllLocationsIfNull(uint32_t geomIndex, geom::Location location)
209 {
210 assert(geomIndex < 2);
211 elt[geomIndex].setAllLocationsIfNull(location);
212 };
213
214 void setAllLocationsIfNull(geom::Location location)
215 {
216 setAllLocationsIfNull(0, location);
217 setAllLocationsIfNull(1, location);
218 };
219
220 bool isNull(uint32_t geomIndex) const
221 {
222 assert(geomIndex < 2);
223 return elt[geomIndex].isNull();
224 };
225
226 bool isNull() const
227 {
228 return elt[0].isNull() && elt[1].isNull();
229 };
230
231 bool isAnyNull(uint32_t geomIndex) const
232 {
233 assert(geomIndex < 2);
234 return elt[geomIndex].isAnyNull();
235 };
236
237 bool isArea() const
238 {
239 return elt[0].isArea() || elt[1].isArea();
240 };
241
242 bool isArea(uint32_t geomIndex) const
243 {
244 assert(geomIndex < 2);
245 return elt[geomIndex].isArea();
246 };
247
248 bool isLine(uint32_t geomIndex) const
249 {
250 assert(geomIndex < 2);
251 return elt[geomIndex].isLine();
252 };
253
254 bool isEqualOnSide(const Label& lbl, uint32_t side) const
255 {
256 return elt[0].isEqualOnSide(lbl.elt[0], side)
257 && elt[1].isEqualOnSide(lbl.elt[1], side);
258 };
259
260 bool allPositionsEqual(uint32_t geomIndex, geom::Location loc) const
261 {
262 assert(geomIndex < 2);
263 return elt[geomIndex].allPositionsEqual(loc);
264 };
265
269 void toLine(uint32_t geomIndex)
270 {
271 assert(geomIndex < 2);
272 if(elt[geomIndex].isArea()) {
273 elt[geomIndex] = TopologyLocation(elt[geomIndex].getLocations()[0]);
274 }
275 };
276
277 std::string toString() const;
278
279private:
280
281 TopologyLocation elt[2];
282
283};
284
285std::ostream& operator<< (std::ostream&, const Label&);
286
287} // namespace geos.geomgraph
288} // namespace geos
289
290
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition: Label.h:57
Label(geom::Location onLoc)
Construct a Label with a single location for both Geometries.
Definition: Label.h:80
Label(geom::Location onLoc, geom::Location leftLoc, geom::Location rightLoc)
Construct a Label with On, Left and Right locations for both Geometries.
Definition: Label.h:105
void merge(const Label &lbl)
Merge this label with another one.
Definition: Label.h:159
Label(uint32_t geomIndex, geom::Location onLoc)
Construct a Label with the location specified for the given Geometry.
Definition: Label.h:92
Label()
Initialize both locations to Location::NONE.
Definition: Label.h:121
static Label toLineLabel(const Label &label)
Converts a Label to a Line label (that is, one with no side Locations)
Definition: Label.h:68
Label(const Label &l)
Copy ctor.
Definition: Label.h:111
Label(uint32_t geomIndex, geom::Location onLoc, geom::Location leftLoc, geom::Location rightLoc)
Construct a Label with On, Left and Right locations for the given Geometries. Initialize the location...
Definition: Label.h:132
void toLine(uint32_t geomIndex)
Converts one GeometryLocation to a Line location.
Definition: Label.h:269
A TopologyLocation is the labelling of a GraphComponent's topological relationship to a single Geomet...
Definition: TopologyLocation.h:62
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