From dc956060f8ca68009166c7fca0546090a9fe236d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 12 Nov 2026 17:52:23 -0800 Subject: [PATCH] 3D: the bevels file stops cutting a path once it passes the point limit A bevel's path is cut into straight lines one segment at a time, and the reader stops at the segment that passes 8,192 points, so a detailed symbol is skipped without cutting the rest of its path. --- crates/engine/src/cmd/bevels.rs | 25 ++++++++++++++++++------- crates/engine/src/tests/bevels.rs | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/bevels.rs b/crates/engine/src/cmd/bevels.rs index f36082862e..efe662b332 100644 --- a/crates/engine/src/cmd/bevels.rs +++ b/crates/engine/src/cmd/bevels.rs @@ -145,14 +145,25 @@ fn points_of(n: &Node) -> std::result::Result, &'static str> { return Err("its path has too many anchors for a bevel"); } let mut line: Vec = vec![]; - let mut too_many = false; let tolerance = path.bounds().map_or(1.0, |b| b.width().hypot(b.height()) / 2000.0).max(1e-9); - vectorcraft_geom::flatten(path.to_bezpath().elements().iter().copied(), tolerance, |el| match el { - PathEl::MoveTo(p) | PathEl::LineTo(p) if line.len() < MAX_LINE_POINTS => line.push(p), - PathEl::MoveTo(_) | PathEl::LineTo(_) => too_many = true, - _ => {} - }); - if too_many { + // One segment at a time, so a path past the limit stops being cut at the segment that passes it. + let mut at: Option = None; + for &el in path.to_bezpath().elements() { + if line.len() > MAX_LINE_POINTS { + return Err("its path is too detailed for a bevel"); + } + match (el, at) { + (PathEl::MoveTo(p), _) => line.push(p), + (_, Some(start)) => vectorcraft_geom::flatten([PathEl::MoveTo(start), el], tolerance, |e| { + if let PathEl::LineTo(p) = e { + line.push(p); + } + }), + (_, None) => {} + } + at = el.end_point().or(at); + } + if line.len() > MAX_LINE_POINTS { return Err("its path is too detailed for a bevel"); } let (Some(&first), Some(&last)) = (line.first(), line.last()) else { return Err("its path has no length") }; diff --git a/crates/engine/src/tests/bevels.rs b/crates/engine/src/tests/bevels.rs index 4540ae9654..5314ce5b00 100644 --- a/crates/engine/src/tests/bevels.rs +++ b/crates/engine/src/tests/bevels.rs @@ -102,6 +102,28 @@ fn curves_and_long_paths_fit_in_the_points_a_bevel_holds() { assert!(arc.points.iter().all(|&(x, y)| (((x - 0.0).powi(2) + (y - 1.0).powi(2)).sqrt() - 1.0).abs() < 0.01), "{:?}", arc.points); } +/// A path of many tall curves, cut into more straight lines than a bevel's path may take, is +/// skipped as too detailed. +#[test] +fn a_path_cut_into_too_many_lines_is_skipped() { + let mut d = Document::new(100.0, 100.0); + let anchors: Vec = (0..4000) + .map(|i| { + let p = Point::new(f64::from(i), f64::from(i) / 4.0); + let swing = if i % 2 == 0 { 1000.0 } else { -1000.0 }; + let mut a = Anchor::corner(p); + a.h_in = Point::new(p.x - 0.5, p.y - swing); + a.h_out = Point::new(p.x + 0.5, p.y + swing); + a + }) + .collect(); + let wild = Node::path(NodeId(0), PathData::single(SubPath::new(anchors, false)), Appearance::default()); + add_symbol(&mut d, "Wild", wild); + let read = bevels_of(&d); + assert!(read.bevels.is_empty()); + assert_eq!(read.skipped, [("Wild".to_string(), "its path is too detailed for a bevel".to_string())]); +} + fn rect(s: &mut Session, x: u32) -> NodeId { NodeId(s.execute("shape.rectangle", &json!({"x": x, "y": 100, "width": 60, "height": 60})).unwrap()["id"].as_u64().unwrap()) }