Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ public class MinimumAreaRectangle
public static Geometry getMinimumRectangle(Geometry geom) {
return (new MinimumAreaRectangle(geom)).getMinimumRectangle();
}

/**
* Gets the minimum-area rectangular {@link Polygon} which encloses the input geometry,
* with a hint whether the geometry is already convex.
* If the geometry is known to be convex, setting {@code isConvex} to {@code true}
* avoids computing the convex hull.
* If the convex hull of the input is degenerate (a line or point)
* a {@link LineString} or a {@link Point} is returned.
*
* @param geom the geometry
* @param isConvex {@code true} if the input geometry is convex
* @return the minimum rectangle enclosing the geometry
*
* @see #MinimumAreaRectangle(Geometry, boolean)
*/
public static Geometry getMinimumRectangle(Geometry geom, boolean isConvex) {
return (new MinimumAreaRectangle(geom, isConvex)).getMinimumRectangle();
}

private final Geometry inputGeom;
private final boolean isConvex;
Expand Down Expand Up @@ -81,7 +99,14 @@ public MinimumAreaRectangle(Geometry inputGeom, boolean isConvex)
this.isConvex = isConvex;
}

private Geometry getMinimumRectangle()
/**
* Gets the minimum-area rectangular {@link Polygon} which encloses the input geometry.
* If the convex hull of the input is degenerate (a line or point)
* a {@link LineString} or a {@link Point} is returned.
*
* @return the minimum rectangle enclosing the geometry
*/
public Geometry getMinimumRectangle()
{
if (inputGeom.isEmpty()) {
return inputGeom.getFactory().createPolygon();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ public void testConvex() {
checkMinRectangle("POLYGON ((3 8, 6 8, 9 5, 7 3, 3 1, 2 4, 3 8))",
"POLYGON ((0.2 6.6, 6.6 9.8, 9.4 4.2, 3 1, 0.2 6.6))");
}

/**
* Convex-hint API: static factory and public instance method (JTS #1149).
* Result must match the non-hint path for a convex polygon.
*/
public void testConvexHintStaticAndInstance() {
String wkt = "POLYGON ((3 8, 6 8, 9 5, 7 3, 3 1, 2 4, 3 8))";
Geometry geom = read(wkt);
Geometry expected = MinimumAreaRectangle.getMinimumRectangle(geom);

Geometry viaStatic = MinimumAreaRectangle.getMinimumRectangle(geom, true);
checkEqual(expected, viaStatic, TOL);

Geometry viaInstance = new MinimumAreaRectangle(geom, true).getMinimumRectangle();
checkEqual(expected, viaInstance, TOL);
}

/**
* Failure case from https://trac.osgeo.org/postgis/ticket/5163
Expand Down
Loading