GEOS  3.14.0dev
Label.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/Label.java r428 (JTS-1.12+)
17  *
18  **********************************************************************/
19 
20 
21 #pragma once
22 
23 #include <geos/export.h>
24 #include <geos/geom/Location.h>
25 #include <geos/geomgraph/TopologyLocation.h>
26 
27 #include <iosfwd> // for operator<<
28 #include <cassert>
29 
30 namespace geos {
31 namespace geomgraph { // geos.geomgraph
32 
57 class GEOS_DLL Label final {
59 
60 public:
61 
62  friend std::ostream& operator<< (std::ostream&, const Label&);
63 
69  static Label toLineLabel(const Label& label)
70  {
71  Label lineLabel(geom::Location::NONE);
72  for(uint32_t i = 0; i < 2; i++) {
73  lineLabel.setLocation(i, label.getLocation(i));
74  }
75  return lineLabel;
76  };
77 
82  : elt{TopologyLocation(onLoc)
83  , TopologyLocation(onLoc)}
84  {};
85 
93  Label(uint32_t geomIndex, geom::Location onLoc)
94  : elt{TopologyLocation(geom::Location::NONE)
95  , TopologyLocation(geom::Location::NONE)}
96  {
97  assert(geomIndex < 2);
98  elt[geomIndex].setLocation(onLoc);
99  };
100 
107  : elt {TopologyLocation(onLoc, leftLoc, rightLoc)
108  , TopologyLocation(onLoc, leftLoc, rightLoc)}
109  {};
110 
112  Label(const Label& l)
113  : elt{TopologyLocation(l.elt[0])
114  , TopologyLocation(l.elt[1])}
115  {};
116 
123  : elt{TopologyLocation(geom::Location::NONE)
124  , TopologyLocation(geom::Location::NONE)}
125  {};
126 
133  Label(uint32_t geomIndex, geom::Location onLoc, geom::Location leftLoc, geom::Location rightLoc)
134  {
137  elt[geomIndex].setLocations(onLoc, leftLoc, rightLoc);
138  };
139 
140  Label&
141  operator=(const Label& l)
142  {
143  elt[0] = TopologyLocation(l.elt[0]);
144  elt[1] = TopologyLocation(l.elt[1]);
145  return *this;
146  };
147 
148  void flip()
149  {
150  elt[0].flip();
151  elt[1].flip();
152  };
153 
160  void merge(const Label& lbl)
161  {
162  for(int i = 0; i < 2; i++) {
163  elt[i].merge(lbl.elt[i]);
164  }
165  };
166 
167  int getGeometryCount() const
168  {
169  int count = 0;
170  if(!elt[0].isNull()) {
171  count++;
172  }
173  if(!elt[1].isNull()) {
174  count++;
175  }
176  return count;
177  };
178 
179  geom::Location getLocation(uint32_t geomIndex, uint32_t posIndex) const
180  {
181  assert(geomIndex < 2);
182  return elt[geomIndex].get(posIndex);
183  };
184 
185  geom::Location getLocation(uint32_t geomIndex) const
186  {
187  assert(geomIndex < 2);
188  return elt[geomIndex].get(Position::ON);
189  };
190 
191  void setLocation(uint32_t geomIndex, uint32_t posIndex, geom::Location location)
192  {
193  assert(geomIndex < 2);
194  elt[geomIndex].setLocation(posIndex, location);
195  };
196 
197  void setLocation(uint32_t geomIndex, geom::Location location)
198  {
199  assert(geomIndex < 2);
200  elt[geomIndex].setLocation(Position::ON, location);
201  };
202 
203  void setAllLocations(uint32_t geomIndex, geom::Location location)
204  {
205  assert(geomIndex < 2);
206  elt[geomIndex].setAllLocations(location);
207  };
208 
209  void setAllLocationsIfNull(uint32_t geomIndex, geom::Location location)
210  {
211  assert(geomIndex < 2);
212  elt[geomIndex].setAllLocationsIfNull(location);
213  };
214 
215  void setAllLocationsIfNull(geom::Location location)
216  {
217  setAllLocationsIfNull(0, location);
218  setAllLocationsIfNull(1, location);
219  };
220 
221  bool isNull(uint32_t geomIndex) const
222  {
223  assert(geomIndex < 2);
224  return elt[geomIndex].isNull();
225  };
226 
227  bool isNull() const
228  {
229  return elt[0].isNull() && elt[1].isNull();
230  };
231 
232  bool isAnyNull(uint32_t geomIndex) const
233  {
234  assert(geomIndex < 2);
235  return elt[geomIndex].isAnyNull();
236  };
237 
238  bool isArea() const
239  {
240  return elt[0].isArea() || elt[1].isArea();
241  };
242 
243  bool isArea(uint32_t geomIndex) const
244  {
245  assert(geomIndex < 2);
246  return elt[geomIndex].isArea();
247  };
248 
249  bool isLine(uint32_t geomIndex) const
250  {
251  assert(geomIndex < 2);
252  return elt[geomIndex].isLine();
253  };
254 
255  bool isEqualOnSide(const Label& lbl, uint32_t side) const
256  {
257  return elt[0].isEqualOnSide(lbl.elt[0], side)
258  && elt[1].isEqualOnSide(lbl.elt[1], side);
259  };
260 
261  bool allPositionsEqual(uint32_t geomIndex, geom::Location loc) const
262  {
263  assert(geomIndex < 2);
264  return elt[geomIndex].allPositionsEqual(loc);
265  };
266 
270  void toLine(uint32_t geomIndex)
271  {
272  assert(geomIndex < 2);
273  if(elt[geomIndex].isArea()) {
274  elt[geomIndex] = TopologyLocation(elt[geomIndex].getLocations()[0]);
275  }
276  };
277 
278  std::string toString() const;
279 
280 private:
281 
282  TopologyLocation elt[2];
283 
284 };
285 
286 std::ostream& operator<< (std::ostream&, const Label&);
287 
288 } // namespace geos.geomgraph
289 } // namespace geos
290 
291 
A Position indicates the position of a Location relative to a graph component (Node,...
Definition: Position.h:37
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition: Label.h:57
Label(geom::Location onLoc)
Construct a Label with a single location for both Geometries.
Definition: Label.h:81
Label(geom::Location onLoc, geom::Location leftLoc, geom::Location rightLoc)
Construct a Label with On, Left and Right locations for both Geometries.
Definition: Label.h:106
void merge(const Label &lbl)
Merge this label with another one.
Definition: Label.h:160
Label(uint32_t geomIndex, geom::Location onLoc)
Construct a Label with the location specified for the given Geometry.
Definition: Label.h:93
Label()
Initialize both locations to Location::NONE.
Definition: Label.h:122
static Label toLineLabel(const Label &label)
Converts a Label to a Line label (that is, one with no side Locations)
Definition: Label.h:69
Label(const Label &l)
Copy ctor.
Definition: Label.h:112
Label(uint32_t geomIndex, geom::Location onLoc, geom::Location leftLoc, geom::Location rightLoc)
Construct a Label with On, Left and Right locations for the given Geometries. Initialize the location...
Definition: Label.h:133
void toLine(uint32_t geomIndex)
Converts one GeometryLocation to a Line location.
Definition: Label.h:270
A TopologyLocation is the labelling of a GraphComponent's topological relationship to a single Geomet...
Definition: TopologyLocation.h:60
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