diff --git a/CLEANROOM.md b/CLEANROOM.md index 3dced58..7beda43 100644 --- a/CLEANROOM.md +++ b/CLEANROOM.md @@ -1176,3 +1176,48 @@ records are the Sovol set's 21 unhandled records: SUN's field list was derived o R2018 alone, and the decoder refuses a release before R2007. So the 2026-10-26 entry's "no other drawing of the corpus holds a SUN" no longer holds. They stay unread until a field list for them is derived by the 2026-10-26 method. + +## 2026-11-30 — MESH: the field list checked against AutoCAD's own output (#478) + +By the method of the 2026-10-26 entry on classes the specification never prints. +The field list in `src/entities/mesh.rs` came in with `530192d7` (2026-04-20), which +credited a section ODA spec v5.4.1 does not have; this entry records its check +against the method's acceptance rule. The pinned corpus holds 14 MESH records, two +on each of R14, R2000, R2004, R2007, R2010, R2013 and R2018, all in ACadSharp's +`sample_base` saves (AutoCAD 2025; handles 0x343 and 0x380), with AutoCAD's DXF +export of the same handles from R2000 to R2018. `examples/probe_mesh.rs`, run over +the whole corpus (Measure run 46372916305), reads each record and walks the +`AcDbSubDMesh` group of its twin in the DXF's own order: version (71), blend crease +(72), subdivision level (91), vertex count (92) and each vertex (10, 20, 30), the +face list's size (93) and its entries (90), the edge count (94) and each endpoint +(90), the crease count (95) and each crease (140), and the trailing count (90). + +Accepted: all 14 records close on their data-stream boundary, and on R2000 to R2018 +the 10,992 values, each group's code and value, equal the twin with 0 differences. +The R14 records have no DXF twin and are held to their boundary alone. Unverified: +a trailing count other than 0, which the decoder refuses, and anything the DXF does +not write. No vocabulary beyond the DXF group codes and subclass marker in the +twins was used, and no third-party DWG or DXF implementation was consulted. + +## 2026-11-30 — WIPEOUT: IMAGE's field list checked against AutoCAD's own output (#478) + +By the method of the 2026-10-26 entry on classes the specification never prints. +`src/entities/wipeout.rs` reads WIPEOUT with IMAGE's field list (§20.4.80), which it +was measured to share on one R2018 record; v5.4.1 names WIPEOUT only in its +object-type table (§20.3). This entry records the check of that reading against the +method's acceptance rule on every corpus record: seven, one on each of R14, R2000, +R2004, R2007, R2010, R2013 and R2018, in ACadSharp's `sample_base` saves (AutoCAD +2025, handle 0x44D), with AutoCAD's DXF export of the same handle from R2000 to +R2018. `examples/probe_wipeout.rs`, run over the whole corpus (Measure run +46372916305), compares the insertion point, the U and V vectors, the image size, +the display flags, clipping, brightness, contrast, fade, the clip mode (written by +the DXF from R2010), the clip boundary's type and vertex count, and each vertex. + +Accepted: all seven records close on their data-stream boundary, and on R2000 to +R2018 the 171 values compared equal the twin with 0 differences. The DXF writes a +clip polygon's first vertex again after its last, so its count is one more than the +record's; that last vertex equals the first on every record. The R14 record has no +DXF twin and is held to its boundary alone. Unverified by value: the +graphics-preview block before the fields, and anything the DXF does not write. No +vocabulary beyond the DXF group codes and subclass markers in the twins was used, +and no third-party DWG or DXF implementation was consulted. diff --git a/docs/spec-coverage.md b/docs/spec-coverage.md index 77ff7aa..6cb9192 100644 --- a/docs/spec-coverage.md +++ b/docs/spec-coverage.md @@ -189,11 +189,11 @@ Classes the corpus holds that v5.4.1 has no prescription for. Their field lists | PLOTSETTINGS | `closes` | src/objects/acad_plot_settings.rs | Read with LAYOUT. | | ACDBDETAILVIEWSTYLE / ACDBSECTIONVIEWSTYLE | `closes` | src/objects/acad_detail_view_style.rs, src/objects/acad_section_view_style.rs | Joint-boundary search, delta 0 (ARCHITECTURE §7d.4). ACDBSECTIONVIEWSTYLE: 68 of 68 corpus records R14 to R2018 close with delta 0; 48 paired records R2000 to R2018 match AutoCAD's DXF exports across all 1,911 non-handle values with 0 differences, including head flags, hatch scale/transparency/flags and all six angles (ARCHITECTURE §7bw, #409). | | EXTRUDEDSURFACE / REVOLVEDSURFACE / SWEPTSURFACE / LOFTEDSURFACE | `missing` | | Removed: no v5.4.1 prescription, no derivation from AutoCAD's output, and no record in the public corpus (CLEANROOM.md 2026-11-29; #475). | -| MESH (subdivision) | `partial` | src/entities/mesh.rs | 2 records error (#71). | +| MESH (subdivision) | `closes` | src/entities/mesh.rs | 14 of 14 corpus records close on every release R14 to R2018; 10,992 values equal the DXF twin (R2000 to R2018), 0 differ (CLEANROOM.md 2026-11-30, #478). | | LIGHT | `decoder` | src/entities/light.rs | LIGHT: boundary closes, values unscored (no DXF twin): its one corpus record (R14, `3d.dwg`) closes on the data-stream boundary (ARCHITECTURE §7br, #152). | | CAMERA / HELIX | `missing` | | Removed: no v5.4.1 prescription, no derivation from AutoCAD's output, and no record in the public corpus (CLEANROOM.md 2026-11-29; #475). | | SUN | `closes` | src/entities/sun.rs | 1 of 1 corpus record (R2018, `geoloc.dwg`); 11 values equal the DXF twin by handle; the corpus holds no SUN on any other release; group 63 is not a field of the data bits (ARCHITECTURE §7bl, #152). | -| WIPEOUT / WIPEOUTVARIABLES | `decoder` | src/entities/wipeout.rs | WIPEOUTVARIABLES decodes in src/objects/small_classes.rs. | +| WIPEOUT / WIPEOUTVARIABLES | `closes` | src/entities/wipeout.rs | WIPEOUT (IMAGE's field list): 7 of 7 corpus records close on every release R14 to R2018; 171 values equal the DXF twin (R2000 to R2018), 0 differ (CLEANROOM.md 2026-11-30, #478). WIPEOUTVARIABLES decodes in src/objects/small_classes.rs. | | PDFUNDERLAY | `closes` | src/entities/underlay.rs | PDFUNDERLAY: 7 of 7 corpus records on every release R14 to R2018; 36 values equal the DXF twin by handle; the scale, rotation, normal and clip-vertex encoding are unverified by value; DWF and DGN share the decoder and have no corpus record (ARCHITECTURE §7bk, #152). The definitions: PDFDEFINITION in src/objects/small_classes.rs. | | DWFUNDERLAY / DGNUNDERLAY | `missing` | | Removed: no v5.4.1 prescription, no derivation from AutoCAD's output, and no record in the public corpus; `underlay::UnderlayKind` holds PDF alone (CLEANROOM.md 2026-11-29; #475). | | DBCOLOR | `missing` | | Referenced by ENC colours (§2.11). | diff --git a/examples/probe_mesh.rs b/examples/probe_mesh.rs index be38388..1dcf69b 100644 --- a/examples/probe_mesh.rs +++ b/examples/probe_mesh.rs @@ -4,12 +4,12 @@ //! //! # What this proves //! -//! For every MESH record (the `MESH` custom class) of a drawing this -//! prints whether the crate's decoder closed exactly on the record's -//! data-stream boundary (ARCHITECTURE.md §7i) and the shape it read. With -//! a second argument — AutoCAD's DXF export of the same drawing — it -//! walks the `AcDbSubDMesh` group of the DXF entity whose handle (group -//! 5) matches and compares, in order: +//! For every MESH record (the `MESH` custom class) of every drawing under the +//! corpus directory this reports whether the crate's decoder closed exactly on +//! the record's data-stream boundary (ARCHITECTURE.md §7i). Where the corpus +//! holds AutoCAD's DXF export of the drawing, it walks the `AcDbSubDMesh` +//! group of the DXF entity whose handle (group 5) matches and compares, in +//! order, each group's code and value: //! //! ```text //! 71 version 72 blend crease 91 subdivision level @@ -24,17 +24,17 @@ //! full: 926 values for a 62-vertex mesh. //! //! ```sh -//! cargo run --release --example probe_mesh -- sample_AC1015.dwg sample_AC1015_ascii.dxf +//! python3 -I tools/corpus/fetch.py --dest ../dwg-corpus +//! cargo run --release --example probe_mesh -- ../dwg-corpus //! ``` -//! -//! Exit status is non-zero when a record errors or a value differs. -use dwg::ObjectType; +#[path = "support/twin.rs"] +mod twin; + use dwg::entities::DecodedEntity; use dwg::entities::mesh::Mesh; -use dwg::{DwgFile, entities}; -use std::collections::HashMap; use std::process::ExitCode; +use twin::{Probe, Record, Tally}; /// The record's values as `(group code, value)` pairs, in the order the /// DXF writes the `AcDbSubDMesh` group. @@ -66,148 +66,53 @@ fn sequence(m: &Mesh) -> Vec<(u16, f64)> { out } -/// Every `MESH` entity of an ASCII DXF, keyed by its handle, as the -/// `(code, value)` pairs after its `AcDbSubDMesh` subclass marker. -fn dxf_meshes(path: &str) -> std::io::Result>> { - let bytes = std::fs::read(path)?; - let text: String = bytes.iter().map(|&b| b as char).collect(); - let lines: Vec<&str> = text.lines().collect(); - let mut out = HashMap::new(); - let mut i = 0; - while i + 1 < lines.len() { - if lines[i].trim() == "0" && lines[i + 1].trim() == "MESH" { - let (mut handle, mut body, mut inside) = (None, Vec::new(), false); - let mut j = i + 2; - while j + 1 < lines.len() && lines[j].trim() != "0" { - let code: u16 = lines[j].trim().parse().unwrap_or(u16::MAX); - let value = lines[j + 1].trim().to_string(); - if code == 5 { - handle = u64::from_str_radix(&value, 16).ok(); - } else if code == 100 { - inside = value == "AcDbSubDMesh"; - } else if inside { - body.push((code, value)); - } - j += 2; - } - if let Some(h) = handle { - out.insert(h, body); - } - i = j; - } else { - i += 2; - } - } - Ok(out) -} - -fn same(ours: f64, theirs: &str) -> bool { - theirs - .parse::() - .is_ok_and(|b| (ours - b).abs() <= 1e-9 * ours.abs().max(b.abs()).max(1.0)) -} - -fn main() -> ExitCode { - let mut args = std::env::args().skip(1); - let Some(path) = args.next() else { - eprintln!("usage: probe_mesh [twin.dxf]"); - return ExitCode::FAILURE; - }; - let dxf = args.next(); - let file = match DwgFile::open(&path) { - Ok(f) => f, - Err(e) => { - eprintln!("open failed ({path}): {e}"); - return ExitCode::FAILURE; - } - }; - let version = file.version(); - let Some(Ok(objects)) = file.all_objects() else { - eprintln!("{path}: no object-stream walk for {version}"); - return ExitCode::FAILURE; +fn compare(decoded: &DecodedEntity, rec: Option<&Record>, t: &mut Tally) -> bool { + let DecodedEntity::Mesh(m) = decoded else { + return false; }; - let Some(Ok(class_map)) = file.class_map() else { - eprintln!("{path}: no class map"); - return ExitCode::FAILURE; + let Some(rec) = rec else { + return true; }; - let twin = match dxf.as_deref().map(dxf_meshes).transpose() { - Ok(t) => t, - Err(e) => { - eprintln!("read failed: {e}"); - return ExitCode::FAILURE; - } - }; - let name = std::path::Path::new(&path) - .file_name() - .map(|n| n.to_string_lossy().into_owned()) - .unwrap_or(path.clone()); - - let (mut records, mut failures) = (0usize, 0usize); - for object in &objects { - let ObjectType::Custom(code) = object.kind else { - continue; - }; - let is_mesh = class_map - .by_type_code(code) - .is_some_and(|d| d.dxf_class_name == "MESH"); - if !is_mesh { - continue; - } - records += 1; - let handle = object.handle.value; - match entities::decode_from_raw_with_class_map(object, version, &class_map, code) { - DecodedEntity::Mesh(m) => { - println!( - "{name} ({version}) 0x{handle:X} closes version {} blend {} level {} \ - vertices {} faces {} edges {} creases {}", - m.version, - m.blend_crease, - m.subdivision_level, - m.vertices.len(), - m.faces.len(), - m.edges.len(), - m.creases.len() - ); - let Some(twin) = &twin else { continue }; - let Some(theirs) = twin.get(&handle) else { - println!(" DXF: no MESH with this handle"); - failures += 1; - continue; - }; - let ours = sequence(&m); - let mut differ = 0usize; - if ours.len() != theirs.len() { - differ += 1; - println!(" group count: dwg {} dxf {}", ours.len(), theirs.len()); - } - for (k, ((oc, ov), (tc, tv))) in ours.iter().zip(theirs).enumerate() { - if oc != tc || !same(*ov, tv) { - differ += 1; - if differ <= 10 { - println!(" [{k}] dwg {oc}={ov} dxf {tc}={tv}"); - } - } - } - println!( - " DXF: {} values compared, {differ} differ", - ours.len().min(theirs.len()) - ); - failures += differ; - } - DecodedEntity::Error { message, .. } => { - failures += 1; - println!("{name} ({version}) 0x{handle:X} ERROR {message}"); - } - other => println!( - "{name} ({version}) 0x{handle:X} type {:?}", - other.type_code() + // The groups after the `AcDbSubDMesh` subclass marker, up to the next marker. + let theirs: Vec<&twin::Group> = rec + .groups + .iter() + .skip_while(|g| !(g.code == 100 && g.value == "AcDbSubDMesh")) + .skip(1) + .take_while(|g| g.code != 100) + .collect(); + let ours = sequence(m); + t.int( + "number of AcDbSubDMesh groups", + ours.len() as i64, + Some(theirs.len() as i64), + ); + for (k, (code, value)) in ours.iter().enumerate() { + match theirs.get(k) { + Some(g) if g.code == *code => t.real(&format!("group {code} #{k}"), *value, g.real()), + Some(g) => t.int( + &format!("group code #{k}"), + i64::from(*code), + Some(i64::from(g.code)), ), + None => t.real(&format!("group {code} #{k}"), *value, None), } } - println!("{name}: {records} MESH"); - if failures > 0 { - ExitCode::FAILURE - } else { - ExitCode::SUCCESS - } + true +} + +fn main() -> ExitCode { + twin::run( + &Probe { + tag: "MESH", + class: Some("MESH"), + kind: None, + dxf_kind: "MESH", + decodes_on: |_| true, + note: "; the trailing count after the creases is read only where it is 0 (any \ + other value is refused), and R14 records, which have no DXF twin in the \ + corpus, are held to their data-stream boundary alone", + }, + compare, + ) } diff --git a/examples/probe_wipeout.rs b/examples/probe_wipeout.rs new file mode 100644 index 0000000..a172c6a --- /dev/null +++ b/examples/probe_wipeout.rs @@ -0,0 +1,127 @@ +//! Does the WIPEOUT field list, the raster-image record that +//! `src/entities/wipeout.rs` reads with IMAGE's decoder, close on every +//! corpus record, and do its values equal AutoCAD's DXF export? (#478) +//! +//! For every WIPEOUT record of every drawing under the corpus directory this +//! reports whether the decoder closed exactly on the record's data-stream +//! boundary, and, where the corpus holds AutoCAD's DXF export of the drawing, +//! compares what it read with the entity of the same handle (group 5): the +//! insertion point (10, 20, 30), the U and V vectors (11 to 32), the image size +//! (13, 23), the display flags (70), clipping (280), brightness (281), contrast +//! (282), fade (283), the clip mode (290, which the DXF writes from R2010), the +//! clip boundary type (71), its vertex count (91) and each vertex (14, 24). +//! +//! ```sh +//! python3 -I tools/corpus/fetch.py --dest ../dwg-corpus +//! cargo run --release --example probe_wipeout -- ../dwg-corpus +//! ``` + +#[path = "support/twin.rs"] +mod twin; + +use dwg::entities::DecodedEntity; +use dwg::entities::image::ClipBoundary; +use std::process::ExitCode; +use twin::{Group, Probe, Record, Tally}; + +fn compare(decoded: &DecodedEntity, rec: Option<&Record>, t: &mut Tally) -> bool { + let DecodedEntity::Wipeout(ours) = decoded else { + return false; + }; + let Some(rec) = rec else { + return true; + }; + let int = |code: u16| rec.first(code).and_then(Group::int); + let real = |code: u16| rec.first(code).and_then(Group::real); + t.real("insertion x (10)", ours.insertion_point.x, real(10)); + t.real("insertion y (20)", ours.insertion_point.y, real(20)); + t.real("insertion z (30)", ours.insertion_point.z, real(30)); + t.real("u x (11)", ours.u_vector.x, real(11)); + t.real("u y (21)", ours.u_vector.y, real(21)); + t.real("u z (31)", ours.u_vector.z, real(31)); + t.real("v x (12)", ours.v_vector.x, real(12)); + t.real("v y (22)", ours.v_vector.y, real(22)); + t.real("v z (32)", ours.v_vector.z, real(32)); + t.real("image width (13)", ours.image_size.x, real(13)); + t.real("image height (23)", ours.image_size.y, real(23)); + t.int("display flags (70)", i64::from(ours.display_flags), int(70)); + t.int("clipping (280)", i64::from(ours.clipping), int(280)); + t.int("brightness (281)", i64::from(ours.brightness), int(281)); + t.int("contrast (282)", i64::from(ours.contrast), int(282)); + t.int("fade (283)", i64::from(ours.fade), int(283)); + t.int("clip mode (290)", i64::from(ours.clip_mode), int(290)); + let (kind, points) = match &ours.clip_boundary { + ClipBoundary::Rectangle { + lower_left, + upper_right, + } => (1, vec![*lower_left, *upper_right]), + ClipBoundary::Polygon(points) => (2, points.clone()), + }; + t.int("clip boundary type (71)", kind, int(71)); + let xs: Vec> = rec + .groups + .iter() + .filter(|g| g.code == 14) + .map(Group::real) + .collect(); + let ys: Vec> = rec + .groups + .iter() + .filter(|g| g.code == 24) + .map(Group::real) + .collect(); + // A polygon the DXF closes by writing its first vertex again after the + // last: its count is one more than the record's, and that last vertex is + // compared with the record's first. + let closed_in_dxf = kind == 2 + && !points.is_empty() + && xs.len() == points.len() + 1 + && ys.len() == points.len() + 1; + if closed_in_dxf { + t.int( + "clip vertex count (91), with the DXF's closing vertex", + points.len() as i64 + 1, + int(91), + ); + t.real( + "closing vertex x (14), the first again", + points[0].x, + xs[points.len()], + ); + t.real( + "closing vertex y (24), the first again", + points[0].y, + ys[points.len()], + ); + } else { + t.int("clip vertex count (91)", points.len() as i64, int(91)); + } + for (k, point) in points.iter().enumerate() { + t.real( + &format!("clip vertex {k} x (14)"), + point.x, + xs.get(k).copied().flatten(), + ); + t.real( + &format!("clip vertex {k} y (24)"), + point.y, + ys.get(k).copied().flatten(), + ); + } + true +} + +fn main() -> ExitCode { + twin::run( + &Probe { + tag: "WIPEOUT", + class: Some("WIPEOUT"), + kind: None, + dxf_kind: "WIPEOUT", + decodes_on: |_| true, + note: "; unverified by value: the graphics-preview block before the fields, and \ + anything the DXF does not write", + }, + compare, + ) +} diff --git a/src/entities/wipeout.rs b/src/entities/wipeout.rs index 8512b8e..d368d86 100644 --- a/src/entities/wipeout.rs +++ b/src/entities/wipeout.rs @@ -19,15 +19,19 @@ //! `(271.921…, 3.988…, 0)`, u/v vectors of length `31.7077…`, image //! size `(1, 1)`, display flags `7`, clipping `true`, brightness `50`, //! contrast `50`, fade `0`, clip mode `0`, clip boundary type `2` and -//! four clip vertices — and lands on bit 2185 of a record whose data -//! stream ends at 2186, one bit of byte padding later. +//! four clip vertices — and lands on bit 2185, where the record's data +//! fields end: from R2010 the data stream closes with a one-bit +//! strings-present flag, so the fields end one bit before the handle +//! stream, which starts at 2186 (the boundary table in `objects::modern`). //! //! The previous field list here (`BL clip_state`, `BS count`, `BD2` //! vertices, `B show_clipped`, three `RC`s) matched no part of those //! bytes; it decoded the graphics-preview payload as geometry. //! -//! Only R2018 has been measured. The pre-R2010 branch is whatever -//! [`super::image::decode`] does for those versions. +//! Measured on every release since (CLEANROOM.md 2026-11-30, #478): the +//! corpus's seven WIPEOUT records, one on each release R14 to R2018, all close +//! on their data-stream boundary with this field list, and on R2000 to R2018 +//! their values equal AutoCAD's DXF export (`examples/probe_wipeout.rs`). use crate::bitcursor::BitCursor; use crate::error::Result;