com.mindee.geometry.BoundingBoxUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mindee-api-java Show documentation
Show all versions of mindee-api-java Show documentation
Java Library to call Mindee's Off-The-Shelf and Custom APIs
package com.mindee.geometry;
import java.util.Arrays;
import java.util.DoubleSummaryStatistics;
/**
* Methods for working with BoundingBoxes.
*/
public final class BoundingBoxUtils {
private BoundingBoxUtils() {
}
public static Polygon createBoundingBoxFrom(Polygon polygon) {
DoubleSummaryStatistics xStatistics = polygon.getCoordinates().stream()
.mapToDouble(Point::getX)
.summaryStatistics();
DoubleSummaryStatistics yStatistics = polygon.getCoordinates()
.stream().mapToDouble(Point::getY)
.summaryStatistics();
return new Polygon(Arrays.asList(
new Point(xStatistics.getMin(), yStatistics.getMin()),
new Point(xStatistics.getMax(), yStatistics.getMin()),
new Point(xStatistics.getMax(), yStatistics.getMax()),
new Point(xStatistics.getMin(), yStatistics.getMax())));
}
}