modest improvement to cropping (safer)

This commit is contained in:
2026-09-15 15:13:41 +02:00
parent 9b22a8a137
commit 5b8215e7f5
6 changed files with 56 additions and 9 deletions
+7 -3
View File
@@ -8,7 +8,10 @@ import numpy as np
import pymupdf
from pdf2image import convert_from_path
from copienator.commands.splitting_int import _render_split_outputs
from copienator.commands.splitting_int import (
ANSWER_TOP_PADDING_POINTS,
_render_split_outputs,
)
class SplittingGeometryTests(unittest.TestCase):
@@ -60,7 +63,8 @@ class SplittingGeometryTests(unittest.TestCase):
else:
coordinates = [("A", 0, 250, 260, 0, 100),
("_", 0, 711, 721, 0, 100)]
bounds = (bounds[0], max(bounds[1], height // 4),
answer_top = int(height // 4 - ANSWER_TOP_PADDING_POINTS)
bounds = (bounds[0], max(bounds[1], answer_top),
bounds[2], min(bounds[3], height * 3 // 4))
_render_split_outputs(source, coordinates, root)
self.assert_matches_preview(root / "A.pdf", preview, bounds)
@@ -85,7 +89,7 @@ class SplittingGeometryTests(unittest.TestCase):
rendered = convert_from_path(root / "A.pdf", dpi=72)
self.assertEqual(len(rendered), 2)
for actual, preview, bounds in zip(rendered, previews,
[(40, 700, 780, 920), (20, 80, 760, 250)]):
[(40, 688, 780, 920), (20, 80, 760, 250)]):
expected = np.asarray(preview.crop(bounds)).astype(float)
actual = np.asarray(actual).astype(float)
self.assertEqual(actual.shape, expected.shape)