Skip to content

Commit

Permalink
Port MaximumInscribedCircle and LargestEmptyCircle
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Apr 28, 2020
1 parent a0fc245 commit 0909042
Show file tree
Hide file tree
Showing 30 changed files with 1,859 additions and 73 deletions.
39 changes: 5 additions & 34 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,10 @@ stages:
matrix:
#Disabled until MSVC 16.4 is released
#(see https://developercommunity.visualstudio.com/content/problem/726778/this-snippet-compiles-totally-fine-on-godbolt-msvc.html?childToView=744771#comment-744771)
#VS 2019 C++20 Strict:
# TOOLSET: msvc-14.2
# CXXSTD: 20
# CXXFLAGS: -permissive-
# VM_IMAGE: 'windows-2019'
VS 2019 C++20 Strict:
TOOLSET: msvc-14.2
CXXSTD: 20
VM_IMAGE: 'windows-2019'
VS 2017 C++17:
TOOLSET: msvc-14.1
CXXSTD: 17
Expand All @@ -171,10 +170,6 @@ stages:
TOOLSET: msvc-14.1
CXXSTD: 14 # default
VM_IMAGE: 'vs2017-win2016'
VS 2015 C++14:
TOOLSET: msvc-14.0
CXXSTD: 14 # default
VM_IMAGE: 'vs2015-win2012r2'
pool:
vmImage: $(VM_IMAGE)
steps:
Expand Down Expand Up @@ -202,7 +197,7 @@ stages:
- job: 'macOS'
pool:
vmImage: 'macOS-10.13'
vmImage: 'macOS-10.14'
strategy:
matrix:
Xcode 10.1:
Expand All @@ -215,30 +210,6 @@ stages:
Xcode 9.4.1:
CXXSTD: 11, 14, 17
XCODE_APP: /Applications/Xcode_9.4.1.app
Xcode 9.4:
CXXSTD: 11, 14, 17
XCODE_APP: /Applications/Xcode_9.4.app
Xcode 9.3.1:
CXXSTD: 11, 14, 17
XCODE_APP: /Applications/Xcode_9.3.1.app
Xcode 9.3:
CXXSTD: 11, 14
XCODE_APP: /Applications/Xcode_9.3.app
Xcode 9.2:
CXXSTD: 11, 14
XCODE_APP: /Applications/Xcode_9.2.app
Xcode 9.1:
CXXSTD: 11
XCODE_APP: /Applications/Xcode_9.1.app
Xcode 9.0.1:
CXXSTD: 11
XCODE_APP: /Applications/Xcode_9.0.1.app
Xcode 9.0:
CXXSTD: 11
XCODE_APP: /Applications/Xcode_9.app
Xcode 8.3.3:
CXXSTD: 11
XCODE_APP: /Applications/Xcode_8.3.3.app
steps:
- script: |
set -e
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Makefile
.vimrc
.dirstamp
.tm_properties
*~
*.o
*.orig
*.lo
Expand Down
6 changes: 3 additions & 3 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ Changes in 3.9.0
2020-xx-xx

- New things:
-
- MaximumInscribedCircle and LargestEmptyCircle (JTS-530, Paul Ramsey)

