fix: a film is cut into parts where its own pixels are clear, never through the art when it can be helped (#136)
Some checks failed
Build and deploy / Validate source (push) Successful in 9s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled

The layout sees a ready sheet as one piece, so a part was cut at its length,
through the artwork. Where no gap between pieces is near the limit, the
film is read there: the cut falls in the middle of the nearest clear band of
3 mm, else of the widest clear band (#83's packed sheets have 2 mm between
rows), else on the row with the least ink. A part is never shorter than half
the limit, and the render limit allows one part more.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-27 14:11:15 -03:00
parent eb56c49016
commit 331e43aa14
4 changed files with 105 additions and 12 deletions

View File

@@ -166,6 +166,40 @@ class PngRenderTests(unittest.TestCase):
self.assertEqual(second.convert('RGBA').getpixel((10, px(22) - px(21) + 5))[:3], RED)
self.assertEqual([p['name'] for p in detail['parts']], ['DTF-7-item-1-p1.png', 'DTF-7-item-1-p2.png'])
def sheet_spec(self, height_cm, film=10):
spec = item([placement(0, 0, film, height_cm)], [source(film, height_cm)], height_cm, film=film)
spec['production']['sources'][0]['kind'] = 'sheet'
return spec
def test_a_ready_sheet_is_cut_in_a_clear_band_not_through_the_art(self):
# Marcus, 2026-11-27, #136: one ready sheet is one piece to the layout;
# the cut finds the clear band in its pixels (30 to 31 cm) under 35 cm.
sheet = Image.new('RGBA', (px(10), px(40)), (220, 30, 60, 255))
sheet.paste((0, 0, 0, 0), (0, px(30), px(10), px(31)))
parts, detail = self.render(self.sheet_spec(40), [self.save(sheet, 'sheet.png')], part_cm=35)
cut = float(detail['parts'][0]['to_cm'])
self.assertTrue(30 < cut < 31, cut)
first = Image.open(parts[0][0]).convert('RGBA')
self.assertEqual(first.getpixel((10, first.height - 2))[3], 0) # ends in the clear band
def test_a_packed_sheet_is_cut_in_its_widest_clear_band(self):
# A sheet packed edge to edge (#83: 2 mm at most between rows): the
# widest clear band, here 2 mm between dots, still cuts no ink.
sheet = Image.new('RGBA', (px(10), px(40)), (220, 30, 60, 255))
sheet.paste((0, 0, 0, 0), (0, px(30), px(10), px(31)))
dots = [px(30 + tenth / 10) for tenth in range(1, 10, 2)] # a dot every 2 mm
for row in dots:
sheet.putpixel((px(5), row), (0, 0, 0, 255))
_, detail = self.render(self.sheet_spec(40), [self.save(sheet, 'sheet.png')], part_cm=35)
cut = px(float(detail['parts'][0]['to_cm']))
self.assertTrue(px(30) < cut < px(31) and cut not in dots, cut)
def test_without_any_clear_row_the_cut_takes_the_least_ink(self):
sheet = Image.new('RGBA', (px(10), px(40)), (220, 30, 60, 255))
sheet.paste((0, 0, 0, 0), (px(1), px(32), px(10), px(32) + 3)) # only a thin edge of ink there
_, detail = self.render(self.sheet_spec(40), [self.save(sheet, 'sheet.png')], part_cm=35)
self.assertTrue(px(32) <= px(float(detail['parts'][0]['to_cm'])) < px(32) + 3, detail['parts'][0])
def test_pieces_for_the_viewer_come_with_the_file(self):
art = quadrants(118, 59, alpha=True)
spec = item([placement(0, 0, 1, 0.5)], [source(1, 0.5)], 0.5)

View File

@@ -48,8 +48,9 @@ class RenderLimitTests(unittest.TestCase):
return {'production': {'height_cm': height, 'placements': [
{'y_cm': 0, 'length_cm': height, 'source_index': 0}]}}
self.assertEqual(render_seconds(film(800)), RENDER_SECONDS)
self.assertEqual(render_seconds(film(2359.2)), 2 * RENDER_SECONDS)
self.assertEqual(render_seconds(film(4600)), 4 * RENDER_SECONDS)
# A film in parts gets one part more: a cut moved to a clear band (#136).
self.assertEqual(render_seconds(film(2359.2)), 3 * RENDER_SECONDS)
self.assertEqual(render_seconds(film(4600)), 5 * RENDER_SECONDS)
self.assertEqual(render_seconds({'mode': 'file'}), RENDER_SECONDS)