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