Skip to content

Commit

Permalink
Add boundary argument to CAPI for LargestEmptyCircle
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed May 7, 2020
1 parent a57d337 commit 099e74b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
4 changes: 2 additions & 2 deletions capi/geos_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ extern "C" {
}

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

Geometry*
Expand Down
4 changes: 2 additions & 2 deletions capi/geos_c.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ extern GEOSGeometry GEOS_DLL *GEOSMinimumRotatedRectangle_r(GEOSContextHandle_t
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);
extern GEOSGeometry GEOS_DLL *GEOSLargestEmptyCircle_r(GEOSContextHandle_t handle, const GEOSGeometry* g, const GEOSGeometry* boundary, 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
Expand Down Expand Up @@ -1632,7 +1632,7 @@ extern GEOSGeometry GEOS_DLL *GEOSMaximumInscribedCircle(const GEOSGeometry* g,
* 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);
extern GEOSGeometry GEOS_DLL *GEOSLargestEmptyCircle(const GEOSGeometry* g, const GEOSGeometry* boundary, 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
Expand Down
4 changes: 2 additions & 2 deletions capi/geos_ts_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,10 +1172,10 @@ extern "C" {
}

Geometry*
GEOSLargestEmptyCircle_r(GEOSContextHandle_t extHandle, const Geometry* g, double tolerance)
GEOSLargestEmptyCircle_r(GEOSContextHandle_t extHandle, const Geometry* g, const GEOSGeometry* boundary, double tolerance)
{
return execute(extHandle, [&]() {
geos::algorithm::construct::LargestEmptyCircle lec(g, tolerance);
geos::algorithm::construct::LargestEmptyCircle lec(g, boundary, tolerance);
auto g3 = lec.getRadiusLine();
g3->setSRID(g->getSRID());
return g3.release();
Expand Down
1 change: 1 addition & 0 deletions include/geos/algorithm/construct/LargestEmptyCircle.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class GEOS_DLL LargestEmptyCircle {
* @param p_tolerance the distance tolerance for computing the circle center point
*/
LargestEmptyCircle(const geom::Geometry* p_obstacles, double p_tolerance);
LargestEmptyCircle(const geom::Geometry* p_obstacles, const geom::Geometry* p_boundary, double p_tolerance);
~LargestEmptyCircle() = default;

/**
Expand Down
24 changes: 21 additions & 3 deletions src/algorithm/construct/LargestEmptyCircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,35 @@ namespace construct { // geos.algorithm.construct


LargestEmptyCircle::LargestEmptyCircle(const Geometry* p_obstacles, double p_tolerance)
: LargestEmptyCircle(p_obstacles, nullptr, p_tolerance)
{
}

LargestEmptyCircle::LargestEmptyCircle(const Geometry* p_obstacles, const Geometry* p_boundary, double p_tolerance)
: tolerance(p_tolerance)
, obstacles(p_obstacles)
, factory(p_obstacles->getFactory())
, boundary(p_obstacles->convexHull())
, obstacleDistance(p_obstacles)
, done(false)
{
if (p_obstacles->isEmpty()) {
if (!p_boundary)
{
boundary = p_obstacles->convexHull();
}
else
{
boundary = p_boundary->clone();
}

if (obstacles->isEmpty()) {
throw util::IllegalArgumentException("Empty obstacles geometry is not supported");
}
if (boundary->isEmpty()) {
throw util::IllegalArgumentException("Empty obstacles geometry is not supported");
}
if (!boundary->covers(obstacles)) {
throw util::IllegalArgumentException("Boundary geometry does not cover obstacles");
}

// if boundary does not enclose an area cannot create a ptLocator
if (boundary->getDimension() >= 2) {
Expand All @@ -61,7 +80,6 @@ LargestEmptyCircle::LargestEmptyCircle(const Geometry* p_obstacles, double p_tol
}
}


/* public static */
std::unique_ptr<Point>
LargestEmptyCircle::getCenter(const Geometry* p_obstacles, double p_tolerance)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/capi/GEOSMaximumInscribedCircleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void object::test<2>
{
geom1_ = GEOSGeomFromWKT("MULTIPOINT ((100 100), (100 200), (200 200), (200 100))");
ensure(nullptr != geom1_);
geom2_ = GEOSLargestEmptyCircle(geom1_, 0.001);
geom2_ = GEOSLargestEmptyCircle(geom1_, nullptr, 0.001);
ensure(nullptr != geom2_);

wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
Expand Down

0 comments on commit 099e74b

Please sign in to comment.