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