@@ -159,10 +159,10 @@ static long computeMaximumIterations(Geometry geom, double toleranceDist) {
159159 */
160160 public MaximumInscribedCircle (Geometry polygonal , double tolerance ) {
161161 if (! (polygonal instanceof Polygon || polygonal instanceof MultiPolygon )) {
162- throw new IllegalArgumentException ("Input geometry must be a Polygon or MultiPolygon" );
162+ throw new IllegalArgumentException ("Input must be a Polygon or MultiPolygon" );
163163 }
164164 if (polygonal .isEmpty ()) {
165- throw new IllegalArgumentException ("Empty input geometry is not supported" );
165+ throw new IllegalArgumentException ("Empty input is not supported" );
166166 }
167167
168168 this .inputGeom = polygonal ;
@@ -192,7 +192,17 @@ public boolean isRadiusWithin(double maxRadius) {
192192 if (maxRadius == 0 ) {
193193 return false ;
194194 }
195- maximumRadius = maxRadius ;
195+ maximumRadius = maxRadius ;
196+
197+ /**
198+ * Check if envelope dimension is smaller than diameter
199+ */
200+ Envelope env = inputGeom .getEnvelopeInternal ();
201+ double maxDiam = 2 * maximumRadius ;
202+ if (env .getWidth () < maxDiam || env .getHeight () < maxDiam ) {
203+ return true ;
204+ }
205+
196206 tolerance = maxRadius * MAX_RADIUS_FRACTION ;
197207 compute ();
198208 double radius = centerPt .distance (radiusPt );
@@ -264,7 +274,7 @@ private void compute() {
264274 if (centerPt != null ) return ;
265275
266276 /**
267- * Handle empty or flat geometries.
277+ * Handle flat geometries.
268278 */
269279 if (inputGeom .getArea () == 0.0 ) {
270280 Coordinate c = inputGeom .getCoordinate ().copy ();
0 commit comments