mirror of
https://github.com/storytold/cadcraft.git
synced 2026-11-30 17:53:00 -06:00
render: say when clipped attributes or parallel parts are left out (#1603)
Review on #3594: - The XCLIP attribute part's `truncated` flag now reaches the parent list, as the block-contents part's already did. A clipped reference whose attributes ran out of budget as the last object of a drawing drew 98 of 105 points and said nothing. - The parts of a parallel build are joined within the list limits (Builder::join). Clipped copies are in no shared count, so two XCLIP'd blocks in different parts could join to 798 primitives against a limit of 748, unmarked. Parts are appended whole while they fit; at the first that doesn't, the build is spent and marked truncated. This is native-only: the web build has no parallel path. Part of #1603. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3771719811
commit
09f025ede3
@@ -125,6 +125,7 @@ pub(crate) fn insert(b: &mut Builder, ctx: &Ctx, e: &Entity, ins: &cadcraft_doc:
|
||||
let mut part = attr_clip.as_ref().map(|_| b.part());
|
||||
attributes(part.as_mut().unwrap_or(&mut *b), ctx, e, ins, rgb, own);
|
||||
if let (Some(part), Some((region, inverted))) = (part, &attr_clip) {
|
||||
b.list.truncated |= part.list.truncated;
|
||||
let limits = b.limits();
|
||||
if !append_clipped_keep(&mut b.list, &part.list, &if *inverted { Clip::Outside(region) } else { Clip::Poly(region) }, limits) {
|
||||
b.spend();
|
||||
|
||||
@@ -464,6 +464,23 @@ impl<'a> Builder<'a> {
|
||||
fn limits(&self) -> Limits {
|
||||
Limits { points: self.max_points, prims: self.max_prims }
|
||||
}
|
||||
/// Join the parts of a list built on all cores to this builder's list, in drawing order and
|
||||
/// within its limits ([`Limits`]): the clipped copies a part holds are in no count, so the
|
||||
/// parts can hold more together than one list may. At the first part that doesn't fit the build
|
||||
/// is spent and the parts left are not joined.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn join(&mut self, parts: Vec<DisplayList>) {
|
||||
let points = |l: &DisplayList| l.verts.len().saturating_add(l.tris.len());
|
||||
for part in parts {
|
||||
if self.list.prims.len().saturating_add(part.prims.len()) > self.max_prims
|
||||
|| points(&self.list).saturating_add(points(&part)) > self.max_points
|
||||
{
|
||||
self.spend();
|
||||
return;
|
||||
}
|
||||
display::append(&mut self.list, part);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The clip boundary of image `i` as a closed outline, or `None` when the whole image shows.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use super::display::append;
|
||||
use super::display::{DisplayList, Kind, NO_LAYER, PlotText, VIEWPORT_CONTENT};
|
||||
use super::draw::entity;
|
||||
use super::viewports::{MAX_VIEWPORTS, viewport};
|
||||
@@ -196,13 +194,11 @@ fn build_parallel(b: &mut Builder, d: &Drawing, store: &cadcraft_doc::EntityStor
|
||||
part.list
|
||||
})
|
||||
.collect();
|
||||
// One allocation per array for the joined list.
|
||||
b.list.prims.reserve(parts.iter().map(|p| p.prims.len()).sum());
|
||||
b.list.verts.reserve(parts.iter().map(|p| p.verts.len()).sum());
|
||||
b.list.tris.reserve(parts.iter().map(|p| p.tris.len()).sum());
|
||||
for part in parts {
|
||||
append(&mut b.list, part);
|
||||
}
|
||||
// One allocation per array for the joined list, within what it may hold.
|
||||
b.list.prims.reserve(parts.iter().map(|p| p.prims.len()).sum::<usize>().min(b.max_prims));
|
||||
b.list.verts.reserve(parts.iter().map(|p| p.verts.len()).sum::<usize>().min(b.max_points));
|
||||
b.list.tris.reserve(parts.iter().map(|p| p.tris.len()).sum::<usize>().min(b.max_points));
|
||||
b.join(parts);
|
||||
}
|
||||
|
||||
/// The plot style table a build draws with: the one in `opts`, else (on screen) the layout's
|
||||
|
||||
@@ -1667,3 +1667,61 @@ fn pieces_cut_by_a_clip_stop_at_the_list_limits_and_say_so() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A block reference clipped (XCLIP, frame off) to a large rectangle, of block "Z" holding `kind`.
|
||||
fn xclipped_ref(d: &mut Drawing, kind: EntityKind, at: Vec3) -> EntityKind {
|
||||
if d.block("Z").is_none() {
|
||||
let mut blk = cadcraft_doc::Block::new("Z");
|
||||
blk.entities.push(block_entity(1, Common::default(), kind));
|
||||
d.blocks.insert("Z".into(), std::sync::Arc::new(blk));
|
||||
}
|
||||
let EntityKind::Insert(mut ins) = insert_of("Z") else { panic!("an insert") };
|
||||
ins.insert = at;
|
||||
ins.clip = Some(cadcraft_doc::ClipBoundary::new(vec![Vec2::new(-100.0, 1.0), Vec2::new(100.0, 100.0)]));
|
||||
EntityKind::Insert(ins)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attributes_cut_by_a_clip_say_what_the_budget_left_out() {
|
||||
// The last object of the drawing: a clipped reference whose attribute text runs out of points.
|
||||
let mut d = Drawing::new_imperial();
|
||||
d.header.set_i64("XCLIPFRAME", 0);
|
||||
let kind = xclipped_ref(&mut d, line_common(Common::default()).1, Vec3::ZERO);
|
||||
let EntityKind::Insert(mut ins) = kind else { panic!("an insert") };
|
||||
let mut a = attrib("TAG");
|
||||
a.text.insert = Vec3::new(1.0, 2.0, 0.0);
|
||||
a.text.value = "ABCDEFGHIJKLMNOP".into();
|
||||
ins.attribs.push(a);
|
||||
d.add(&Space::Model, Common::default(), EntityKind::Insert(ins)).unwrap();
|
||||
let build = |max_points| crate::pipeline::build_space_within(&d, &Space::Model, &Options::default(), false, max_points, MAX_DISPLAY_PRIMS);
|
||||
let full = build(MAX_DISPLAY_POINTS);
|
||||
assert!(!full.truncated && points(&full) > 20, "{}", points(&full));
|
||||
let l = build(points(&full) - 1);
|
||||
assert!(l.truncated && points(&l) < points(&full), "{} of {}", points(&l), points(&full));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parts_built_on_all_cores_are_joined_within_the_list_limits() {
|
||||
// Two clipped zigzags in different parts of the parallel build: each part fits the list's
|
||||
// limits and the build's counts, which hold the zigzags and not their pieces; together they
|
||||
// don't fit.
|
||||
let mut d = Drawing::new_imperial();
|
||||
d.header.set_i64("XCLIPFRAME", 0);
|
||||
for i in 0..600 {
|
||||
let kind = if i == 0 || i == 300 { xclipped_ref(&mut d, zigzag(), Vec3::ZERO) } else { point_at(f64::from(i)) };
|
||||
d.add(&Space::Model, Common::default(), kind).unwrap();
|
||||
}
|
||||
let build = |max_points, max_prims| crate::pipeline::build_space_within(&d, &Space::Model, &Options::default(), false, max_points, max_prims);
|
||||
let full = build(MAX_DISPLAY_POINTS, MAX_DISPLAY_PRIMS);
|
||||
assert!(!full.truncated && full.prims.len() > 700 && points(&full) > 1000, "{} prims, {} points", full.prims.len(), points(&full));
|
||||
let max = full.prims.len() - 50;
|
||||
let l = build(MAX_DISPLAY_POINTS, max);
|
||||
assert!(l.truncated && l.prims.len() <= max, "{} of {max}", l.prims.len());
|
||||
let max = points(&full) - 50;
|
||||
let l = build(max, MAX_DISPLAY_PRIMS);
|
||||
assert!(l.truncated && points(&l) <= max, "{} of {max}", points(&l));
|
||||
// Exactly as much as the parts hold is joined whole.
|
||||
for l in [build(MAX_DISPLAY_POINTS, full.prims.len()), build(points(&full), MAX_DISPLAY_PRIMS)] {
|
||||
assert!(!l.truncated && l.prims.len() == full.prims.len(), "{} of {}", l.prims.len(), full.prims.len());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use super::display::append;
|
||||
use super::display::{DImage, DPrim, DisplayList, Kind, NO_LAYER, PlotText, VIEWPORT_CONTENT};
|
||||
use super::draw::entity;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -174,9 +172,7 @@ fn contents(b: &mut Builder, d: &Drawing, vp: &cadcraft_doc::Viewport, area: Bou
|
||||
part.list
|
||||
})
|
||||
.collect();
|
||||
for part in parts {
|
||||
append(&mut sub.list, part);
|
||||
}
|
||||
sub.join(parts);
|
||||
}
|
||||
} else {
|
||||
let c = ctx();
|
||||
|
||||
Reference in New Issue
Block a user