3D and Materials: test the 16-image limit and the shared pixel limit when rendered 3D draws

Adds tests that draw a see-through object whose two images each fit the
pixel limit alone but not together, and one with 16 and 17 see-through
fills, so removing the shared limit or the image cap fails a test. The
white-background test now uses a see-through solid past the pixel limit
and compares its fallback with the same object in shaded mode.
This commit is contained in:
dotCooCoo committed 2026-12-05 15:20:49 -08:00
1 parent f033a17bd0
commit cb63a90ca3
1 file changed
+70 -4
+70 -4
View File
@@ -718,15 +718,20 @@ fn a_solid_at_zero_opacity_does_not_widen_the_image() {
assert!(width(0.0) < 200.0, "the member at 0% is left out: {}", width(0.0));
}
/// With `background: white`, a large drawn solid still exceeds the image's pixel limit.
/// With `background: white`, a see-through solid past the pixel limit reports it and draws the
/// shaded faces instead of its images.
#[test]
fn a_white_background_is_checked_when_a_large_solid_draws() {
fn a_large_see_through_solid_on_white_draws_the_shaded_faces() {
let doc = vectorcraft_doc::Document::new(400.0, 400.0);
let params = json!({"render": {"mode": "rendered", "quality": "low", "background": "white", "resolution": 2400}});
let mut n = solid_square(super::super::EXTRUDE, Color::rgb(0.2, 0.5, 0.8), params);
let mut n = inked(solid_square(super::super::EXTRUDE, Color::rgb(0.2, 0.5, 0.8), params), 0.5, Default::default());
n.kind = Node::path(NodeId(1), square(0.0, 0.0, 2000.0), Appearance::default()).kind;
assert_eq!(crate::rendered_warning(&doc, &n).as_deref(), Some(TOO_LARGE));
assert!(images(&drawn(&n)).is_empty());
let art = drawn(&n);
assert!(images(&art).is_empty());
let mut shaded = n.clone();
shaded.appearance.effects[0].params["render"]["mode"] = json!("shaded");
assert_eq!(art, drawn(&shaded), "the shaded faces draw");
}
/// Solids that all draw nothing measure nothing: painted bounds take no image rectangle.
@@ -766,6 +771,67 @@ fn layered_images_share_the_pixel_limit() {
assert!(measure(&meshes, &lighting, MEDIUM, 72.0, false, &shared_limits(&limits, 5)).is_err());
}
/// A Rotate square with one fill, rendered at Low quality at `resolution` ppi.
fn rotated_square(size: f64, resolution: f64) -> Node {
let mut n = Node::path(NodeId(1), square(100.0, 100.0, size), Appearance::basic(Paint::solid(Color::rgb(0.2, 0.5, 0.8)), Paint::None, 0.0));
let params = json!({"render": {"mode": "rendered", "quality": "low", "resolution": resolution}});
n.appearance.effects.push(crate::new_effect(super::super::ROTATE, &params).unwrap());
n
}
/// Drawing shares the pixel limit among the images: an object whose one image fits the limit draws
/// the shaded faces once a second, see-through fill makes it two images of the same size.
#[test]
fn drawn_images_share_the_pixel_limit() {
let doc = vectorcraft_doc::Document::new(400.0, 400.0);
let pixels = |resolution: f64| {
let (meshes, lighting) = scene_of(&rotated_square(200.0, resolution));
let settings = RenderSettings { quality: 0, resolution: Some(resolution), white: false };
let m = measure(&meshes, &lighting, settings, 72.0, false, &Limits::default()).unwrap();
u64::from(m.cols) * u64::from(m.rows)
};
let max = Limits::default().max_pixels;
let resolution = (72.0 * (0.75 * max as f64 / pixels(72.0) as f64).sqrt()).round();
let size = pixels(resolution);
assert!(size > max / 2 && size <= max, "{size} pixels at {resolution} ppi");
let one = rotated_square(200.0, resolution);
assert_eq!(crate::rendered_warning(&doc, &one), None, "one image of {size} pixels fits");
let mut two = one.clone();
let mut faint = two.appearance.items[0].clone();
if let vectorcraft_doc::AppearanceItem::Fill(f) = &mut faint {
f.opacity = 0.5;
}
two.appearance.items.push(faint);
assert_eq!(crate::rendered_warning(&doc, &two).as_deref(), Some(TOO_LARGE), "two images of {size} pixels");
let art = drawn(&two);
assert!(images(&art).is_empty(), "two images of {size} pixels draw the shaded faces");
assert!(faces_bounds(&art).is_some());
}
/// An object draws at most 16 images: 16 see-through fills draw 16, and a 17th draws the shaded
/// faces instead.
#[test]
fn more_than_sixteen_images_draw_the_shaded_faces() {
let doc = vectorcraft_doc::Document::new(400.0, 400.0);
let fills = |count: usize| {
let mut n = rotated_square(20.0, 72.0);
let mut faint = n.appearance.items[0].clone();
if let vectorcraft_doc::AppearanceItem::Fill(f) = &mut faint {
f.opacity = 0.5;
}
n.appearance.items = vec![faint; count];
n
};
let sixteen = fills(16);
assert_eq!(crate::rendered_warning(&doc, &sixteen), None);
assert_eq!(image_nodes(&drawn(&sixteen)).len(), 16);
let seventeen = fills(17);
assert_eq!(crate::rendered_warning(&doc, &seventeen).as_deref(), Some(TOO_LARGE));
let art = drawn(&seventeen);
assert!(images(&art).is_empty(), "17 images draw the shaded faces");
assert!(faces_bounds(&art).is_some());
}
/// A loaded file whose `render` breaks the rules draws the shaded faces.
#[test]
fn an_invalid_loaded_render_draws_shaded() {