Skip to content

Commit e788619

Browse files
committed
Fix ExactMaxInscribedCircle to handle collinear input
1 parent 8d5ced1 commit e788619

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

modules/core/src/main/java/org/locationtech/jts/algorithm/Angle.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ public static double angleBetweenOriented(Coordinate tip1, Coordinate tail,
185185
* Computes the angle of the unoriented bisector
186186
* of the smallest angle between two vectors.
187187
* The computed angle will be in the range (-Pi, Pi].
188+
* Collinear inputs are handled.
188189
*
189190
* @param tip1 the tip of v1
190191
* @param tail the tail of each vector

modules/core/src/main/java/org/locationtech/jts/algorithm/construct/ExactMaxInscribedCircle.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ private static LineSegment computeConvexBisector(Coordinate[] pts, int index, do
163163
int iNext = index >= pts.length ? 0 : index + 1;
164164
Coordinate pPrev = pts[iPrev];
165165
Coordinate pNext = pts[iNext];
166-
if (! isConvex(pPrev, basePt, pNext))
167-
throw new IllegalArgumentException("Input is not convex");
166+
167+
//-- this should never happen, since only convex quads are handled
168+
if (isConcave(pPrev, basePt, pNext))
169+
throw new IllegalStateException("Input is not convex");
170+
168171
double bisectAng = Angle.bisector(pPrev, basePt, pNext);
169172
Coordinate endPt = Angle.project(basePt, bisectAng, len);
170173
return new LineSegment(basePt.copy(), endPt);
@@ -201,8 +204,8 @@ else if (orient != ringOrient) {
201204
return true;
202205
}
203206

204-
private static boolean isConvex(Coordinate p0, Coordinate p1, Coordinate p2) {
205-
return Orientation.CLOCKWISE == Orientation.index(p0, p1, p2);
207+
private static boolean isConcave(Coordinate p0, Coordinate p1, Coordinate p2) {
208+
return Orientation.COUNTERCLOCKWISE == Orientation.index(p0, p1, p2);
206209
}
207210

208211
private static boolean isPointInConvexRing(Coordinate[] ringCW, Coordinate p) {

modules/core/src/test/java/org/locationtech/jts/algorithm/construct/MaximumInscribedCircleTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ public void testVeryThin() {
112112
0.01 );
113113
}
114114

115+
public void testQuadWithCollinearVertex() {
116+
checkCircle("POLYGON ((1 5, 5 5, 9 5, 5 1, 1 5))",
117+
0.001, 5.0, 3.3431, 1.65685 );
118+
}
119+
115120
/**
116121
* A coarse distance check, mainly testing
117122
* that there is not a huge number of iterations.

0 commit comments

Comments
 (0)