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