From 3b4530af42824c7919eec081d21d7490a429cdbf Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 23:43:37 -0800 Subject: [PATCH] DXF/DWG import: close pattern lines far apart draw; far gradients keep their fill - Pattern line spacings and dash periods are refused only when they are below the precision of the boundary's coordinates, or when the lines and dashes that actually cross the boundary exceed the per-hatch limits. Two small areas far apart no longer refuse a fine pattern. - A line family based far from the boundary is moved to the line nearest it by whole offsets (and its dashes by whole periods), so its line indices fit and each line keeps its dash phase. - A dot that ends the period before a span's start is drawn on the span's start. - A pattern of dashes and dots is checked for every object and path point it makes before either path is made, and charges nothing when it is left out. - A gradient hatch whose gradient reaches past the coordinate limit keeps its gradient when its boundary is in range; a gradient that cannot be placed becomes a solid fill. - The dense-pattern warning and docs/mcp.md name the edge and work limits, and docs/mcp.md says when island styles fall back to filling every loop. - Tests check which loops each island style keeps and that a block's boundary fallback takes each insert's linetype. - Fixes the clippy cloned_ref_to_slice_refs error in the hatch tests. --- crates/cad/src/import/build.rs | 80 ++++++++++++++++++++++-- crates/cad/src/import/entity.rs | 28 ++++++--- crates/cad/src/import/hatch.rs | 105 +++++++++++++++++++++++++++----- crates/cad/src/import/tests.rs | 86 ++++++++++++++++++++++++-- docs/mcp.md | 7 ++- 5 files changed, 272 insertions(+), 34 deletions(-) diff --git a/crates/cad/src/import/build.rs b/crates/cad/src/import/build.rs index b1e6683061..82d2a6deb9 100644 --- a/crates/cad/src/import/build.rs +++ b/crates/cad/src/import/build.rs @@ -538,15 +538,17 @@ impl<'d, 'a> Build<'d, 'a> { return self.path(bp, Look::Pattern { dots: false }, 0.0, p, map, inh); } let (mut dashes, mut points) = (BezPath::new(), BezPath::new()); + let (mut dash_count, mut dot_count) = (0usize, 0usize); let mut from = None; for el in bp.elements() { match *el { PathEl::MoveTo(a) => from = Some(a), PathEl::LineTo(b) => { if let Some(a) = from { - let out = if a == b { &mut points } else { &mut dashes }; + let (out, count) = if a == b { (&mut points, &mut dot_count) } else { (&mut dashes, &mut dash_count) }; out.move_to(a); out.line_to(b); + *count += 1; } } _ => {} @@ -558,13 +560,25 @@ impl<'d, 'a> Build<'d, 'a> { if points.elements().is_empty() { return self.path(&dashes, Look::Pattern { dots: false }, 0.0, p, map, inh); } - // The two paths are objects of their own inside the group that `item` counts. - if self.nodes.saturating_add(2) >= MAX_NODES { + // Every object the split makes: the group (`item` counts it), the two paths, and each + // piece of a path with more than one (`path` counts those). + let loops = |count: usize| if count > 1 { count } else { 0 }; + if loops(dash_count).saturating_add(loops(dot_count)).saturating_add(3) > MAX_NODES.saturating_sub(self.nodes) { self.warn(TOO_MANY); return None; } - let lines = self.path(&dashes, Look::Pattern { dots: false }, 0.0, p, map, inh)?; - let dots = self.path(&points, Look::Pattern { dots: true }, 0.0, p, map, inh)?; + if dashes.elements().len().saturating_add(points.elements().len()) > MAX_ELEMENTS.saturating_sub(self.elements) { + self.warn(TOO_MANY_POINTS); + return None; + } + // A split that loses either path is left out whole, and charges nothing. + let (nodes, elements) = (self.nodes, self.elements); + let lines = self.path(&dashes, Look::Pattern { dots: false }, 0.0, p, map, inh); + let dots = lines.as_ref().and_then(|_| self.path(&points, Look::Pattern { dots: true }, 0.0, p, map, inh)); + let (Some(lines), Some(dots)) = (lines, dots) else { + (self.nodes, self.elements) = (nodes, elements); + return None; + }; self.nodes += 2; Some(Node::group(self.doc.alloc_id(), vec![Arc::new(lines), Arc::new(dots)])) } @@ -833,3 +847,59 @@ fn unique(base: &str, next: &mut HashMap, taken: &HashSet } } } + +#[cfg(test)] +mod tests { + use super::*; + + const EMPTY: &[u8] = b" 0\nSECTION\n 2\nENTITIES\n 0\nENDSEC\n 0\nEOF\n"; + + fn props() -> Props { + Props { + layer: "0".into(), + color: Col::Rgb([0, 0, 0]), + lineweight: Lw::Default, + linetype: "CONTINUOUS".into(), + ltscale: 1.0, + alpha: Alpha::Opacity(1.0), + } + } + + /// Two dashes and two dots: the group, its two paths and four pieces, in 8 path elements. + fn mixed() -> BezPath { + let mut bp = BezPath::new(); + for (a, b) in [((0.0, 0.0), (1.0, 0.0)), ((0.0, 1.0), (1.0, 1.0)), ((2.0, 0.0), (2.0, 0.0)), ((2.0, 1.0), (2.0, 1.0))] { + bp.move_to(a); + bp.line_to(b); + } + bp + } + + #[test] + fn mixed_patterns_fit_every_object_and_point_or_charge_nothing() { + let (tags, _) = super::super::tags(EMPTY).unwrap(); + let d = Drawing::read(craft_dxf::model::Document::read(&tags)); + let o = ImportOptions::default(); + let (p, inh) = (props(), Inherit::default()); + // Seven objects with six slots free: refused; with seven: drawn, the group left to `item`. + let mut b = Build::new(&d, &o); + b.nodes = MAX_NODES - 6; + assert!(b.pattern(&mixed(), true, &p, Affine::IDENTITY, &inh).is_none()); + assert_eq!(b.nodes, MAX_NODES - 6); + b.nodes = MAX_NODES - 7; + assert!(b.pattern(&mixed(), true, &p, Affine::IDENTITY, &inh).is_some()); + assert_eq!(b.nodes, MAX_NODES - 1); + // Eight points with seven left: refused without charging them, so a 4-point path that + // follows still fits. + let mut b = Build::new(&d, &o); + b.elements = MAX_ELEMENTS - 7; + assert!(b.pattern(&mixed(), true, &p, Affine::IDENTITY, &inh).is_none()); + assert_eq!(b.elements, MAX_ELEMENTS - 7); + let mut line = BezPath::new(); + line.move_to((0.0, 0.0)); + line.line_to((1.0, 0.0)); + line.line_to((1.0, 1.0)); + line.line_to((0.0, 1.0)); + assert!(b.path(&line, Look::Line, 0.0, &p, Affine::IDENTITY, &inh).is_some()); + } +} diff --git a/crates/cad/src/import/entity.rs b/crates/cad/src/import/entity.rs index 3bfecbf61d..3e3ddd26d3 100644 --- a/crates/cad/src/import/entity.rs +++ b/crates/cad/src/import/entity.rs @@ -203,7 +203,8 @@ pub(crate) struct Converter { } const PATTERN_HATCH: &str = "pattern hatches without usable pattern lines come in as their boundaries"; -const DENSE_PATTERN: &str = "pattern hatches of more than 20,000 dashes come in as their boundaries"; +const DENSE_PATTERN: &str = + "pattern hatches of more than 20,000 dashes, 200,000 boundary edges or 20,000,000 clipping steps come in as their boundaries"; const MANY_PATTERNS: &str = "the drawing's pattern hatches have more than 2,000,000 dashes in all: the rest come in as their boundaries"; const MUCH_PATTERN_WORK: &str = "the drawing's pattern hatches take too much work to clip: the rest come in as their boundaries"; const MUCH_ISLAND_WORK: &str = "hatches with too many boundary points to sort into islands are filled as if every loop were a boundary"; @@ -240,7 +241,7 @@ impl Converter { if !m.common.visible { continue; } - match self.geom(e, &m) { + match self.geom(e, &m).map(usable_paint) { Some(geom) if !in_range(&geom) => self.warn(FAR_AWAY), Some(geom) => out.push(Item { props: Props::read(&m.common), geom }), None if is_known(e.kind) => {} @@ -581,7 +582,23 @@ impl Converter { } } -/// Is the geometry within [`MAX_COORD`] of the origin? +/// A gradient hatch whose gradient cannot be placed (numbers out of range) as a solid fill. +fn usable_paint(g: Geom) -> Geom { + match g { + Geom::Shaded { bp, shade: Shade::Gradient(grad) } => { + let geom = &grad.geom; + let finite = |p: Point| p.x.is_finite() && p.y.is_finite(); + if finite(geom.start) && finite(geom.end) && geom.aspect.is_finite() && geom.focal.is_none_or(finite) { + Geom::Shaded { bp, shade: Shade::Gradient(grad) } + } else { + Geom::Path { bp, fill: true, width: 0.0 } + } + } + g => g, + } +} + +/// Is the geometry within [`MAX_COORD`] of the origin? A gradient's handles may lie beyond it. fn in_range(g: &Geom) -> bool { let near = |p: Point| p.x.abs() <= MAX_COORD && p.y.abs() <= MAX_COORD; let origin = |m: &Affine| near(m.translation().to_point()); @@ -589,10 +606,7 @@ fn in_range(g: &Geom) -> bool { Geom::Path { bp, width, .. } => { curve::bounds(bp).is_some_and(|b| near(Point::new(b.x0, b.y0)) && near(Point::new(b.x1, b.y1))) && *width <= MAX_COORD } - Geom::Shaded { bp, shade } => { - let far = matches!(shade, Shade::Gradient(g) if !near(g.geom.start) || !near(g.geom.end) || !g.geom.aspect.is_finite()); - !far && curve::bounds(bp).is_some_and(|b| near(Point::new(b.x0, b.y0)) && near(Point::new(b.x1, b.y1))) - } + Geom::Shaded { bp, .. } => curve::bounds(bp).is_some_and(|b| near(Point::new(b.x0, b.y0)) && near(Point::new(b.x1, b.y1))), Geom::Text(t) => origin(&t.xf) && t.height <= MAX_COORD, Geom::Insert(i) => i.cells.iter().all(|m| origin(m) && m.as_coeffs().iter().all(|v| v.is_finite() && v.abs() <= MAX_COORD)), } diff --git a/crates/cad/src/import/hatch.rs b/crates/cad/src/import/hatch.rs index cc375424ba..3457fa4527 100644 --- a/crates/cad/src/import/hatch.rs +++ b/crates/cad/src/import/hatch.rs @@ -24,10 +24,8 @@ pub(crate) const MAX_TOTAL_PIECES: usize = if cfg!(test) { 1_000 } else { 2_000_ pub(crate) const MAX_TOTAL_WORK: usize = if cfg!(test) { 200_000 } else { 200_000_000 }; /// How far flattened boundary curves may stray, as a fraction of their loop's larger side. const FLATNESS: f64 = 1e-4; -/// Line spacings and dash periods below this fraction of the boundary's larger side count as -/// none. -const TINY: f64 = 1e-9; -/// Spans shorter than this many units of the last place of their coordinates count as none. +/// Spans, line spacings and dash periods shorter than this many units of the last place of their +/// coordinates count as none. const LOCAL_TINY: f64 = 64.0 * f64::EPSILON; /// Why a pattern hatch is not drawn as its pattern. @@ -35,7 +33,8 @@ const LOCAL_TINY: f64 = 64.0 * f64::EPSILON; pub(crate) enum NoPattern { /// The hatch holds no pattern lines. Undefined, - /// Drawing it would take more than [`MAX_PIECES`] pieces or [`MAX_WORK`] steps. + /// Drawing it would take more than [`MAX_PIECES`] pieces, [`MAX_EDGES`] boundary edges or + /// [`MAX_WORK`] steps. TooDense, /// The drawing reaches its total piece limit. DrawingPieces, @@ -122,7 +121,9 @@ pub(crate) fn pattern(lines: &[PatternLine], boundary: &BezPath, budget: &mut Bu return Ok((out, false)); } let corners = [Point::new(b.x0, b.y0), Point::new(b.x1, b.y0), Point::new(b.x0, b.y1), Point::new(b.x1, b.y1)]; - let tiny = size * TINY; + let center = b.center(); + // The precision of the boundary's coordinates: spacings and periods below it draw nothing apart. + let tiny = LOCAL_TINY * center.to_vec2().hypot().max(size); let (mut work, mut pieces, mut dots, mut usable) = (0usize, 0usize, false, false); for l in lines { let a = l.angle.to_radians(); @@ -136,10 +137,26 @@ pub(crate) fn pattern(lines: &[PatternLine], boundary: &BezPath, budget: &mut Bu continue; } usable = true; - // Lines no distance apart, or as good as none, fill the area past what can be drawn. + // Lines no distance apart, or closer than the coordinates can tell apart, fill the area + // past what can be drawn. if step.abs() <= tiny { return Err(NoPattern::TooDense); } + let period: f64 = l.dashes.iter().map(|v| v.abs()).sum(); + if !l.dashes.is_empty() && period <= tiny { + return Err(NoPattern::TooDense); + } + // The same family from the line nearest the boundary's center: a whole number of offsets + // along, so each line keeps its dashes' phase, and then a whole number of dash periods + // along the line. + let (across, along) = ((base - center).dot(n), (base - center).dot(d)); + let shift = -(across / step).round(); + let across = across + shift * step; + let along = if l.dashes.is_empty() { 0.0 } else { (along + shift * offset.dot(d)).rem_euclid(period) }; + if !(across.is_finite() && along.is_finite()) { + continue; + } + let base = center + n * across + d * along; // The lines crossing the boundary's box: base + k * offset for whole k. let h = corners.map(|c| (c - base).dot(n) / step); let lo = h.iter().copied().fold(f64::INFINITY, f64::min).ceil(); @@ -151,10 +168,6 @@ pub(crate) fn pattern(lines: &[PatternLine], boundary: &BezPath, budget: &mut Bu if count * (edges.len() as f64) + work as f64 > MAX_WORK as f64 { return Err(NoPattern::TooDense); } - let period: f64 = l.dashes.iter().map(|v| v.abs()).sum(); - if !l.dashes.is_empty() && period <= tiny { - return Err(NoPattern::TooDense); - } let mut t = Vec::new(); for k in (lo as i64)..=(hi as i64) { budget.work(&mut work, edges.len())?; @@ -175,9 +188,19 @@ pub(crate) fn pattern(lines: &[PatternLine], boundary: &BezPath, budget: &mut Bu emit(ta, tb, budget)?; continue; } - // The dashes run from the line's base point: the first period that reaches the - // span, element by element. + // The dashes run from the line's base point, element by element, from the period + // before the one the span starts in, so a dot that ends that period (on the span's + // start) is kept. let mut at = (ta / period).floor() * period; + if at >= ta { + at -= period; + } + // Periods too short to move along the span, or more dashes than one hatch may + // look at, are refused before any of them is looked at. + let steps = ((tb - at) / period + 1.0) * l.dashes.len() as f64; + if period <= LOCAL_TINY * at.abs().max(tb.abs()) || steps + work as f64 > MAX_WORK as f64 { + return Err(NoPattern::TooDense); + } 'span: loop { for v in &l.dashes { if at > tb { @@ -499,7 +522,7 @@ mod tests { let mut boundary = strip(0.0); boundary.extend(strip(1e10)); let l = PatternLine { angle: 0.0, base: [0.0, 25.0], offset: [0.0, 50.0], dashes: vec![] }; - let (bp, _) = pattern(&[l.clone()], &boundary).unwrap(); + let (bp, _) = pattern(std::slice::from_ref(&l), &boundary).unwrap(); let p = pieces(&bp); assert_eq!(p.len(), 4, "{p:?}"); assert!(p.iter().all(|(a, b)| ((b.x - a.x) - 1.0).abs() < 1e-3), "{p:?}"); @@ -516,6 +539,54 @@ mod tests { assert!(p.iter().all(|(a, b)| ((b.x - a.x).abs() - chord).abs() < chord * 1e-2), "{p:?}"); } + #[test] + fn close_lines_across_squares_far_apart_are_drawn() { + // Two unit squares 10 billion units apart, lines 0.5 apart: two lines cross each square. + let mut boundary = square(1.0); + let mut far = square(1.0); + far.apply_affine(Affine::translate((1e10, 0.0))); + boundary.extend(far); + let (bp, _) = pattern(&[line(0.0, [0.0, 0.5], &[])], &boundary).unwrap(); + assert_eq!(pieces(&bp).len(), 4, "{:?}", pieces(&bp)); + // Dashes 0.25 long with 0.25 gaps: two per line in each square. + let (bp, _) = pattern(&[line(0.0, [0.0, 0.5], &[0.25, -0.25])], &boundary).unwrap(); + assert_eq!(pieces(&bp).len(), 8, "{:?}", pieces(&bp)); + } + + #[test] + fn families_based_far_away_draw_the_same_lines() { + // Lines one apart from a base 1e19 up are the lines one apart from the origin. + let mut far = line(0.0, [0.0, 1.0], &[]); + far.base = [0.0, 1e19]; + let (bp, _) = pattern(&[far], &square(100.0)).unwrap(); + let p = pieces(&bp); + assert_eq!(p.len(), 100, "{p:?}"); + assert!(p.iter().all(|(a, b)| a.y == b.y && a.y.fract() == 0.0 && (0.0..100.0).contains(&a.y)), "{p:?}"); + // A staggered family based 100 lines away keeps each line's dash phase. + let mut near = line(0.0, [5.0, 10.0], &[3.0, -7.0]); + near.base = [-497.0, 0.0]; + let mut away = near.clone(); + away.base = [3.0, 1000.0]; + let sorted = |l: PatternLine| { + let mut p = pieces(&pattern(&[l], &square(100.0)).unwrap().0); + p.sort_by(|a, b| (a.0.y, a.0.x).partial_cmp(&(b.0.y, b.0.x)).unwrap_or(std::cmp::Ordering::Equal)); + p + }; + let (a, b) = (sorted(near), sorted(away)); + assert_eq!(a.len(), b.len()); + assert!(!a.is_empty()); + assert!(a.iter().zip(&b).all(|(x, y)| x.0.distance(y.0) < 1e-9 && x.1.distance(y.1) < 1e-9), "{a:?} {b:?}"); + } + + #[test] + fn a_dot_on_the_start_of_a_span_is_kept() { + // A gap of 5 then a dot, from x 0: dots at 0, 5 and 10 on the line along the bottom. + let (bp, dots) = pattern(&[line(0.0, [0.0, 20.0], &[-5.0, 0.0])], &square(10.0)).unwrap(); + assert!(dots); + let xs: Vec = pieces(&bp).iter().filter(|(a, _)| a.y == 0.0).map(|(a, _)| a.x).collect(); + assert_eq!(xs, [0.0, 5.0, 10.0]); + } + #[test] fn slanted_lines_fill_a_square_evenly() { // 45 degree lines 1 apart across the square's diagonal of 14.1: each piece runs from one @@ -536,9 +607,13 @@ mod tests { // Few lines, but dashes far shorter than the square: more pieces than allowed. assert_eq!(pattern(&[line(0.0, [0.0, 10.0], &[0.01, -0.01])], &square(1000.0)), Err(NoPattern::TooDense)); // A tiny nonempty dash period is too dense; only an empty list draws continuous lines. - // It is refused before any line is clipped or dashed. + // It is refused once the first line is clipped, before any of its dashes is looked at. let mut budget = Budget { pieces: usize::MAX, work: usize::MAX, stopped: None }; assert_eq!(super::pattern(&[line(0.0, [0.0, 1.0], &[-1e-12])], &square(10.0), &mut budget), Err(NoPattern::TooDense)); + assert_eq!(budget.work, usize::MAX - 4, "one line clipped against four edges, no dashes looked at"); + // A period below the coordinates' precision is refused before any line is clipped. + let mut budget = Budget { pieces: usize::MAX, work: usize::MAX, stopped: None }; + assert_eq!(super::pattern(&[line(0.0, [0.0, 1.0], &[-1e-15])], &square(10.0), &mut budget), Err(NoPattern::TooDense)); assert_eq!(budget.work, usize::MAX, "no work done"); let (bp, _) = pattern(&[line(0.0, [0.0, 1.0], &[])], &square(10.0)).unwrap(); assert!(!pieces(&bp).is_empty()); diff --git a/crates/cad/src/import/tests.rs b/crates/cad/src/import/tests.rs index 081c40fa5a..2731979702 100644 --- a/crates/cad/src/import/tests.rs +++ b/crates/cad/src/import/tests.rs @@ -568,19 +568,25 @@ fn hatch_island_styles_select_nested_boundary_levels() { ]); } e.splice(count + 1..end, loops); - for (style, expected) in [("0", 3), ("1", 2), ("2", 1), ("3", 3)] { + // The sides of the squares each style keeps: normal and unknown styles all three, outer the + // outermost and middle ones, ignore the outermost alone. + for (style, expected) in [("0", &[20.0, 60.0, 100.0][..]), ("1", &[60.0, 100.0]), ("2", &[100.0]), ("3", &[20.0, 60.0, 100.0])] { *e.iter_mut().find(|p| p.0 == 75).unwrap() = (75, style); let r = open(&entities(&e), &points()); assert!(r.warnings.is_empty(), "style {style}: {:?}", r.warnings); let [area] = &r.document.layers[0].children().unwrap()[..] else { panic!("one hatch") }; - let count = match &area.kind { + let mut sides: Vec = match &area.kind { NodeKind::Compound { children, rule } => { assert_eq!(*rule, FillRule::EvenOdd); - children.len() + children.iter().map(|c| bounds(c).width().round()).collect() + } + _ => { + assert_eq!(area.path_data().unwrap().subpaths.len(), 1); + vec![bounds(area).width().round()] } - _ => area.path_data().unwrap().subpaths.len(), }; - assert_eq!(count, expected, "boundary loops for island style {style}"); + sides.sort_by(f64::total_cmp); + assert_eq!(sides, expected, "boundary loops for island style {style}"); assert!(area.appearance.fill().is_some_and(|f| !f.paint.is_none())); } } @@ -1000,6 +1006,57 @@ fn block_gradient_stops_keep_the_inserts_color() { } } +#[test] +fn gradient_hatches_far_out_keep_their_fill() { + // A sphere hatch on a strip 10 wide ending 1e12 out: its circle reaches past 1e12, and the + // strip still comes in, centered on the artboard. + let mut e = vec![(0, "HATCH"), (62, "1"), (10, "0"), (20, "0"), (30, "0"), (2, "SOLID"), (70, "1"), (71, "0"), (91, "1")]; + e.extend([(92, "3"), (72, "0"), (73, "1"), (93, "4")]); + for (x, y) in [("999999999990", "0"), ("1000000000000", "0"), ("1000000000000", "100"), ("999999999990", "100")] { + e.extend([(10, x), (20, y)]); + } + e.extend([(97, "0"), (75, "0"), (76, "1"), (98, "0")]); + e.extend([(450, "1"), (451, "0"), (452, "0"), (453, "2"), (460, "0"), (461, "0")]); + e.extend([(462, "0"), (463, "0"), (63, "1"), (463, "1"), (63, "5"), (470, "SPHERICAL")]); + let r = open(&entities(&e), &ImportOptions { center: true, ..points() }); + assert!(r.warnings.is_empty(), "{:?}", r.warnings); + let [area] = &r.document.layers[0].children().unwrap()[..] else { panic!("one hatch") }; + assert_eq!(gradient_of(area).gradient.kind, vectorcraft_color::GradientKind::Radial); + assert_eq!(bounds(area).width().round(), 10.0); +} + +/// [`with_door`] with a dashed linetype `DASHED` in the drawing. +fn with_dashed_door(block_art: &[(i32, &'static str)], inserts: &[(i32, &'static str)]) -> Vec { + let mut blocks = vec![(0, "BLOCK"), (8, "0"), (2, "Door"), (70, "0"), (10, "5"), (20, "5"), (3, "Door")]; + blocks.extend_from_slice(block_art); + blocks.push((0, "ENDBLK")); + let tables = [ + (0, "TABLE"), + (2, "LTYPE"), + (0, "LTYPE"), + (2, "DASHED"), + (73, "2"), + (40, "15"), + (49, "10"), + (49, "-5"), + (0, "ENDTAB"), + (0, "TABLE"), + (2, "LAYER"), + (0, "LAYER"), + (2, "Doors"), + (70, "0"), + (62, "5"), + (6, "CONTINUOUS"), + (0, "ENDTAB"), + ]; + drawing(&[], &tables, &blocks, inserts) +} + +/// Whether `n` or any object inside it has a dashed stroke. +fn dashed(n: &Node) -> bool { + n.appearance.stroke().is_some_and(|s| s.dash.is_some()) || n.children().is_some_and(|c| c.iter().any(|c| dashed(c))) +} + #[test] fn block_pattern_hatches_ignore_the_inserts_linetype() { let inserts = [(0, "INSERT"), (2, "Door"), (62, "1"), (10, "0"), (20, "0"), (0, "INSERT"), (2, "Door"), (62, "3"), (10, "200"), (20, "0")]; @@ -1014,6 +1071,25 @@ fn block_pattern_hatches_ignore_the_inserts_linetype() { boundary.splice(1..1, [(8, "Doors"), (370, "25"), (6, "BYBLOCK")]); let r = open(&with_door(&boundary, &inserts), &points()); assert_eq!(r.document.symbols.len(), 2, "{:?}", r.warnings); + + // Inserts of one color, one dashed and one continuous. + let inserts = + [(0, "INSERT"), (2, "Door"), (6, "DASHED"), (10, "0"), (20, "0"), (0, "INSERT"), (2, "Door"), (6, "CONTINUOUS"), (10, "200"), (20, "0")]; + let r = open(&with_dashed_door(&lines, &inserts), &points()); + assert!(r.warnings.is_empty(), "{:?}", r.warnings); + let [symbol] = &r.document.symbols[..] else { panic!("one symbol for both linetypes") }; + assert!(!dashed(&symbol.art), "pattern lines carry no linetype dashes"); + // The boundary drawn for each insert takes that insert's linetype. + let r = open(&with_dashed_door(&boundary, &inserts), &points()); + assert_eq!(r.document.symbols.len(), 2, "{:?}", r.warnings); + let looks: Vec = leaves(&r.document) + .iter() + .map(|n| { + let NodeKind::SymbolInstance { symbol, .. } = &n.kind else { panic!("{:?}", n.kind) }; + dashed(&r.document.symbols.iter().find(|s| s.name == *symbol).unwrap().art) + }) + .collect(); + assert_eq!(looks, [true, false], "the dashed insert's boundary is dashed, the continuous one's is not"); } #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 323cc769d6..5ee73290d0 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -12893,10 +12893,13 @@ artboard under `at`). `center: false` puts the drawing's origin (fitted art: its artboard's bottom-left corner; `mergeLayers` puts all art on one layer. Each DXF layer holding art becomes a layer (off and frozen layers hidden, locked ones locked, non-plotting ones non-printing). Lines, polylines (arc segments from bulges), circles, arcs, ellipses, splines (NURBS, within a millionth of their size), solids and hatches become paths (solid -hatches filled; hatches follow their island style (normal, outer, ignore); gradient hatches filled with a linear or +hatches filled; hatches follow their island style (normal, outer, ignore), except that a hatch with too many boundary +points to sort into islands is filled as if every loop were a boundary, with a warning, so an ignore-style hatch can +keep its holes; gradient hatches filled with a linear or radial gradient at their angle, in their two colors or one color shaded or tinted; pattern hatches as their pattern's lines clipped to the boundary, each cut into its dashes and dots and stroked at the lineweight without the linetype; a pattern hatch with no usable pattern lines, with more -than 20,000 dashes, or past the drawing's budget of 2,000,000 dashes or 200,000,000 clipping steps, as its boundary), +than 20,000 dashes, 200,000 boundary edges or 20,000,000 clipping and dash steps, or past the drawing's budget of +2,000,000 dashes or 200,000,000 clipping steps, as its boundary), text and multiline text point type, named blocks symbols (one per look when their art takes colour "by block"), anonymous blocks such as dimensions groups. 3D faces, polyface meshes and polygon meshes are seen from above, their height dropped: a 3D face or a polyface mesh's face becomes the