mirror of
https://github.com/storytold/cadcraft.git
synced 2026-12-02 02:38:30 -06:00
A dashed run is laid out over at most two million pattern elements, but nothing bounded the total, and a pattern of mostly gaps visits many elements for each point it draws, so the 64M-point display budget never stopped it: 1,000 lines on a 256-element pattern of gaps and one dash (a 58 KB DXF) took 11.6 s to PNG and 12.7 s to a 69 MB PDF on a dev build. A run past the per-run limit was also drawn continuous without a word (#1069). - MAX_DASH_ELEMENTS (64M, as many as the list's points) is charged by linetype::layout before a run is laid out, on a counter shared like the point budget's (parallel parts, XCLIP parts, viewport contents). Once a run does not fit, the rest of the build's dashed runs are drawn continuous. The per-run limit is MAX_RUN_DASH_ELEMENTS, unchanged. - A run drawn continuous because of either limit sets DisplayList::truncated and counts in the new DisplayList::undashed, merged where lists are joined. Runs drawn continuous by rule (short, sub-pixel, the screen's 50,000-period level of detail) are not counted. - cadcraft_io::write_framed_noted (and png/svg/pdf "noted" variants) return the note; cadcraft-cli convert and run --export print it. - Linetype texts are placed only on a run whose dashes were laid out; phase checks the limits without laying the run out again. On 11 real drawings the most a complete plot asked was 26.5M elements; a 16M total would have drawn 8,241 runs of that drawing solid. With 64M the gap-pattern file takes 0.8 s / 0.4 s, the #1069 controls and three real drawings export byte-identical, and the audit's dense dash/gap file stays as on main (it fills the point budget at the same time). Part of #1923 (F-05 f). Part of #1069: the app's EXPORT and PLOT don't show the note yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
2.7 KiB
Rust
74 lines
2.7 KiB
Rust
//! Multilines: each element in its style colour and linetype (ByLayer and ByBlock elements
|
|
//! follow the multiline's own), caps and joints in the multiline's properties, and the fill.
|
|
|
|
use super::{Builder, Ctx, Ink, fill, ink, linetype, resolve_common};
|
|
use cadcraft_color::Color;
|
|
use cadcraft_doc::{Entity, MLine};
|
|
use cadcraft_geom::Vec2;
|
|
|
|
pub(super) fn draw(b: &mut Builder, ctx: &Ctx, e: &Entity, m: &MLine, rgb: Ink, lw: f32, tol: f64) {
|
|
let g = m.geometry();
|
|
if let Some(fc) = m.def.fill
|
|
&& b.opts.fill
|
|
&& !g.fill.is_empty()
|
|
{
|
|
let c = match fc {
|
|
Color::ByLayer | Color::ByBlock => rgb,
|
|
c => ink(c, Color::Index(7), ctx.block_color),
|
|
};
|
|
b.tris(ctx, c, &fill::triangulate_evenodd(&g.fill));
|
|
}
|
|
let min = b.opts.min_dash / ctx.xf.scale_factor().max(1e-12);
|
|
// One look per element: colour, lineweight, linetype and its scale.
|
|
let looks: Vec<_> = m
|
|
.def
|
|
.elements
|
|
.iter()
|
|
.map(|el| {
|
|
let mut c = e.common.clone();
|
|
if !matches!(el.color, Color::ByLayer | Color::ByBlock) {
|
|
c.color = el.color;
|
|
}
|
|
let lt = el.linetype.trim();
|
|
if !lt.is_empty() && !lt.eq_ignore_ascii_case("bylayer") && !lt.eq_ignore_ascii_case("byblock") {
|
|
c.linetype = lt.to_string();
|
|
}
|
|
let (rgb, w, lt, scale, _, _, _) = resolve_common(ctx, &c, b.plotting);
|
|
let lt = match b.styles.and_then(|s| s.linetype(rgb, b.named)) {
|
|
Some(over) => over,
|
|
None => lt,
|
|
};
|
|
(rgb, if b.opts.lineweights { w } else { 0.0 }, lt, scale)
|
|
})
|
|
.collect();
|
|
for (i, a, z) in &g.lines {
|
|
let Some((rgb, w, lt, scale)) = looks.get(*i) else { continue };
|
|
stroke(b, ctx, *rgb, *w, lt.as_ref(), *scale, min, &[*a, *z]);
|
|
}
|
|
let own = resolve_common(ctx, &e.common, b.plotting);
|
|
let lt = match b.styles.and_then(|s| s.linetype(rgb, b.named)) {
|
|
Some(over) => over,
|
|
None => own.2,
|
|
};
|
|
for s in &g.caps {
|
|
let mut pts = Vec::new();
|
|
s.tessellate(tol, &mut pts);
|
|
stroke(b, ctx, rgb, lw, lt.as_ref(), own.3, min, &pts);
|
|
}
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
fn stroke(b: &mut Builder, ctx: &Ctx, rgb: Ink, lw: f32, lt: Option<&cadcraft_doc::Linetype>, scale: f64, min: f64, pts: &[Vec2]) {
|
|
match lt.filter(|_| b.opts.linetypes) {
|
|
Some(lt) => {
|
|
for dash in linetype::apply(pts, lt, scale, min, b) {
|
|
match dash.as_slice() {
|
|
[p] => b.point(ctx, rgb, *p),
|
|
_ => b.polyline(ctx, rgb, lw, &dash),
|
|
}
|
|
}
|
|
}
|
|
None => b.polyline(ctx, rgb, lw, pts),
|
|
}
|
|
}
|