mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-25 03:16:50 -06:00
Objects whose lineweight resolves to Default were always drawn and plotted at 0.25 mm. They now use LWDEFAULT (hundredths of a mm, 0..211), falling back to 0.25 mm when it is unset or out of range. All backends (canvas, PNG, SVG, PDF) read the width from the display list. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
1.2 KiB
Rust
28 lines
1.2 KiB
Rust
//! The "Default" lineweight is the width LWDEFAULT names (issue #292).
|
|
|
|
use cadcraft_doc::{Common, Drawing, EntityKind, Line, Lineweight, Space};
|
|
use cadcraft_geom::Vec3;
|
|
use cadcraft_render::{Kind, Options, build};
|
|
|
|
/// Lineweights (mm) of a ByLayer line on layer 0 (lineweight Default) and an explicit 0.50 mm line.
|
|
fn widths(lwdefault: Option<i64>) -> Vec<f32> {
|
|
let mut d = Drawing::new_metric();
|
|
if let Some(v) = lwdefault {
|
|
d.header.set_i64("LWDEFAULT", v);
|
|
}
|
|
let line = |y: f64| EntityKind::Line(Line { a: Vec3::new(0.0, y, 0.0), b: Vec3::new(10.0, y, 0.0) });
|
|
d.add(&Space::Model, Common::default(), line(0.0)).unwrap();
|
|
d.add(&Space::Model, Common { lineweight: Lineweight::Mm100(50), ..Default::default() }, line(1.0)).unwrap();
|
|
let l = build(&d, &Space::Model, &Options { lineweights: true, ..Default::default() });
|
|
l.prims.iter().filter(|p| p.kind == Kind::Polyline).map(|p| p.lw).collect()
|
|
}
|
|
|
|
#[test]
|
|
fn default_lineweight_follows_lwdefault() {
|
|
assert_eq!(widths(None), [0.25, 0.5], "unset: 0.25 mm");
|
|
assert_eq!(widths(Some(70)), [0.7, 0.5]);
|
|
assert_eq!(widths(Some(0)), [0.0, 0.5]);
|
|
assert_eq!(widths(Some(-3)), [0.25, 0.5], "out of range: 0.25 mm");
|
|
assert_eq!(widths(Some(5000)), [0.25, 0.5]);
|
|
}
|