GEOS  3.13.0dev
TopologyLocation.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/TopologyLocation.java r428 (JTS-1.12+)
17  *
18  **********************************************************************/
19 
20 #pragma once
21 
22 #include <geos/export.h>
23 #include <geos/geom/Location.h>
24 #include <geos/geom/Position.h>
25 
26 #include <vector>
27 #include <array>
28 #include <string>
29 #include <cassert>
30 #include <cstdint>
31 
32 #ifdef _MSC_VER
33 #pragma warning(push)
34 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
35 #endif
36 
39 
40 namespace geos {
41 namespace geomgraph { // geos.geomgraph
42 
63 class GEOS_DLL TopologyLocation {
64 
65 public:
66 
67  friend std::ostream& operator<< (std::ostream&, const TopologyLocation&);
68 
69  TopologyLocation() = default;
70 
82  TopologyLocation(Location on, Location left, Location right)
83  : locationSize(3)
84  {
85  location[Position::ON] = on;
86  location[Position::LEFT] = left;
87  location[Position::RIGHT] = right;
88  }
89 
90  TopologyLocation(Location on)
91  : locationSize(1)
92  {
93  location.fill(Location::NONE);
94  location[Position::ON] = on;
95  };
96 
97  TopologyLocation(const TopologyLocation& gl)
98  : location(gl.location)
99  , locationSize(gl.locationSize)
100  {};
101 
102  TopologyLocation& operator= (const TopologyLocation& gl)
103  {
104  location = gl.location;
105  locationSize = gl.locationSize;
106  return *this;
107  };
108 
109  Location get(std::size_t posIndex) const
110  {
111  // should be an assert() instead ?
112  if(posIndex < locationSize) {
113  return location[posIndex];
114  }
115  return Location::NONE;
116  };
117 
121  bool isNull() const
122  {
123  for(std::size_t i = 0; i < locationSize; ++i) {
124  if(location[i] != Location::NONE) {
125  return false;
126  }
127  }
128  return true;
129  };
130 
134  bool isAnyNull() const
135  {
136  for(std::size_t i = 0; i < locationSize; ++i) {
137  if(location[i] == Location::NONE) {
138  return true;
139  }
140  }
141  return false;
142  };
143 
144  bool isEqualOnSide(const TopologyLocation& le, uint32_t locIndex) const
145  {
146  return location[locIndex] == le.location[locIndex];
147  };
148 
149  bool isArea() const
150  {
151  return locationSize > 1;
152  };
153 
154  bool isLine() const
155  {
156  return locationSize == 1;
157  };
158 
159  void flip()
160  {
161  if(locationSize <= 1) {
162  return;
163  }
164  std::swap(location[Position::LEFT], location[Position::RIGHT]);
165  };
166 
167  void setAllLocations(Location locValue)
168  {
169  location.fill(locValue);
170  };
171 
172 
173  void setAllLocationsIfNull(Location locValue)
174  {
175  for(std::size_t i = 0; i < locationSize; ++i) {
176  if(location[i] == Location::NONE) {
177  location[i] = locValue;
178  }
179  }
180  };
181 
182  void setLocation(std::size_t locIndex, Location locValue)
183  {
184  location[locIndex] = locValue;
185  };
186 
187  void setLocation(Location locValue)
188  {
189  setLocation(Position::ON, locValue);
190  };
191 
192  const std::array<Location, 3>& getLocations() const
193  {
194  return location;
195  };
196 
197  void setLocations(Location on, Location left, Location right)
198  {
199  assert(locationSize >= 3);
200  location[Position::ON] = on;
201  location[Position::LEFT] = left;
202  location[Position::RIGHT] = right;
203  };
204 
205  bool allPositionsEqual(Location loc) const
206  {
207  for(std::size_t i = 0; i < locationSize; ++i) {
208  if(location[i] != loc) {
209  return false;
210  }
211  }
212  return true;
213  };
214 
219  void merge(const TopologyLocation& gl);
220 
221  std::string toString() const;
222 
223 
224 private:
225 
226  std::array<geom::Location, 3> location;
227  std::uint8_t locationSize;
228 
229 };
230 
231 std::ostream& operator<< (std::ostream&, const TopologyLocation&);
232 
233 } // namespace geos.geomgraph
234 } // namespace geos
235 
236 #ifdef _MSC_VER
237 #pragma warning(pop)
238 #endif
A Position indicates the position of a Location relative to a graph component (Node,...
Definition: Position.h:37
A TopologyLocation is the labelling of a GraphComponent's topological relationship to a single Geomet...
Definition: TopologyLocation.h:63
bool isNull() const
Definition: TopologyLocation.h:121
TopologyLocation(Location on, Location left, Location right)
Constructs a TopologyLocation specifying how points on, to the left of, and to the right of some Grap...
Definition: TopologyLocation.h:82
void merge(const TopologyLocation &gl)
merge updates only the UNDEF attributes of this object with the attributes of another.
bool isAnyNull() const
Definition: TopologyLocation.h:134
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