Skip to content

Commit

Permalink
cache as long as tolerance doesn't change
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Nov 14, 2023
1 parent 5f4d445 commit 1e12f1c
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public abstract class SourceFeature implements WithTags, WithGeometryType {
private Geometry centroid = null;
private Geometry pointOnSurface = null;
private Geometry centroidIfConvex = null;
private double innermostPointTolerance = Double.NaN;
private Geometry innermostPoint = null;
private Geometry linearGeometry = null;
private Geometry polygonGeometry = null;
private Geometry validPolygon = null;
Expand Down Expand Up @@ -136,7 +138,12 @@ public final Geometry pointOnSurface() throws GeometryException {
*/
public final Geometry innermostPoint(double tolerance) throws GeometryException {
if (canBePolygon()) {
return MaximumInscribedCircle.getCenter(polygon(), Math.sqrt(area()) * tolerance);
// cache as long as the tolerance hasn't changed
if (tolerance != innermostPointTolerance || innermostPoint == null) {
innermostPoint = MaximumInscribedCircle.getCenter(polygon(), Math.sqrt(area()) * tolerance);
innermostPointTolerance = tolerance;
}
return innermostPoint;
} else {
return pointOnSurface();
}
Expand Down

0 comments on commit 1e12f1c

Please sign in to comment.