diff --git a/crates/cad/src/tests.rs b/crates/cad/src/tests.rs index 996f6fba..37bebbd0 100644 --- a/crates/cad/src/tests.rs +++ b/crates/cad/src/tests.rs @@ -125,6 +125,18 @@ fn every_version_declares_its_acadver_and_is_well_formed() { assert_eq!(DxfVersion::from_id("2019"), None); } +#[test] +fn r12_viewport_has_no_duplicate_group_codes() { + let d = shapes_doc(); + let out = export(&d, &DxfOptions { version: DxfVersion::R12, ..opts(&d) }).unwrap(); + let vport = table(&out, "VPORT").into_iter().find(|o| kind(o) == "VPORT").expect("VPORT table record"); + let codes: Vec = vport.iter().map(|pair| pair.0).collect(); + let unique: std::collections::HashSet<_> = codes.iter().collect(); + assert_eq!(unique.len(), codes.len(), "R12 VPORT record has duplicate group codes: {vport:?}"); + let z = vport.iter().find(|pair| pair.0 == 36).map(|pair| pair.1.trim().parse::().unwrap()); + assert_eq!(z, Some(1.0), "the view direction looks down the z axis"); +} + #[test] fn lines_are_lwpolylines_curves_splines_and_fills_hatches() { let d = shapes_doc(); diff --git a/crates/cad/src/writer.rs b/crates/cad/src/writer.rs index 2fe4ec39..665f8576 100644 --- a/crates/cad/src/writer.rs +++ b/crates/cad/src/writer.rs @@ -441,7 +441,8 @@ impl Drawing { c.xy(13, 0.0, 0.0); c.xy(14, 1.0, 1.0); c.xy(15, 10.0, 10.0); - c.xyz(16, 0.0, 0.0); + // The view direction looks down the z axis: (0, 0, 1), each code once. + c.xy(16, 0.0, 0.0); c.num(36, 1.0); c.xyz(17, 0.0, 0.0); let (w, h) = ((x1 - x0).abs(), (y1 - y0).abs());