- Improvements:
- Stack allocate segments in OverlapUnion (Paul Ramsey)
- Improve performance of GEOSisValid (Dan Baston)
- Update geos-config tool for consistency
and escape paths (https://git.osgeo.org/gitea/geos/geos/pulls/99)
- Update geos-config tool for consistency
and escape paths (https://git.osgeo.org/gitea/geos/geos/pulls/99)
changes mostly affect CMake MSVC builds (#1015, Mike Taves)
- Testing on Rasberry Pi 32-bit (berrie) (#1017, Bruce Rindahl, Regina Obe)
- Replace ttmath with JTS DD double-double implementation (Paul Ramsey)
Expand Down
12 changes: 12 additions & 0 deletions capi/geos_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,18 @@ extern "C" {
return GEOSMinimumRotatedRectangle_r(handle, g);
}

Geometry*
GEOSMaximumInscribedCircle(const Geometry* g, double tolerance)
{
return GEOSMaximumInscribedCircle_r(handle, g, tolerance);
}

Geometry*
GEOSLargestEmptyCircle(const Geometry* g, double tolerance)
{
return GEOSLargestEmptyCircle_r(handle, g, tolerance);
}

Geometry*
GEOSMinimumWidth(const Geometry* g)
{
Expand Down
35 changes: 35 additions & 0 deletions capi/geos_c.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ extern GEOSGeometry GEOS_DLL *GEOSConvexHull_r(GEOSContextHandle_t handle,
extern GEOSGeometry GEOS_DLL *GEOSMinimumRotatedRectangle_r(GEOSContextHandle_t handle,
const GEOSGeometry* g);

extern GEOSGeometry GEOS_DLL *GEOSMaximumInscribedCircle_r(GEOSContextHandle_t handle, const GEOSGeometry* g, double tolerance);
extern GEOSGeometry GEOS_DLL *GEOSLargestEmptyCircle_r(GEOSContextHandle_t handle, const GEOSGeometry* g, double tolerance);

/* Returns a LINESTRING geometry which represents the minimum diameter of the geometry.
* The minimum diameter is defined to be the width of the smallest band that
* contains the geometry, where a band is a strip of the plane defined
Expand Down Expand Up @@ -1599,6 +1602,38 @@ extern GEOSGeometry GEOS_DLL *GEOSConvexHull(const GEOSGeometry* g);
*/
extern GEOSGeometry GEOS_DLL *GEOSMinimumRotatedRectangle(const GEOSGeometry* g);

/* Constructs the Maximum Inscribed Circle for a polygonal geometry, up to a specified tolerance.
* The Maximum Inscribed Circle is determined by a point in the interior of the area
* which has the farthest distance from the area boundary, along with a boundary point at that distance.
* In the context of geography the center of the Maximum Inscribed Circle is known as the
* Pole of Inaccessibility. A cartographic use case is to determine a suitable point
* to place a map label within a polygon.
* The radius length of the Maximum Inscribed Circle is a measure of how "narrow" a polygon is. It is the
* distance at which the negative buffer becomes empty.
* The class supports polygons with holes and multipolygons.
* The implementation uses a successive-approximation technique over a grid of square cells covering the area geometry.
* The grid is refined using a branch-and-bound algorithm. Point containment and distance are computed in a performant
* way by using spatial indexes.
* Returns a two-point linestring, with one point at the center of the inscribed circle and the other
* on the boundary of the inscribed circle.
*/
extern GEOSGeometry GEOS_DLL *GEOSMaximumInscribedCircle(const GEOSGeometry* g, double tolerance);

/* Constructs the Largest Empty Circle for a set of obstacle geometries, up to a
* specified tolerance. The obstacles are point and line geometries.
* The Largest Empty Circle is the largest circle which has its center in the convex hull of the
* obstacles (the boundary), and whose interior does not intersect with any obstacle.
* The circle center is the point in the interior of the boundary which has the farthest distance from
* the obstacles (up to tolerance). The circle is determined by the center point and a point lying on an
* obstacle indicating the circle radius.
* The implementation uses a successive-approximation technique over a grid of square cells covering the obstacles and boundary.
* The grid is refined using a branch-and-bound algorithm. Point containment and distance are computed in a performant
* way by using spatial indexes.
* Returns a two-point linestring, with one point at the center of the inscribed circle and the other
* on the boundary of the inscribed circle.
*/
extern GEOSGeometry GEOS_DLL *GEOSLargestEmptyCircle(const GEOSGeometry* g, double tolerance);

/* Returns a LINESTRING geometry which represents the minimum diameter of the geometry.
* The minimum diameter is defined to be the width of the smallest band that
* contains the geometry, where a band is a strip of the plane defined
Expand Down
24 changes: 24 additions & 0 deletions capi/geos_ts_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include <geos/algorithm/MinimumBoundingCircle.h>
#include <geos/algorithm/MinimumDiameter.h>
#include <geos/algorithm/Orientation.h>
#include <geos/algorithm/construct/MaximumInscribedCircle.h>
#include <geos/algorithm/construct/LargestEmptyCircle.h>
#include <geos/algorithm/distance/DiscreteHausdorffDistance.h>
#include <geos/algorithm/distance/DiscreteFrechetDistance.h>
#include <geos/simplify/DouglasPeuckerSimplifier.h>
Expand Down Expand Up @@ -1158,6 +1160,28 @@ extern "C" {
});
}

Geometry*
GEOSMaximumInscribedCircle_r(GEOSContextHandle_t extHandle, const Geometry* g, double tolerance)
{
return execute(extHandle, [&]() {
geos::algorithm::construct::MaximumInscribedCircle mic(g, tolerance);
auto g3 = mic.getRadiusLine();
g3->setSRID(g->getSRID());
return g3.release();
});
}

Geometry*
GEOSLargestEmptyCircle_r(GEOSContextHandle_t extHandle, const Geometry* g, double tolerance)
{
return execute(extHandle, [&]() {
geos::algorithm::construct::LargestEmptyCircle lec(g, tolerance);
auto g3 = lec.getRadiusLine();
g3->setSRID(g->getSRID());
return g3.release();
});
}

Geometry*
GEOSMinimumWidth_r(GEOSContextHandle_t extHandle, const Geometry* g)
{
Expand Down
4 changes: 3 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ AC_OUTPUT([
macros/Makefile
src/Makefile
src/algorithm/Makefile
src/algorithm/locate/Makefile
src/algorithm/construct/Makefile
src/algorithm/distance/Makefile
src/algorithm/locate/Makefile
src/geom/Makefile
src/geom/prep/Makefile
src/geom/util/Makefile
Expand All @@ -376,6 +377,7 @@ AC_OUTPUT([
include/geos/algorithm/Makefile
include/geos/algorithm/locate/Makefile
include/geos/algorithm/distance/Makefile
include/geos/algorithm/construct/Makefile
include/geos/geom/Makefile
include/geos/geom/prep/Makefile
include/geos/geom/util/Makefile
Expand Down
3 changes: 2 additions & 1 deletion include/geos/algorithm/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#
SUBDIRS = \
locate \
distance
distance \
construct

EXTRA_DIST =

Expand Down
Loading

0 comments on commit 0909042

Please sign in to comment.