GEOS  3.14.0dev
MaximumInscribedCircle.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  * Last port: algorithm/construct/MaximumInscribedCircle.java
16  * https://github.com/locationtech/jts/commit/98274a7ea9b40651e9de6323dc10fb2cac17a245
17  *
18  **********************************************************************/
19 
20 #pragma once
21 
22 #include <geos/geom/Coordinate.h>
23 #include <geos/geom/Point.h>
24 #include <geos/geom/Envelope.h>
25 #include <geos/algorithm/locate/IndexedPointInAreaLocator.h>
26 #include <geos/operation/distance/IndexedFacetDistance.h>
27 
28 #include <memory>
29 #include <queue>
30 
31 
32 
33 namespace geos {
34 namespace geom {
35 class Coordinate;
36 class Envelope;
37 class Geometry;
38 class GeometryFactory;
39 class LineString;
40 class Point;
41 }
42 }
43 
44 namespace geos {
45 namespace algorithm { // geos::algorithm
46 namespace construct { // geos::algorithm::construct
47 
53 class GEOS_DLL MaximumInscribedCircle {
56 
57 public:
58 
59  MaximumInscribedCircle(const geom::Geometry* polygonal, double tolerance);
60  ~MaximumInscribedCircle() = default;
61 
68  std::unique_ptr<geom::Point> getCenter();
69 
80  std::unique_ptr<geom::Point> getRadiusPoint();
81 
87  std::unique_ptr<geom::LineString> getRadiusLine();
88 
97  static std::unique_ptr<geom::Point> getCenter(const geom::Geometry* polygonal, double tolerance);
98 
107  static std::unique_ptr<geom::LineString> getRadiusLine(const geom::Geometry* polygonal, double tolerance);
108 
123  static std::size_t computeMaximumIterations(const geom::Geometry* geom, double toleranceDist);
124 
125 private:
126 
127  /* private members */
128  const geom::Geometry* inputGeom;
129  std::unique_ptr<geom::Geometry> inputGeomBoundary;
130  double tolerance;
131  IndexedFacetDistance indexedDistance;
132  IndexedPointInAreaLocator ptLocator;
133  const geom::GeometryFactory* factory;
134  bool done;
135  geom::CoordinateXY centerPt;
136  geom::CoordinateXY radiusPt;
137 
138  /* private methods */
139  double distanceToBoundary(const geom::Coordinate& c);
140  double distanceToBoundary(double x, double y);
141  void compute();
142 
143  /* private class */
144  class Cell {
145  private:
146  static constexpr double SQRT2 = 1.4142135623730951;
147  double x;
148  double y;
149  double hSize;
150  double distance;
151  double maxDist;
152 
153  public:
154  Cell(double p_x, double p_y, double p_hSize, double p_distanceToBoundary)
155  : x(p_x)
156  , y(p_y)
157  , hSize(p_hSize)
158  , distance(p_distanceToBoundary)
159  , maxDist(p_distanceToBoundary+(p_hSize*SQRT2))
160  {};
161 
162  geom::Envelope getEnvelope() const
163  {
164  geom::Envelope env(x-hSize, x+hSize, y-hSize, y+hSize);
165  return env;
166  }
167 
168  double getMaxDistance() const
169  {
170  return maxDist;
171  }
172  double getDistance() const
173  {
174  return distance;
175  }
176  double getHSize() const
177  {
178  return hSize;
179  }
180  double getX() const
181  {
182  return x;
183  }
184  double getY() const
185  {
186  return y;
187  }
188 
189  bool operator< (const Cell& rhs) const
190  {
191  return maxDist < rhs.maxDist;
192  }
193 
194  bool operator> (const Cell& rhs) const
195  {
196  return maxDist > rhs.maxDist;
197  }
198 
199  bool operator==(const Cell& rhs) const
200  {
201  return maxDist == rhs.maxDist;
202  }
203 
209  using CellQueue = std::priority_queue<Cell>;
210  };
211 
212  void createInitialGrid(const geom::Envelope* env, Cell::CellQueue& cellQueue);
213  Cell createInteriorPointCell(const geom::Geometry* geom);
214 
215 };
216 
217 
218 } // geos::algorithm::construct
219 } // geos::algorithm
220 } // geos
Definition: MaximumInscribedCircle.h:53
std::unique_ptr< geom::LineString > getRadiusLine()
static std::unique_ptr< geom::Point > getCenter(const geom::Geometry *polygonal, double tolerance)
static std::unique_ptr< geom::LineString > getRadiusLine(const geom::Geometry *polygonal, double tolerance)
std::unique_ptr< geom::Point > getCenter()
std::unique_ptr< geom::Point > getRadiusPoint()
static std::size_t computeMaximumIterations(const geom::Geometry *geom, double toleranceDist)
Determines the location of Coordinates relative to an areal geometry, using indexing for efficiency.
Definition: IndexedPointInAreaLocator.h:54
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:217
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:70
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:197
Computes the distance between the facets (segments and vertices) of two Geometrys using a Branch-and-...
Definition: IndexedFacetDistance.h:46
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25