Preserve W21 NoPictures parity and repeatability source proposal

This commit is contained in:
selune committed 2026-10-30 08:30:35 +01:00
1 parent 7d66a4d0ab
commit c46fd3acd4
3 files changed
+135

No files matched your search

@@ -0,0 +1,12 @@
# W21 NoPictures export acceptance — source-only continuation
The original three-test increment is preserved here for the agreed contribution to [#7591](https://github.com/tangency-labs/solidcraft/pull/7591), under [Cam’s test-file handoff](https://github.com/tangency-labs/solidcraft/issues/4890#issuecomment-6503678820). This is a source archive, not the stacked implementation PR or completed W21 delivery.
Receiver checked 30 October 2026: `5ddde8e23a86c530f2b4d2395980e3f7b88048ae`, `crates/io/src/paper/png_tests.rs` blob `39e4bc69c53f4cefe1f6b4cba8a23ec29af93502`. Only this existing test file is affected. Its complete original bytes and 14 tests stay intact. The two original NoPictures parity tests are unchanged; one new determinism test reuses each Prepared across both real writers, reversing call order on repeats. The separate three picture proposals are excluded. No Scene, Prepared, Grid, exporter implementation or dependency changes.
The absolute tests check preplaced 50/25 mm paper lengths and 0.2 mm stroke widths at 254 DPI, plus outward rounding and partial edges on a 100.08 × 80.08 mm sheet. Expected values come from authored paper geometry. Repeatability compares complete encoded SVG/PNG bytes and reports, separately from those geometry assertions. This does not test model projection, rasterize SVG, or qualify pictures, dashes, text, clipping or all of W21.
Independent source review found no actionable blocker within this scope. Patch reconstruction and byte-prefix preservation were checked. **Three new / seventeen total test declarations; not compiled or run.** No result from D8 or the render build qualifies this source. The agreed stacked draft, exact-source sole-builder registration/execution and applicable repository checks remain pending. Existing contributor ownership and the single build queue are preserved.
Patch SHA-256: `48c3d33ca4a225f7f8a1b33d90accb62ebc8976e829d20538adaad56f0176540`.
Expected candidate-file SHA-256: `893c9d6a62b192dae8b5cb1fb7415e920d3afb3a8f9a6056cb3c8d57ae13d833`.
@@ -0,0 +1,3 @@
paper::png::tests::svg_and_png_keep_mixed_scale_paper_lengths_and_fixed_width
paper::png::tests::svg_and_png_keep_fractional_sheet_edges_on_the_outward_grid
paper::png::tests::svg_and_png_repeat_the_same_prepared_scene_byte_for_byte
@@ -0,0 +1,120 @@
--- a/crates/io/src/paper/png_tests.rs
+++ b/crates/io/src/paper/png_tests.rs
@@ -426,3 +426,117 @@
pictured(&scene(p(20.0, 10.0), vec![picture(1, p(30.0, 30.0), p(40.0, 40.0), 1.0)]), RGB_254, &provider);
assert!(provider.asked.borrow().is_empty());
}
+
+/// One authored 100 mm length is already placed on paper at 1:2 and 1:4.
+/// These are consumer fixtures, not a model-view transform or a new view kind.
+fn mixed_scale_paper_pair() -> Scene {
+ Scene {
+ size_mm: p(100.0, 80.0),
+ groups: [(101, p(10.0, 20.0), p(60.0, 20.0)), (202, p(10.0, 40.0), p(35.0, 40.0))]
+ .into_iter()
+ .map(|(object, a, b)| Group {
+ object,
+ kind: ObjectKind::DrawingBorder,
+ items: vec![Item::Stroke { path: vec![line(a, b)], closed: false, width_mm: 0.2 }],
+ })
+ .collect(),
+ }
+}
+
+/// Both real writers consume this same checked scene; no picture source is needed.
+fn svg_png_pair(scene: &Scene) -> (String, Image, PngReport) {
+ let prepared = scene.prepare().unwrap();
+ let (svg, svg_report) = crate::paper::paper_svg(&prepared, &NoPictures, 300.0).unwrap();
+ let mut png = Vec::new();
+ let png_report = paper_png(&prepared, AT_254, &NoPictures, &mut png).unwrap();
+ assert_eq!(svg_report, png_report.grid, "both consumers use the same number-grid rules");
+ let image = read(&png);
+ assert_eq!((image.info.color_type, image.info.bit_depth), (png::ColorType::Grayscale, png::BitDepth::Eight));
+ (String::from_utf8(svg).unwrap(), image, png_report)
+}
+
+/// 254 dpi is 10 px/mm: 50/25 mm occupy 500/250 px while both 0.2 mm widths stay 2 px.
+/// All coordinates are hand-derived from the preplaced fixture, not recorded output.
+#[test]
+fn svg_and_png_keep_mixed_scale_paper_lengths_and_fixed_width() {
+ let (svg, image, report) = svg_png_pair(&mixed_scale_paper_pair());
+ assert!(svg.contains("width=\"100mm\" height=\"80mm\" viewBox=\"0 0 100 80\""));
+ assert_eq!(svg.matches("<g data-object=").count(), 2);
+ assert_eq!(svg.matches("<path ").count(), 2);
+ for path in [
+ "<path stroke-width=\"0.2\" d=\"M10 60L60 60\"/>",
+ "<path stroke-width=\"0.2\" d=\"M10 40L35 40\"/>",
+ ] {
+ assert_eq!(svg.matches(path).count(), 1, "{path}");
+ }
+ let first = svg.find("<g data-object=\"101\" data-kind=\"drawing_border\">").unwrap();
+ let second = svg.find("<g data-object=\"202\" data-kind=\"drawing_border\">").unwrap();
+ assert!(first < second, "group order is retained");
+ assert_eq!(report.pixels, [1000, 800]);
+ assert_eq!((image.info.width, image.info.height), (1000, 800));
+ // Butt ends are [100,600) and [100,350). After the y flip, their two complete
+ // black rows are 599/600 and 399/400. Every other pixel is white.
+ for y in 0..800 {
+ for x in 0..1000 {
+ let ink = ((599..601).contains(&y) && (100..600).contains(&x)) || ((399..401).contains(&y) && (100..350).contains(&x));
+ assert_eq!(image.at(x, y), if ink { &[0][..] } else { &[255][..] }, "pixel ({x},{y})");
+ }
+ }
+}
+
+/// The vector sheet is exactly 100.08 by 80.08 mm. At 254 dpi its 1000.8 by
+/// 800.8 pixel extent needs an outward 1001 by 801 image. Ink reaches both last
+/// partial pixels; rounding away that row/column or moving the origin loses it.
+#[test]
+fn svg_and_png_keep_fractional_sheet_edges_on_the_outward_grid() {
+ let sheet = scene(
+ p(100.08, 80.08),
+ vec![Item::Fill { region: Region2 { outer: rectangle(p(99.0, 0.0), p(100.08, 1.0)), holes: vec![] } }],
+ );
+ let (svg, image, report) = svg_png_pair(&sheet);
+ assert!(svg.contains("width=\"100.08mm\" height=\"80.08mm\" viewBox=\"0 0 100.08 80.08\""));
+ assert_eq!(svg.matches("<path ").count(), 1);
+ assert!(svg.contains("<path fill=\"#000\" stroke=\"none\" fill-rule=\"evenodd\" d=\"M99 80.08L100.08 80.08L100.08 79.08L99 79.08Z\"/>"));
+ assert_eq!(report.pixels, [1001, 801]);
+ assert_eq!((image.info.width, image.info.height), (1001, 801));
+ assert_eq!(image.at(995, 795), [0], "inside the fill");
+ assert_eq!(image.at(989, 795), [255], "left of the fill");
+ assert_eq!(image.at(995, 789), [255], "above the fill");
+ // The last column/row have 0.8 coverage and the corner 0.64. They are
+ // partial dark pixels, not fully black and not white; no exact AA byte is
+ // assumed. The existing PNG tests use the same mid-grey ink distinction.
+ for (x, y) in [(1000, 795), (995, 800), (1000, 800)] {
+ let grey = image.at(x, y)[0];
+ assert!(grey > 0 && grey < 128, "ink in the last partial pixel ({x},{y}): {grey}");
+ }
+ let top = image.at(995, 790)[0];
+ assert!(top > 128 && top < 255, "the first partial row has only 0.2 coverage: {top}");
+}
+
+/// Reusing one Prepared must not make either exporter depend on prior traversal.
+/// Compare whole encoded files as well as reports, for both exact and outward-rounded sheets.
+#[test]
+fn svg_and_png_repeat_the_same_prepared_scene_byte_for_byte() {
+ for sheet in [
+ mixed_scale_paper_pair(),
+ scene(
+ p(100.08, 80.08),
+ vec![Item::Fill { region: Region2 { outer: rectangle(p(99.0, 0.0), p(100.08, 1.0)), holes: vec![] } }],
+ ),
+ ] {
+ let prepared = sheet.prepare().unwrap();
+ let (svg, svg_report) = crate::paper::paper_svg(&prepared, &NoPictures, 300.0).unwrap();
+ let mut png = Vec::new();
+ let png_report = paper_png(&prepared, AT_254, &NoPictures, &mut png).unwrap();
+ assert_eq!(svg_report, png_report.grid);
+ for _ in 0..2 {
+ let mut repeated_png = Vec::new();
+ let repeated_png_report = paper_png(&prepared, AT_254, &NoPictures, &mut repeated_png).unwrap();
+ let (repeated_svg, repeated_svg_report) = crate::paper::paper_svg(&prepared, &NoPictures, 300.0).unwrap();
+ assert_eq!(repeated_svg, svg);
+ assert_eq!(repeated_png, png);
+ assert_eq!(repeated_svg_report, svg_report);
+ assert_eq!(repeated_png_report, png_report);
+ }
+ }
+}