Skip to content

Commit 8c3167e

Browse files
authored
Add largest empty circle method to Geometry. (#78)
1 parent d517aa3 commit 8c3167e

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

doc/api/geom/geometry.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,10 @@ Common Geometry Methods
281281
Tests if this geometry is within the other geometry. This is the
282282
inverse of :func:`contains`.
283283

284+
.. function:: Geometry.getLargestEmptyCircle
284285

286+
:arg config: :`Object` tolerance property defaults to 1.0
287+
:returns: :class:`geom.Geometry`
285288

286-
287-
288-
289+
Get the largest empty circle in this Geometry.
289290

src/main/java/org/geoscript/js/geom/Geometry.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.List;
77
import java.util.Objects;
88

9+
import org.locationtech.jts.algorithm.construct.LargestEmptyCircle;
910
import org.locationtech.jts.algorithm.construct.MaximumInscribedCircle;
1011
import org.locationtech.jts.densify.Densifier;
1112
import org.geoscript.js.GeoObject;
@@ -370,6 +371,16 @@ public ScriptableObject createDelaunayTriangles(boolean isConforming) {
370371
return triangles;
371372
}
372373

374+
@JSFunction
375+
public Geometry getLargestEmptyCircle(NativeObject config) {
376+
double tolerance = getDouble(config.getOrDefault("tolerance", 1.0));
377+
LargestEmptyCircle algorithm = new LargestEmptyCircle(getGeometry(), tolerance);
378+
return (Geometry) GeometryWrapper.wrap(
379+
getParentScope(),
380+
algorithm.getCenter().buffer(algorithm.getRadiusLine().getLength())
381+
);
382+
}
383+
373384
@JSFunction
374385
public String getGeometryType() {
375386
return geometry.getGeometryType();

src/test/resources/org/geoscript/js/tests/geoscript/test_geom.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ exports["test: create random points"] = function() {
176176

177177
}
178178

179+
exports["test: largest empty circle"] = function() {
180+
181+
var geom = new GEOM.Polygon([[
182+
[-122.38855361938475, 47.5805786829606], [-122.38636493682861, 47.5783206388176],
183+
[-122.38700866699219, 47.5750491969984], [-122.38177299499512, 47.57502024527343],
184+
[-122.38481998443604, 47.5780600889959], [-122.38151550292969, 47.5805786829606],
185+
[-122.38855361938475, 47.5805786829606]
186+
]]);
187+
ASSERT.ok(geom instanceof GEOM.Polygon);
188+
var circle = geom.getLargestEmptyCircle({tolerance: 1.0});
189+
ASSERT.ok(circle instanceof GEOM.Polygon);
190+
191+
}
192+
179193
exports["test: create conforming delaunay triangles"] = function() {
180194

181195
var geom = GEOM.Point([1,1]).buffer(50)

0 commit comments

Comments
 (0)