Skip to content
Merged
45 changes: 45 additions & 0 deletions CLEANROOM.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions docs/spec-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). |
Expand Down
207 changes: 56 additions & 151 deletions examples/probe_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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<HashMap<u64, Vec<(u16, String)>>> {
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::<f64>()
.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 <file.dwg> [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,
)
}
Loading
Loading