diff --git a/src/main/java/com/mindee/geometry/Bbox.java b/src/main/java/com/mindee/geometry/Bbox.java index 4f4f3dd8b..79e804277 100644 --- a/src/main/java/com/mindee/geometry/Bbox.java +++ b/src/main/java/com/mindee/geometry/Bbox.java @@ -1,6 +1,5 @@ package com.mindee.geometry; -import java.util.Arrays; import java.util.List; import lombok.Getter; @@ -34,8 +33,8 @@ public Bbox(double minX, double maxX, double minY, double maxY) { * Get the Bbox as a Polygon. */ public Polygon getAsPolygon() { - List points = Arrays - .asList( + var points = List + .of( new Point(this.minX, this.minY), new Point(this.maxX, this.minY), new Point(this.maxX, this.maxY), diff --git a/src/main/java/com/mindee/geometry/BboxUtils.java b/src/main/java/com/mindee/geometry/BboxUtils.java index 0b4ca8bcd..98802a90f 100644 --- a/src/main/java/com/mindee/geometry/BboxUtils.java +++ b/src/main/java/com/mindee/geometry/BboxUtils.java @@ -1,8 +1,6 @@ package com.mindee.geometry; -import java.util.DoubleSummaryStatistics; import java.util.List; -import java.util.Optional; /** * Methods for working with BBoxes. @@ -20,17 +18,8 @@ public static Bbox generate(Polygon polygon) { return null; } - DoubleSummaryStatistics statsX = polygon - .getCoordinates() - .stream() - .mapToDouble(Point::getX) - .summaryStatistics(); - - DoubleSummaryStatistics statsY = polygon - .getCoordinates() - .stream() - .mapToDouble(Point::getY) - .summaryStatistics(); + var statsX = polygon.getCoordinates().stream().mapToDouble(Point::getX).summaryStatistics(); + var statsY = polygon.getCoordinates().stream().mapToDouble(Point::getY).summaryStatistics(); return new Bbox(statsX.getMin(), statsX.getMax(), statsY.getMin(), statsY.getMax()); } @@ -44,13 +33,7 @@ public static Bbox generate(List polygons) { return null; } - Optional mergedPolygon = polygons.stream().reduce(PolygonUtils::combine); - - if (!mergedPolygon.isPresent()) { - return null; - } - - return generate(mergedPolygon.get()); + return polygons.stream().reduce(PolygonUtils::combine).map(BboxUtils::generate).orElse(null); } /** @@ -62,10 +45,10 @@ public static Bbox merge(List bboxes) { } return new Bbox( - bboxes.stream().map(Bbox::getMinX).min(Double::compare).get(), - bboxes.stream().map(Bbox::getMaxX).max(Double::compare).get(), - bboxes.stream().map(Bbox::getMinY).min(Double::compare).get(), - bboxes.stream().map(Bbox::getMaxY).max(Double::compare).get() + bboxes.stream().mapToDouble(Bbox::getMinX).min().getAsDouble(), + bboxes.stream().mapToDouble(Bbox::getMaxX).max().getAsDouble(), + bboxes.stream().mapToDouble(Bbox::getMinY).min().getAsDouble(), + bboxes.stream().mapToDouble(Bbox::getMaxY).max().getAsDouble() ); } diff --git a/src/main/java/com/mindee/geometry/BoundingBoxUtils.java b/src/main/java/com/mindee/geometry/BoundingBoxUtils.java deleted file mode 100644 index d4b8e31bf..000000000 --- a/src/main/java/com/mindee/geometry/BoundingBoxUtils.java +++ /dev/null @@ -1,36 +0,0 @@ -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()) - ) - ); - } -} diff --git a/src/main/java/com/mindee/geometry/Polygon.java b/src/main/java/com/mindee/geometry/Polygon.java index 168fbb6f2..0c2a64b6e 100644 --- a/src/main/java/com/mindee/geometry/Polygon.java +++ b/src/main/java/com/mindee/geometry/Polygon.java @@ -42,6 +42,23 @@ public Bbox getAsBbox() { return BboxUtils.generate(this); } + /** + * Get a bounding box that encloses the Polygon. + */ + public Polygon getBoundingBox() { + var minMaxX = getMinMaxX(); + var minMaxY = getMinMaxY(); + return new Polygon( + List + .of( + new Point(minMaxX.getMin(), minMaxY.getMin()), + new Point(minMaxX.getMax(), minMaxY.getMin()), + new Point(minMaxX.getMax(), minMaxY.getMax()), + new Point(minMaxX.getMin(), minMaxY.getMax()) + ) + ); + } + /** * Get the central coordinates (centroid) of the Polygon. */ @@ -84,15 +101,7 @@ public String toString() { * String representation with precise coordinates. */ public String toStringPrecise() { - StringBuilder builder = new StringBuilder("("); - for (int i = 0; i < coordinates.size(); i++) { - if (i > 0) { - builder.append(", "); - } - builder.append(coordinates.get(i)); - } - builder.append(")"); - return builder.toString(); + return coordinates.stream().map(Point::toString).collect(Collectors.joining(", ", "(", ")")); } /** diff --git a/src/main/java/com/mindee/geometry/PolygonUtils.java b/src/main/java/com/mindee/geometry/PolygonUtils.java index dd5a8c977..6fb017d72 100644 --- a/src/main/java/com/mindee/geometry/PolygonUtils.java +++ b/src/main/java/com/mindee/geometry/PolygonUtils.java @@ -1,7 +1,5 @@ package com.mindee.geometry; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -19,8 +17,8 @@ private PolygonUtils() { public static Point getCentroid(List vertices) { int verticesSum = vertices.size(); - double xSum = vertices.stream().map(Point::getX).mapToDouble(Double::doubleValue).sum(); - double ySum = vertices.stream().map(Point::getY).mapToDouble(Double::doubleValue).sum(); + double xSum = vertices.stream().mapToDouble(Point::getX).sum(); + double ySum = vertices.stream().mapToDouble(Point::getY).sum(); return new Point(xSum / verticesSum, ySum / verticesSum); } @@ -28,16 +26,16 @@ public static Point getCentroid(List vertices) { * Get the maximum and minimum Y coordinates in a given list of Points. */ public static MinMax getMinMaxY(List vertices) { - List points = vertices.stream().map(Point::getY).collect(Collectors.toList()); - return new MinMax(Collections.min(points), Collections.max(points)); + var stats = vertices.stream().mapToDouble(Point::getY).summaryStatistics(); + return new MinMax(stats.getMin(), stats.getMax()); } /** * Get the maximum and minimum X coordinates in a given list of Points. */ public static MinMax getMinMaxX(List vertices) { - List points = vertices.stream().map(Point::getX).collect(Collectors.toList()); - return new MinMax(Collections.min(points), Collections.max(points)); + var stats = vertices.stream().mapToDouble(Point::getX).summaryStatistics(); + return new MinMax(stats.getMin(), stats.getMax()); } /** @@ -70,77 +68,20 @@ public static Polygon combine(Polygon base, Polygon target) { target = base; } - Double maxx = Math - .max( - target - .getCoordinates() - .stream() - .map(Point::getX) - .max(Double::compareTo) - .orElse(Double.MIN_VALUE), - base - .getCoordinates() - .stream() - .map(Point::getX) - .max(Double::compareTo) - .orElse(Double.MIN_VALUE) - ); + var combinedCoords = java.util.stream.Stream + .concat(base.getCoordinates().stream(), target.getCoordinates().stream()) + .collect(Collectors.toList()); - Double minx = Math - .min( - target - .getCoordinates() - .stream() - .map(Point::getX) - .min(Double::compareTo) - .orElse(Double.MAX_VALUE), - base - .getCoordinates() - .stream() - .map(Point::getX) - .min(Double::compareTo) - .orElse(Double.MAX_VALUE) - ); - - Double maxy = Math - .max( - target - .getCoordinates() - .stream() - .map(Point::getY) - .max(Double::compareTo) - .orElse(Double.MIN_VALUE), - base - .getCoordinates() - .stream() - .map(Point::getY) - .max(Double::compareTo) - .orElse(Double.MIN_VALUE) - ); - - Double miny = Math - .min( - target - .getCoordinates() - .stream() - .map(Point::getY) - .min(Double::compareTo) - .orElse(Double.MAX_VALUE), - base - .getCoordinates() - .stream() - .map(Point::getY) - .min(Double::compareTo) - .orElse(Double.MAX_VALUE) - ); + var xStats = combinedCoords.stream().mapToDouble(Point::getX).summaryStatistics(); + var yStats = combinedCoords.stream().mapToDouble(Point::getY).summaryStatistics(); return new Polygon( - Arrays - .asList( - new Point(minx, miny), - new Point(maxx, miny), - new Point(maxx, maxy), - new Point(minx, maxy) + List + .of( + new Point(xStats.getMin(), yStats.getMin()), + new Point(xStats.getMax(), yStats.getMin()), + new Point(xStats.getMax(), yStats.getMax()), + new Point(xStats.getMin(), yStats.getMax()) ) ); } diff --git a/src/main/java/com/mindee/http/MindeeApiCommon.java b/src/main/java/com/mindee/http/MindeeApiCommon.java index 0f3c68632..62e3574e8 100644 --- a/src/main/java/com/mindee/http/MindeeApiCommon.java +++ b/src/main/java/com/mindee/http/MindeeApiCommon.java @@ -2,6 +2,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import org.apache.hc.core5.http.HttpEntity; /** @@ -10,7 +11,7 @@ public abstract class MindeeApiCommon { /** * Retrieves the user agent. - * + * * @return the user agent. */ protected String getUserAgent() { @@ -36,7 +37,7 @@ protected String getUserAgent() { /** * Checks if the status code is out of the 2xx-3xx range. - * + * * @param statusCode the status code to check. * @return {@code true} if the status code is in the 2xx range, false otherwise. */ @@ -50,6 +51,6 @@ protected String readRawResponse(HttpEntity responseEntity) throws IOException { for (int length; (length = responseEntity.getContent().read(buffer)) != -1;) { contentRead.write(buffer, 0, length); } - return contentRead.toString("UTF-8"); + return contentRead.toString(StandardCharsets.UTF_8); } } diff --git a/src/main/java/com/mindee/image/ExtractedImage.java b/src/main/java/com/mindee/image/ExtractedImage.java index 76540a8a3..319f98f5d 100644 --- a/src/main/java/com/mindee/image/ExtractedImage.java +++ b/src/main/java/com/mindee/image/ExtractedImage.java @@ -3,7 +3,6 @@ import com.mindee.input.LocalInputSource; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; @@ -40,9 +39,7 @@ public ExtractedImage(BufferedImage image, String filename, String saveFormat) { * @throws IOException Throws if the file can't be accessed. */ public void writeToFile(String outputPath) throws IOException { - Path imagePath = Paths.get(outputPath, this.filename); - File outputfile = imagePath.toFile(); - ImageIO.write(this.image, this.saveFormat, outputfile); + writeToFile(Paths.get(outputPath)); } /** @@ -53,8 +50,8 @@ public void writeToFile(String outputPath) throws IOException { * @throws IOException Throws if the file can't be accessed. */ public void writeToFile(Path outputPath) throws IOException { - Path imagePath = outputPath.resolve(this.filename); - File outputfile = imagePath.toFile(); + var imagePath = outputPath.resolve(this.filename); + var outputfile = imagePath.toFile(); ImageIO.write(this.image, this.saveFormat, outputfile); } @@ -65,7 +62,7 @@ public void writeToFile(Path outputPath) throws IOException { * @throws IOException Throws if the file can't be accessed. */ public LocalInputSource asInputSource() throws IOException { - ByteArrayOutputStream output = new ByteArrayOutputStream(); + var output = new ByteArrayOutputStream(); ImageIO.write(this.image, this.saveFormat, output); return new LocalInputSource(output.toByteArray(), this.filename); } diff --git a/src/main/java/com/mindee/image/ImageCompressor.java b/src/main/java/com/mindee/image/ImageCompressor.java index 8a58231d4..b56096322 100644 --- a/src/main/java/com/mindee/image/ImageCompressor.java +++ b/src/main/java/com/mindee/image/ImageCompressor.java @@ -1,12 +1,10 @@ package com.mindee.image; -import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.util.Iterator; import javax.imageio.IIOImage; import javax.imageio.ImageIO; import javax.imageio.ImageWriteParam; @@ -21,10 +19,10 @@ public static BufferedImage resize( Integer newWidth, Integer newHeight ) { - Image scaledImage = inputImage.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH); - BufferedImage outImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB); + var scaledImage = inputImage.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH); + var outImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = outImage.createGraphics(); + var g2d = outImage.createGraphics(); g2d.drawImage(scaledImage, 0, 0, null); g2d.dispose(); @@ -38,8 +36,8 @@ public static byte[] compressImage( Integer maxHeight ) throws IOException { - ByteArrayInputStream bis = new ByteArrayInputStream(imageData); - BufferedImage original = ImageIO.read(bis); + var bis = new ByteArrayInputStream(imageData); + var original = ImageIO.read(bis); ImageUtils.Dimensions dimensions = ImageUtils .calculateNewDimensions(original, maxWidth, maxHeight); return compressImage(original, quality, dimensions.width, dimensions.height); @@ -70,7 +68,7 @@ public static byte[] compressImage( if (quality == null) { quality = 85; } - BufferedImage resizedImage = resize(original, finalWidth, finalHeight); + var resizedImage = resize(original, finalWidth, finalHeight); return encodeToJpegByteArray(resizedImage, (float) quality / 100f); } @@ -78,14 +76,14 @@ public static BufferedImage removeAlphaChannel(BufferedImage original) { if (original.getType() == BufferedImage.TYPE_INT_RGB) { return original; } - BufferedImage newImage = new BufferedImage( + var newImage = new BufferedImage( original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_RGB ); - Graphics2D g = newImage.createGraphics(); - g.drawImage(original, 0, 0, null); - g.dispose(); + var graphics = newImage.createGraphics(); + graphics.drawImage(original, 0, 0, null); + graphics.dispose(); return newImage; } @@ -93,17 +91,17 @@ public static byte[] encodeToJpegByteArray( BufferedImage image, float quality ) throws IOException { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + var outputStream = new ByteArrayOutputStream(); - Iterator writers = ImageIO.getImageWritersByFormatName("jpg"); + var writers = ImageIO.getImageWritersByFormatName("jpg"); ImageWriter writer = writers.next(); - ImageWriteParam params = writer.getDefaultWriteParam(); + var params = writer.getDefaultWriteParam(); params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); params.setCompressionQuality(quality); writer.setOutput(ImageIO.createImageOutputStream(outputStream)); - BufferedImage alphaCheckedImage = removeAlphaChannel(image); + var alphaCheckedImage = removeAlphaChannel(image); writer.write(null, new IIOImage(alphaCheckedImage, null, null), params); writer.dispose(); diff --git a/src/main/java/com/mindee/image/ImageExtractor.java b/src/main/java/com/mindee/image/ImageExtractor.java index 8dcb6b181..24ea7b15b 100644 --- a/src/main/java/com/mindee/image/ImageExtractor.java +++ b/src/main/java/com/mindee/image/ImageExtractor.java @@ -44,7 +44,7 @@ public ImageExtractor(LocalInputSource source) throws IOException { if (source.isPdf()) { this.saveFormat = "jpg"; - List pdfPageImages = PDFUtils.pdfToImages(source); + var pdfPageImages = PDFUtils.pdfToImages(source); for (PdfPageImage pdfPageImage : pdfPageImages) { this.pageImages.add(pdfPageImage.getImage()); } @@ -52,7 +52,7 @@ public ImageExtractor(LocalInputSource source) throws IOException { String[] splitName = InputSourceUtils.splitNameStrict(this.filename); this.saveFormat = splitName[1].toLowerCase(); - ByteArrayInputStream input = new ByteArrayInputStream(source.getFile()); + var input = new ByteArrayInputStream(source.getFile()); this.pageImages.add(ImageIO.read(input)); } } @@ -111,11 +111,11 @@ private List extractFromPage( String outputName ) { String[] splitName = InputSourceUtils.splitNameStrict(outputName); - String filename = String + var filename = String .format("%s_page-%3s.%s", splitName[0], pageIndex + 1, splitName[1]) .replace(" ", "0"); - List extractedImages = new ArrayList<>(); + var extractedImages = new ArrayList(); for (int i = 0; i < fields.size(); i++) { ExtractedImage extractedImage = extractImage(fields.get(i), pageIndex, i + 1, filename); if (extractedImage != null) { @@ -178,7 +178,7 @@ public ExtractedImage extractImage( } private BufferedImage extractImage(Bbox bbox, int pageIndex) { - BufferedImage image = this.pageImages.get(pageIndex); + var image = this.pageImages.get(pageIndex); int width = image.getWidth(); int height = image.getHeight(); int minX = (int) Math.round(bbox.getMinX() * width); diff --git a/src/main/java/com/mindee/input/LocalInputSource.java b/src/main/java/com/mindee/input/LocalInputSource.java index 46fc006c4..b5f0169ad 100644 --- a/src/main/java/com/mindee/input/LocalInputSource.java +++ b/src/main/java/com/mindee/input/LocalInputSource.java @@ -30,7 +30,7 @@ public LocalInputSource(InputStream file, String filename) throws IOException { } public LocalInputSource(String filePath) throws IOException { - File file = new File(filePath); + var file = new File(filePath); this.file = Files.readAllBytes(file.toPath()); this.filename = file.getName(); } @@ -57,7 +57,7 @@ public LocalInputSource(String fileAsBase64, String filename) { /** * Get the number of pages in the document. - * + * * @return the number of pages in the current file. * @throws IOException If an I/O error occurs during the PDF operation. */ diff --git a/src/main/java/com/mindee/input/PageOptionsOperation.java b/src/main/java/com/mindee/input/PageOptionsOperation.java index d21663d94..7fead0f82 100644 --- a/src/main/java/com/mindee/input/PageOptionsOperation.java +++ b/src/main/java/com/mindee/input/PageOptionsOperation.java @@ -5,11 +5,11 @@ */ public enum PageOptionsOperation { /** - * Keep only the specified pages, and remove all others. + * Keep only the specified pages, removing all others. */ KEEP_ONLY, /** - * Remove the specified pages, and keep all others. + * Remove the specified pages, keeping all others. */ REMOVE } diff --git a/src/main/java/com/mindee/parsing/SummaryHelper.java b/src/main/java/com/mindee/parsing/SummaryHelper.java index dd6cb7f24..1f98b7b2c 100644 --- a/src/main/java/com/mindee/parsing/SummaryHelper.java +++ b/src/main/java/com/mindee/parsing/SummaryHelper.java @@ -72,7 +72,7 @@ public static String formatForDisplay(Boolean inputValue, Integer maxColSize) { * Format an rST table line separator. */ public static String lineSeparator(int[] columnSizes, String str) { - StringBuilder outStr = new StringBuilder(" +"); + var outStr = new StringBuilder(" +"); for (int size : columnSizes) { outStr.append(String.format("%" + size + "s+", "").replace(" ", str)); } diff --git a/src/main/java/com/mindee/pdf/ExtractedPDF.java b/src/main/java/com/mindee/pdf/ExtractedPDF.java index 3041ef143..7bfe24c95 100644 --- a/src/main/java/com/mindee/pdf/ExtractedPDF.java +++ b/src/main/java/com/mindee/pdf/ExtractedPDF.java @@ -4,7 +4,6 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.nio.file.Path; import java.nio.file.Paths; import lombok.Getter; import org.apache.pdfbox.pdmodel.PDDocument; @@ -35,8 +34,8 @@ public ExtractedPDF(PDDocument pdf, String filename) { * @throws IOException Throws if the file can't be accessed. */ public void writeToFile(String outputPath) throws IOException { - Path pdfPath = Paths.get(outputPath, this.filename); - File outputfile = new File(pdfPath.toString()); + var pdfPath = Paths.get(outputPath, this.filename); + var outputfile = new File(pdfPath.toString()); this.pdf.save(outputfile); } @@ -47,7 +46,7 @@ public void writeToFile(String outputPath) throws IOException { * @throws IOException Throws if the file can't be accessed. */ public LocalInputSource asInputSource() throws IOException { - ByteArrayOutputStream output = new ByteArrayOutputStream(); + var output = new ByteArrayOutputStream(); this.pdf.save(output); return new LocalInputSource(output.toByteArray(), this.filename); } diff --git a/src/main/java/com/mindee/v1/parsing/standard/BaseField.java b/src/main/java/com/mindee/v1/parsing/standard/BaseField.java index f4fa24f0c..3e8c8af8f 100644 --- a/src/main/java/com/mindee/v1/parsing/standard/BaseField.java +++ b/src/main/java/com/mindee/v1/parsing/standard/BaseField.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.mindee.geometry.BoundingBoxUtils; import com.mindee.geometry.Polygon; import com.mindee.geometry.PolygonDeserializer; import com.mindee.geometry.PositionDataField; @@ -54,7 +53,7 @@ protected BaseField( this.polygon = polygon; this.pageId = pageId; if (polygon != null) { - this.boundingBox = BoundingBoxUtils.createBoundingBoxFrom(this.polygon); + this.boundingBox = this.polygon.getBoundingBox(); } else { this.boundingBox = null; } @@ -65,7 +64,7 @@ protected BaseField( */ protected BaseField() { if (polygon != null) { - this.boundingBox = BoundingBoxUtils.createBoundingBoxFrom(this.polygon); + this.boundingBox = this.polygon.getBoundingBox(); } else { this.boundingBox = null; } diff --git a/src/test/java/com/mindee/geometry/BoundingBoxUtilsTest.java b/src/test/java/com/mindee/geometry/BoundingBoxUtilsTest.java index b72afab78..8ea4bb73e 100644 --- a/src/test/java/com/mindee/geometry/BoundingBoxUtilsTest.java +++ b/src/test/java/com/mindee/geometry/BoundingBoxUtilsTest.java @@ -7,22 +7,16 @@ class BoundingBoxUtilsTest { @Test public void bboxFromARectanglePolygonMustHaveALimitedNumberOfCoordinates() { - // given Polygon polygonAsRectangle = PolygonSample.getPolygonAsRectangle(); - - // then - Polygon boundingBox = BoundingBoxUtils.createBoundingBoxFrom(polygonAsRectangle); + Polygon boundingBox = polygonAsRectangle.getBoundingBox(); Assertions.assertEquals(4, boundingBox.getCoordinates().size()); } @Test public void fromARectanglePolygonMustGetAValidBbox() { - // given Polygon polygonAsRectangle = PolygonSample.getPolygonAsRectangle(); - - // then - Polygon boundingBox = BoundingBoxUtils.createBoundingBoxFrom(polygonAsRectangle); + Polygon boundingBox = polygonAsRectangle.getBoundingBox(); Assertions .assertTrue(boundingBox.getCoordinates().stream().anyMatch(c -> c.getX().equals(0.123))); @@ -37,11 +31,8 @@ public void fromARectanglePolygonMustGetAValidBbox() { @Test public void fromPolygonMustGetAValidBbox() { - // given Polygon polygonWichIsNotRectangle = PolygonSample.getPolygonWichIsNotRectangle(); - - // then - Polygon boundingBox = BoundingBoxUtils.createBoundingBoxFrom(polygonWichIsNotRectangle); + Polygon boundingBox = polygonWichIsNotRectangle.getBoundingBox(); Assertions .assertTrue(boundingBox.getCoordinates().stream().anyMatch(c -> c.getX().equals(0.205)));