diff --git a/doc/api/geom/geometry.rst b/doc/api/geom/geometry.rst index a1922f7..f20ed51 100644 --- a/doc/api/geom/geometry.rst +++ b/doc/api/geom/geometry.rst @@ -266,6 +266,13 @@ Common Geometry Methods :attr:`projection` of this geometry must be set before calling this method. Returns a new geometry. +.. function:: Geometry.getMaximumInscribedCircle + + :arg config: :`Object` tolerance property defaults to 1.0 + :returns: :class:`geom.Geometry` + + Get the maximum inscribed circle for this Geometry. + .. function:: Geometry.within :arg other: :class:`geom.Geometry` diff --git a/src/main/java/org/geoscript/js/geom/Geometry.java b/src/main/java/org/geoscript/js/geom/Geometry.java index 35bb87e..bad3cd4 100644 --- a/src/main/java/org/geoscript/js/geom/Geometry.java +++ b/src/main/java/org/geoscript/js/geom/Geometry.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Objects; +import org.locationtech.jts.algorithm.construct.MaximumInscribedCircle; import org.locationtech.jts.densify.Densifier; import org.geoscript.js.GeoObject; import org.geoscript.js.proj.Projection; @@ -341,6 +342,16 @@ public ScriptableObject randomPoints(int number) { return points; } + @JSFunction + public Geometry getMaximumInscribedCircle(NativeObject config) { + double tolerance = getDouble(config.getOrDefault("tolerance", 1.0)); + MaximumInscribedCircle algorithm = new MaximumInscribedCircle(getGeometry(), tolerance); + return (Geometry) GeometryWrapper.wrap( + getParentScope(), + algorithm.getCenter().buffer(algorithm.getRadiusLine().getLength()) + ); + } + @JSFunction public ScriptableObject createDelaunayTriangles(boolean isConforming) { org.locationtech.jts.geom.Geometry geom; diff --git a/src/test/resources/org/geoscript/js/tests/geoscript/test_geom.js b/src/test/resources/org/geoscript/js/tests/geoscript/test_geom.js index 769a387..a134e38 100644 --- a/src/test/resources/org/geoscript/js/tests/geoscript/test_geom.js +++ b/src/test/resources/org/geoscript/js/tests/geoscript/test_geom.js @@ -186,6 +186,20 @@ exports["test: create conforming delaunay triangles"] = function() { } +exports["test: maximum inscribed circle"] = function() { + + var geom = new GEOM.Polygon([[ + [-122.38855361938475, 47.5805786829606], [-122.38636493682861, 47.5783206388176], + [-122.38700866699219, 47.5750491969984], [-122.38177299499512, 47.57502024527343], + [-122.38481998443604, 47.5780600889959], [-122.38151550292969, 47.5805786829606], + [-122.38855361938475, 47.5805786829606] + ]]); + ASSERT.ok(geom instanceof GEOM.Polygon); + var circle = geom.getMaximumInscribedCircle({tolerance: 1.0}); + ASSERT.ok(circle instanceof GEOM.Polygon); + +} + exports["test: create non-conforming delaunay triangles"] = function() { var geom = GEOM.Point([1,1]).buffer(50)