From ef745bbedaefac11baa5fee5d971ed8c7797fe0a Mon Sep 17 00:00:00 2001 From: schoeller Date: Tue, 24 Nov 2026 22:49:04 +0100 Subject: [PATCH] Pin the 3D polyline closed-flag round trip with a test (W4-2) The D016 packet-4 census of the tutorials' Surface-1A.dwg reported the built _EG-BNDY 3D polyline (192 vertices, the EG surface boundary) as open while the oracle's is closed. The writer carries the flag: the loss was in the corpus builder, which never set the typed field (fixed on the parity/corpus-roundtrip branch). Pin the behavior the packet depends on with a DWG round-trip test: a closed 3D polyline reads back closed with its vertices bit-exact. --- src/entities/polyline3d.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/entities/polyline3d.rs b/src/entities/polyline3d.rs index e3c3ec8da..158fc1289 100644 --- a/src/entities/polyline3d.rs +++ b/src/entities/polyline3d.rs @@ -536,4 +536,39 @@ mod tests { assert_eq!(polyline.start_point(), Some(Vector3::new(0.0, 0.0, 0.0))); assert_eq!(polyline.end_point(), Some(Vector3::new(10.0, 0.0, 0.0))); } + + /// A closed 3D polyline keeps its closed flag and its vertices through a + /// DWG round trip (W4-2: the `_EG-BNDY` surface boundary of the + /// tutorials' Surface-1A.dwg is the record that carries the flag). + #[test] + fn a_closed_3d_polyline_round_trips_closed() { + use crate::entities::EntityType; + use crate::io::dwg::{DwgReader, DwgWriter}; + use crate::types::DxfVersion; + let mut doc = crate::CadDocument::new(); + doc.version = DxfVersion::AC1032; + let mut polyline = Polyline3D::new(); + polyline.flags.closed = true; + polyline.vertices = (0..4) + .map(|i| Vertex3DPolyline { + handle: Handle::NULL, + layer: String::new(), + position: Vector3::new(i as f64, (i % 2) as f64, i as f64 * 0.5), + flags: 0, + }) + .collect(); + let h = doc.add_entity(EntityType::Polyline3D(polyline)).unwrap(); + let path = std::env::temp_dir().join(format!("polyline3d-closed-{}.dwg", std::process::id())); + DwgWriter::write_to_file(&path, &doc).unwrap(); + let back = DwgReader::from_file(&path).unwrap().read().unwrap(); + let _ = std::fs::remove_file(&path); + let Some(EntityType::Polyline3D(p)) = back.get_entity(h) else { + panic!("the 3D polyline did not round trip"); + }; + assert!(p.flags.closed); + assert!(p.flags.is_3d); + let expected: Vec = (0..4).map(|i| Vector3::new(i as f64, (i % 2) as f64, i as f64 * 0.5)).collect(); + let positions: Vec = p.vertices.iter().map(|v| v.position).collect(); + assert_eq!(positions, expected); + } }