mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 12:38:18 +00:00
Render: RenderOptions::hidden is a set, so each hidden check is one lookup
RenderOptions::hidden was a Vec<NodeId>, and the renderer checked each node it visits against it with contains (node_checks::left_out and Renderer::draw_node), so every check could compare against all k hidden ids. The Fold Preview print hides every non-printing layer and, with Show Fold Lines off, every object with a line role. hidden is now a HashSet<NodeId>, so each check is one hash lookup. The Fold Preview collects print_hidden's list into the set, and two tests that built the field with vec! build it from an array. The field's doc comment now names the Fold Preview print as its example. New test a_render_leaves_out_every_object_of_a_large_hidden_set renders 2,000 strips with 1,000 of them in hidden and checks every strip's pixel. It checks that hiding still works for a large set; the old Vec drew the same pixels, so the test does not fail at run time without the change.
This commit is contained in:
@@ -1010,7 +1010,7 @@ fn an_edit_out_of_sight_builds_nothing() {
|
||||
let drawn_hidden = extruded(&mut d, 70.0);
|
||||
let ids = [d.insert(Some(l), 0, hidden).unwrap(), group.children().unwrap()[0].id, d.insert(Some(l), 0, drawn_hidden).unwrap()];
|
||||
d.insert(Some(l), 0, group).unwrap();
|
||||
let opts = RenderOptions { hidden: vec![ids[2]], ..Default::default() };
|
||||
let opts = RenderOptions { hidden: [ids[2]].into(), ..Default::default() };
|
||||
let mut r = Renderer::new();
|
||||
r.render(&d, 100, 100, Affine::IDENTITY, &opts);
|
||||
let mut e = d.clone();
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use super::geometry::region_pixels;
|
||||
use super::{Arc, NodeId, Rect, encode, proof};
|
||||
|
||||
@@ -39,8 +41,8 @@ pub struct RenderOptions {
|
||||
pub background: Option<[u8; 4]>,
|
||||
/// Draw artboards as white rectangles (screen view). Export sets this to false.
|
||||
pub artboards: bool,
|
||||
/// Objects not to draw (e.g. the object being edited by a live drag preview).
|
||||
pub hidden: Vec<NodeId>,
|
||||
/// Objects not to draw (e.g. the layers and fold lines the Fold Preview's print leaves out).
|
||||
pub hidden: HashSet<NodeId>,
|
||||
/// Draw the layers as their Layer Options show them on screen: Preview off in outline, Dim
|
||||
/// Images fading their images (a template layer's too), a template in Preview in Outline view.
|
||||
pub dim_templates: bool,
|
||||
@@ -194,7 +196,7 @@ impl Default for RenderOptions {
|
||||
outline: false,
|
||||
background: None,
|
||||
artboards: false,
|
||||
hidden: vec![],
|
||||
hidden: HashSet::new(),
|
||||
dim_templates: true,
|
||||
proof: None,
|
||||
overprint_preview: false,
|
||||
|
||||
@@ -224,6 +224,33 @@ fn hidden_and_culled() {
|
||||
assert_eq!(rr.stats.culled, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_render_leaves_out_every_object_of_a_large_hidden_set() {
|
||||
// 2,000 one-pixel-wide strips; the strips in even columns are in `hidden`.
|
||||
let mut d = Document::new(100.0, 100.0);
|
||||
let l = d.layers[0].id;
|
||||
let mut hidden = std::collections::HashSet::new();
|
||||
for row in 0..20 {
|
||||
for col in 0..100 {
|
||||
let r = Rect::new(f64::from(col), f64::from(row * 5), f64::from(col + 1), f64::from(row * 5 + 5));
|
||||
let n = rect_node(&mut d, r, Paint::solid(Color::BLACK), Paint::None, 0.0);
|
||||
let id = d.insert(Some(l), usize::MAX, n).unwrap();
|
||||
if col % 2 == 0 {
|
||||
hidden.insert(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_eq!(hidden.len(), 1_000);
|
||||
let opts = RenderOptions { hidden, ..Default::default() };
|
||||
let r = Renderer::new().render(&d, 100, 100, Affine::IDENTITY, &opts);
|
||||
for row in 0..20 {
|
||||
for col in 0..100 {
|
||||
let want = if col % 2 == 0 { [0, 0, 0, 0] } else { [0, 0, 0, 255] };
|
||||
assert_eq!(r.pixel(col, row * 5 + 2), want, "column {col}, row {row}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A document with symbol "Far" holding a red rectangle `art`, and an instance of it moved by
|
||||
/// (-50, -50): its 20 × 20 square, (-60, -60) to (-40, -40), lies outside a view of the page.
|
||||
fn far_instance(art: Rect) -> Document {
|
||||
|
||||
@@ -473,7 +473,7 @@ fn invisible_and_hidden_nodes_are_not_drawn() {
|
||||
let mut b = DocBuilder::new(100.0, 100.0);
|
||||
let id = b.rect(Rect::new(0.0, 0.0, 100.0, 100.0), Color::BLACK, |_| {});
|
||||
let d = b.build();
|
||||
let opts = vectorcraft_render::RenderOptions { background: Some([255, 255, 255, 255]), hidden: vec![id], ..Default::default() };
|
||||
let opts = vectorcraft_render::RenderOptions { background: Some([255, 255, 255, 255]), hidden: [id].into(), ..Default::default() };
|
||||
let r = vectorcraft_render::Renderer::new().render(&d, 100, 100, vectorcraft_geom::Affine::IDENTITY, &opts);
|
||||
assert_eq!(Image::from_rendered(&r).ink(), 0);
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ impl Cache {
|
||||
let opts = vectorcraft_render::RenderOptions {
|
||||
skip_templates: true,
|
||||
image_mips: true,
|
||||
hidden: vectorcraft_engine::cmd::print_hidden(doc, key.fold_lines),
|
||||
hidden: vectorcraft_engine::cmd::print_hidden(doc, key.fold_lines).into_iter().collect(),
|
||||
..Default::default()
|
||||
};
|
||||
if let Some(w) = &self.worker {
|
||||
|
||||
Reference in New Issue
Block a user