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