From 8bd2b33123b37d349ef1bc506d99cc12902ce9a3 Mon Sep 17 00:00:00 2001 From: Kakhnovich Raman Date: Wed, 8 Oct 2025 16:15:49 +0300 Subject: [PATCH] Add min/max checks to BoundingBox constructors --- .../entities/geometry/BoundingBox.java | 10 +-- .../files/tables/PDFUA-Ref-2-06_Brochure.json | 81 ------------------- 2 files changed, 5 insertions(+), 86 deletions(-) diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/BoundingBox.java b/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/BoundingBox.java index bbd7d38f..74b90e36 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/BoundingBox.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/BoundingBox.java @@ -25,7 +25,7 @@ public BoundingBox(Integer pageNumber) { } public BoundingBox(double[] bbox) { - init(bbox[0], bbox[1], bbox[2], bbox[3]); + init(Math.min(bbox[0], bbox[2]), Math.min(bbox[1], bbox[3]), Math.max(bbox[0], bbox[2]), Math.max(bbox[1], bbox[3])); } public BoundingBox(Integer pageNumber, double[] bbox) { @@ -34,22 +34,22 @@ public BoundingBox(Integer pageNumber, double[] bbox) { } public BoundingBox(Integer pageNumber, Integer lastPageNumber, double[] bbox) { - init(bbox[0], bbox[1], bbox[2], bbox[3]); + init(Math.min(bbox[0], bbox[2]), Math.min(bbox[1], bbox[3]), Math.max(bbox[0], bbox[2]), Math.max(bbox[1], bbox[3])); this.pageNumber = pageNumber; this.lastPageNumber = lastPageNumber; } public BoundingBox(double left, double bottom, double right, double top) { - init(left, bottom, right, top); + init(Math.min(left, right), Math.min(bottom, top), Math.max(left, right), Math.max(bottom, top)); } public BoundingBox(Integer pageNumber, double left, double bottom, double right, double top) { - init(left, bottom, right, top); + init(Math.min(left, right), Math.min(bottom, top), Math.max(left, right), Math.max(bottom, top)); this.pageNumber = this.lastPageNumber = pageNumber; } public BoundingBox(Integer pageNumber, Integer lastPageNumber, double left, double bottom, double right, double top) { - init(left, bottom, right, top); + init(Math.min(left, right), Math.min(bottom, top), Math.max(left, right), Math.max(bottom, top)); this.pageNumber = pageNumber; this.lastPageNumber = lastPageNumber; } diff --git a/src/test/resources/files/tables/PDFUA-Ref-2-06_Brochure.json b/src/test/resources/files/tables/PDFUA-Ref-2-06_Brochure.json index b2f5b7eb..d2fa6fa5 100644 --- a/src/test/resources/files/tables/PDFUA-Ref-2-06_Brochure.json +++ b/src/test/resources/files/tables/PDFUA-Ref-2-06_Brochure.json @@ -6702,15 +6702,6 @@ "endY":41.258148999999996, "width":47.509 }, - { - "type":"LineChunk", - "pageNumber":0, - "startX":741.7416373, - "startY":41.258148999999996, - "endX":836.7596373, - "endY":41.258148999999996, - "width":-38.007 - }, { "type":"LineChunk", "pageNumber":0, @@ -6738,42 +6729,6 @@ "endY":53.122648999999996, "width":5.312 }, - { - "type":"LineChunk", - "pageNumber":0, - "startX":791.1796525000001, - "startY":26.734148999999995, - "endX":791.1796525000001, - "endY":34.852149, - "width":-1.657 - }, - { - "type":"LineChunk", - "pageNumber":0, - "startX":791.1796525000001, - "startY":33.985149, - "endX":791.1796525000001, - "endY":37.06114899999999, - "width":-1.657 - }, - { - "type":"LineChunk", - "pageNumber":0, - "startX":803.7796525000001, - "startY":26.734148899999994, - "endX":803.7796525000001, - "endY":34.852148899999996, - "width":-1.657 - }, - { - "type":"LineChunk", - "pageNumber":0, - "startX":803.7796525000001, - "startY":33.9851489, - "endX":803.7796525000001, - "endY":37.06114889999999, - "width":-1.657 - }, { "type":"TextChunk", "pageNumber":0, @@ -6893,42 +6848,6 @@ "endX":319.723945716, "endY":99.3177195654, "width":8.096 - }, - { - "type":"LineChunk", - "pageNumber":0, - "startX":342.6117960947532, - "startY":59.098604222349984, - "endX":342.6117960947532, - "endY":71.47179352925, - "width":-2.525 - }, - { - "type":"LineChunk", - "pageNumber":0, - "startX":342.6117960947532, - "startY":70.15077331794998, - "endX":342.6117960947532, - "endY":74.83884504435, - "width":-2.525 - }, - { - "type":"LineChunk", - "pageNumber":0, - "startX":361.8170901312562, - "startY":59.09861942258255, - "endX":361.8170901312562, - "endY":71.47180872948256, - "width":-2.525 - }, - { - "type":"LineChunk", - "pageNumber":0, - "startX":361.8170901312562, - "startY":70.15078851818255, - "endX":361.8170901312562, - "endY":74.83886024458256, - "width":-2.525 } ] },