GEOS 3.11.2
OverlayLabel.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca>
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <cstdint>
18
19#include <geos/geom/Location.h>
20#include <geos/geom/Position.h>
21#include <geos/export.h>
22#include <cstdint>
23
26
27namespace geos { // geos.
28namespace operation { // geos.operation
29namespace overlayng { // geos.operation.overlayng
30
90class GEOS_DLL OverlayLabel {
91
92private:
93
94 // Members
95 int aDim = DIM_NOT_PART;
96 bool aIsHole = false;
97 Location aLocLeft = LOC_UNKNOWN;
98 Location aLocRight = LOC_UNKNOWN;
99 Location aLocLine = LOC_UNKNOWN;
100 int bDim = DIM_NOT_PART;
101 bool bIsHole = false;
102 Location bLocLeft = LOC_UNKNOWN;
103 Location bLocRight = LOC_UNKNOWN;
104 Location bLocLine = LOC_UNKNOWN;
105
106 std::string dimensionSymbol(int dim) const;
107 void locationString(uint8_t index, bool isForward, std::ostream& os) const;
108
109
110public:
111
112 static constexpr Location LOC_UNKNOWN = Location::NONE;
113
114 enum {
115 DIM_UNKNOWN = -1,
116 DIM_NOT_PART = -1,
117 DIM_LINE = 1,
118 DIM_BOUNDARY = 2,
119 DIM_COLLAPSE = 3
120 };
121
123 : aDim(DIM_NOT_PART)
124 , aIsHole(false)
125 , aLocLeft(LOC_UNKNOWN)
126 , aLocRight(LOC_UNKNOWN)
127 , aLocLine(LOC_UNKNOWN)
128 , bDim(DIM_NOT_PART)
129 , bIsHole(false)
130 , bLocLeft(LOC_UNKNOWN)
131 , bLocRight(LOC_UNKNOWN)
132 , bLocLine(LOC_UNKNOWN) {};
133
134 explicit OverlayLabel(uint8_t p_index)
135 : OverlayLabel()
136 {
137 initLine(p_index);
138 };
139
140 OverlayLabel(uint8_t p_index, Location p_locLeft, Location p_locRight, bool p_isHole)
141 : OverlayLabel()
142 {
143 initBoundary(p_index, p_locLeft, p_locRight, p_isHole);
144 };
145
146 int dimension(uint8_t index) const { return index == 0 ? aDim : bDim; };
147 void initBoundary(uint8_t index, Location locLeft, Location locRight, bool p_isHole);
148 void initCollapse(uint8_t index, bool p_isHole);
149 void initLine(uint8_t index);
150 void initNotPart(uint8_t index);
151
161 void setLocationLine(uint8_t index, Location loc);
162 void setLocationAll(uint8_t index, Location loc);
163 void setLocationCollapse(uint8_t index);
164
165 /*
166 * Tests whether at least one of the sources is a Line.
167 *
168 * @return true if at least one source is a line
169 */
170 bool isLine() const
171 {
172 return aDim == DIM_LINE || bDim == DIM_LINE;
173 };
174
175 bool isLine(uint8_t index) const
176 {
177 return index == 0 ? aDim == DIM_LINE : bDim == DIM_LINE;
178 };
179
180 bool isLinear(uint8_t index) const
181 {
182 if (index == 0) {
183 return aDim == DIM_LINE || aDim == DIM_COLLAPSE;
184 }
185 return bDim == DIM_LINE || bDim == DIM_COLLAPSE;
186 };
187
188 bool isKnown(uint8_t index) const
189 {
190 if (index == 0) {
191 return aDim != DIM_UNKNOWN;
192 }
193 return bDim != DIM_UNKNOWN;
194 };
195
196 bool isNotPart(uint8_t index) const
197 {
198 if (index == 0) {
199 return aDim == DIM_NOT_PART;
200 }
201 return bDim == DIM_NOT_PART;
202 };
203
204 bool isBoundaryEither() const
205 {
206 return aDim == DIM_BOUNDARY || bDim == DIM_BOUNDARY;
207 };
208
209 bool isBoundaryBoth() const
210 {
211 return aDim == DIM_BOUNDARY && bDim == DIM_BOUNDARY;
212 };
213
222 {
223 if (isLine()) return false;
224 return ! isBoundaryBoth();
225 };
226
231 bool isBoundaryTouch() const
232 {
233 return isBoundaryBoth() &&
234 getLocation(0, Position::RIGHT, true) != getLocation(1, Position::RIGHT, true);
235 };
236
237 bool isBoundary(uint8_t index) const
238 {
239 if (index == 0) {
240 return aDim == DIM_BOUNDARY;
241 }
242 return bDim == DIM_BOUNDARY;
243 };
244
245 bool isLineLocationUnknown(int index) const
246 {
247 if (index == 0) {
248 return aLocLine == LOC_UNKNOWN;
249 }
250 else {
251 return bLocLine == LOC_UNKNOWN;
252 }
253 };
254
260 {
261 if (aDim == DIM_BOUNDARY && bDim == DIM_NOT_PART) {
262 return true;
263 }
264
265 if (bDim == DIM_BOUNDARY && aDim == DIM_NOT_PART) {
266 return true;
267 }
268
269 return false;
270 };
271
277 bool isLineInArea(int8_t index) const
278 {
279 if (index == 0) {
280 return aLocLine == Location::INTERIOR;
281 }
282 return bLocLine == Location::INTERIOR;
283 };
284
285 bool isHole(uint8_t index) const
286 {
287 if (index == 0) {
288 return aIsHole;
289 }
290 else {
291 return bIsHole;
292 }
293 };
294
295 bool isCollapse(uint8_t index) const
296 {
297 return dimension(index) == DIM_COLLAPSE;
298 };
299
300 Location getLineLocation(uint8_t index) const
301 {
302 if (index == 0) {
303 return aLocLine;
304 }
305 else {
306 return bLocLine;
307 }
308 };
309
315 {
316 if (aDim == DIM_COLLAPSE && aLocLine == Location::INTERIOR)
317 return true;
318 if (bDim == DIM_COLLAPSE && bLocLine == Location::INTERIOR)
319 return true;
320
321 return false;
322 };
323
329
336 bool isLineInterior(uint8_t index) const
337 {
338 if (index == 0) {
339 return aLocLine == Location::INTERIOR;
340 }
341 return bLocLine == Location::INTERIOR;
342 };
343
356 uint8_t index,
357 int position,
358 bool isForward) const
359 {
360 if (isBoundary(index)) {
361 return getLocation(index, position, isForward);
362 }
363 return getLineLocation(index);
364 };
365
372 Location getLocation(uint8_t index) const {
373 if (index == 0) {
374 return aLocLine;
375 }
376 return bLocLine;
377 };
378
379 Location getLocation(uint8_t index, int position, bool isForward) const;
380
381 bool hasSides(uint8_t index) const {
382 if (index == 0) {
383 return aLocLeft != LOC_UNKNOWN
384 || aLocRight != LOC_UNKNOWN;
385 }
386 return bLocLeft != LOC_UNKNOWN
387 || bLocRight != LOC_UNKNOWN;
388 };
389
390 OverlayLabel copy() const
391 {
392 OverlayLabel lbl = *this;
393 return lbl;
394 };
395
396 friend std::ostream& operator<<(std::ostream& os, const OverlayLabel& ol);
397 void toString(bool isForward, std::ostream& os) const;
398
399
400};
401
402
403} // namespace geos.operation.overlayng
404} // namespace geos.operation
405} // namespace geos
A Position indicates the position of a Location relative to a graph component (Node,...
Definition: Position.h:37
Definition: OverlayLabel.h:90
void setLocationLine(uint8_t index, Location loc)
Location getLocation(uint8_t index) const
Definition: OverlayLabel.h:372
bool isLineInterior(uint8_t index) const
Definition: OverlayLabel.h:336
bool isBoundaryCollapse() const
Definition: OverlayLabel.h:221
bool isInteriorCollapse() const
Definition: OverlayLabel.h:314
Location getLocationBoundaryOrLine(uint8_t index, int position, bool isForward) const
Definition: OverlayLabel.h:355
bool isBoundaryTouch() const
Definition: OverlayLabel.h:231
bool isLineInArea(int8_t index) const
Definition: OverlayLabel.h:277
bool isBoundarySingleton() const
Definition: OverlayLabel.h:259
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