GEOS 3.13.1
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
33namespace geos {
34namespace geom {
35class Coordinate;
36class Envelope;
37class Geometry;
38class GeometryFactory;
39class LineString;
40class Point;
41}
42}
43
46
47namespace geos {
48namespace algorithm { // geos::algorithm
49namespace construct { // geos::algorithm::construct
50
56class GEOS_DLL MaximumInscribedCircle {
57
58public:
59
60 MaximumInscribedCircle(const geom::Geometry* polygonal, double tolerance);
61 ~MaximumInscribedCircle() = default;
62
69 std::unique_ptr<geom::Point> getCenter();
70
81 std::unique_ptr<geom::Point> getRadiusPoint();
82
88 std::unique_ptr<geom::LineString> getRadiusLine();
89
98 static std::unique_ptr<geom::Point> getCenter(const geom::Geometry* polygonal, double tolerance);
99
108 static std::unique_ptr<geom::LineString> getRadiusLine(const geom::Geometry* polygonal, double tolerance);
109
124 static std::size_t computeMaximumIterations(const geom::Geometry* geom, double toleranceDist);
125
126private:
127
128 /* private members */
129 const geom::Geometry* inputGeom;
130 std::unique_ptr<geom::Geometry> inputGeomBoundary;
131 double tolerance;
132 IndexedFacetDistance indexedDistance;
134 const geom::GeometryFactory* factory;
135 bool done;
136 geom::CoordinateXY centerPt;
137 geom::CoordinateXY radiusPt;
138
139 /* private methods */
140 double distanceToBoundary(const geom::Point& pt);
141 double distanceToBoundary(double x, double y);
142 void compute();
143
144 /* private class */
145 class Cell {
146 private:
147 static constexpr double SQRT2 = 1.4142135623730951;
148 double x;
149 double y;
150 double hSize;
151 double distance;
152 double maxDist;
153
154 public:
155 Cell(double p_x, double p_y, double p_hSize, double p_distanceToBoundary)
156 : x(p_x)
157 , y(p_y)
158 , hSize(p_hSize)
159 , distance(p_distanceToBoundary)
160 , maxDist(p_distanceToBoundary+(p_hSize*SQRT2))
161 {};
162
163 geom::Envelope getEnvelope() const
164 {
165 geom::Envelope env(x-hSize, x+hSize, y-hSize, y+hSize);
166 return env;
167 }
168
169 double getMaxDistance() const
170 {
171 return maxDist;
172 }
173 double getDistance() const
174 {
175 return distance;
176 }
177 double getHSize() const
178 {
179 return hSize;
180 }
181 double getX() const
182 {
183 return x;
184 }
185 double getY() const
186 {
187 return y;
188 }
189
190 bool operator< (const Cell& rhs) const
191 {
192 return maxDist < rhs.maxDist;
193 }
194
195 bool operator> (const Cell& rhs) const
196 {
197 return maxDist > rhs.maxDist;
198 }
199
200 bool operator==(const Cell& rhs) const
201 {
202 return maxDist == rhs.maxDist;
203 }
204
210 using CellQueue = std::priority_queue<Cell>;
211 };
212
213 void createInitialGrid(const geom::Envelope* env, Cell::CellQueue& cellQueue);
214 Cell createInteriorPointCell(const geom::Geometry* geom);
215
216};
217
218
219} // geos::algorithm::construct
220} // geos::algorithm
221} // geos
Definition MaximumInscribedCircle.h:56
std::unique_ptr< geom::Point > getCenter()
static std::unique_ptr< geom::Point > getCenter(const geom::Geometry *polygonal, double tolerance)
std::unique_ptr< geom::LineString > getRadiusLine()
static std::size_t computeMaximumIterations(const geom::Geometry *geom, double toleranceDist)
std::unique_ptr< geom::Point > getRadiusPoint()
static std::unique_ptr< geom::LineString > getRadiusLine(const geom::Geometry *polygonal, double tolerance)
Determines the location of Coordinates relative to an areal geometry, using indexing for efficiency.
Definition IndexedPointInAreaLocator.h:54
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
Definition Point.h:61
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 geos.h:39