Skip to content

Commit d517aa3

Browse files
authored
Add get maximum inscribed circle method to Geometry (#79)
1 parent 12d067f commit d517aa3

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

doc/api/geom/geometry.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ Common Geometry Methods
266266
:attr:`projection` of this geometry must be set before calling this
267267
method. Returns a new geometry.
268268

269+
.. function:: Geometry.getMaximumInscribedCircle
270+
271+
:arg config: :`Object` tolerance property defaults to 1.0
272+
:returns: :class:`geom.Geometry`
273+
274+
Get the maximum inscribed circle for this Geometry.
275+
269276
.. function:: Geometry.within
270277

271278
:arg other: :class:`geom.Geometry`

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.MaximumInscribedCircle;
910
import org.locationtech.jts.densify.Densifier;
1011
import org.geoscript.js.GeoObject;
1112
import org.geoscript.js.proj.Projection;
@@ -341,6 +342,16 @@ public ScriptableObject randomPoints(int number) {
341342
return points;
342343
}
343344

345+
@JSFunction
346+
public Geometry getMaximumInscribedCircle(NativeObject config) {
347+
double tolerance = getDouble(config.getOrDefault("tolerance", 1.0));
348+
MaximumInscribedCircle algorithm = new MaximumInscribedCircle(getGeometry(), tolerance);
349+
return (Geometry) GeometryWrapper.wrap(
350+
getParentScope(),
351+
algorithm.getCenter().buffer(algorithm.getRadiusLine().getLength())
352+
);
353+
}
354+
344355
@JSFunction
345356
public ScriptableObject createDelaunayTriangles(boolean isConforming) {
346357
org.locationtech.jts.geom.Geometry geom;

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
@@ -186,6 +186,20 @@ exports["test: create conforming delaunay triangles"] = function() {
186186

187187
}
188188

189+
exports["test: maximum inscribed circle"] = function() {
190+
191+
var geom = new GEOM.Polygon([[
192+
[-122.38855361938475, 47.5805786829606], [-122.38636493682861, 47.5783206388176],
193+
[-122.38700866699219, 47.5750491969984], [-122.38177299499512, 47.57502024527343],
194+
[-122.38481998443604, 47.5780600889959], [-122.38151550292969, 47.5805786829606],
195+
[-122.38855361938475, 47.5805786829606]
196+
]]);
197+
ASSERT.ok(geom instanceof GEOM.Polygon);
198+
var circle = geom.getMaximumInscribedCircle({tolerance: 1.0});
199+
ASSERT.ok(circle instanceof GEOM.Polygon);
200+
201+
}
202+
189203
exports["test: create non-conforming delaunay triangles"] = function() {
190204

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

0 commit comments

Comments
 (0)