Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/api/geom/geometry.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/geoscript/js/geom/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/test/resources/org/geoscript/js/tests/geoscript/test_geom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down