GEOS  3.13.0dev
Depth.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/Depth.java rev. 1.4 (JTS-1.10)
17  *
18  **********************************************************************/
19 
20 
21 #pragma once
22 
23 #include <geos/export.h>
24 #include <geos/geom/Location.h>
25 #include <geos/geom/Position.h>
26 #include <string>
27 #include <cstdint>
28 
29 // Forward declarations
30 namespace geos {
31 namespace geomgraph {
32 class Label;
33 }
34 }
35 
36 namespace geos {
37 namespace geomgraph { // geos.geomgraph
38 
41 class GEOS_DLL Depth {
42 
43 private:
44 
45  static constexpr int NULL_VALUE = -1; // Replaces NULL
46 
47  int depth[2][3];
48 
49 
50 public:
51 
52  static int depthAtLocation(geom::Location location)
53  {
54  if(location == geom::Location::EXTERIOR) {
55  return 0;
56  }
57  if(location == geom::Location::INTERIOR) {
58  return 1;
59  }
60  return NULL_VALUE;
61  };
62 
63 
64  Depth()
65  {
66  // initialize depth array to a sentinel value
67  for(std::size_t i = 0; i < 2; i++) {
68  for(std::size_t j = 0; j < 3; j++) {
69  depth[i][j] = NULL_VALUE;
70  }
71  }
72  };
73 
74  virtual ~Depth() = default; // FIXME: shouldn't be virtual!
75 
76  int getDepth(int geomIndex, int posIndex) const
77  {
78  return depth[geomIndex][posIndex];
79  };
80 
81  void setDepth(int geomIndex, int posIndex, int depthValue)
82  {
83  depth[geomIndex][posIndex] = depthValue;
84  };
85 
86  geom::Location getLocation(int geomIndex, int posIndex) const
87  {
88  if(depth[geomIndex][posIndex] <= 0) {
90  }
92  };
93 
94  void add(int geomIndex, int posIndex, geom::Location location)
95  {
96  if(location == geom::Location::INTERIOR) {
97  depth[geomIndex][posIndex]++;
98  }
99  };
100 
104  bool isNull() const
105  {
106  for(std::size_t i = 0; i < 2; i++) {
107  for(std::size_t j = 0; j < 3; j++) {
108  if(depth[i][j] != NULL_VALUE) {
109  return false;
110  }
111  }
112  }
113  return true;
114  };
115 
116  bool isNull(uint8_t geomIndex) const
117  {
118  return depth[geomIndex][1] == NULL_VALUE;
119  };
120 
121  bool isNull(uint8_t geomIndex, uint8_t posIndex) const
122  {
123  return depth[geomIndex][posIndex] == NULL_VALUE;
124  };
125 
126  int getDelta(int geomIndex) const
127  {
128  return depth[geomIndex][geom::Position::RIGHT] - depth[geomIndex][geom::Position::LEFT];
129  };
130 
131  void normalize();
132 
133  void add(const Label& lbl);
134 
135  std::string toString() const;
136 
137 
138 };
139 
140 
141 } // namespace geos.geomgraph
142 } // namespace geos
143 
@ LEFT
An indicator that a Location is to the left of a GraphComponent.
Definition: Position.h:50
@ RIGHT
An indicator that a Location is to the right of a GraphComponent.
Definition: Position.h:56
A Depth object records the topological depth of the sides of an Edge for up to two Geometries.
Definition: Depth.h:41
bool isNull() const
Definition: Depth.h:104
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition: Label.h:57
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