Skip to content

fix(entities): decode the whole §20.4.38 VIEWPORT record on every release (#71) - #247

Merged
DrunkOnJava merged 11 commits into
mainfrom
fix/71-viewport-r2018
Oct 26, 2026
Merged

DrunkOnJava merged 11 commits into
mainfrom
fix/71-viewport-r2018

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Decode the whole §20.4.38 VIEWPORT record, with every version branch as the spec prints it. All 51 VIEWPORT records of the public corpus now close on their data-stream boundary (R14 to R2018), and on the 36 that have an AutoCAD DXF export of the same drawing every value read equals the DXF, matched by handle. Part of #71 (VIEWPORT; LEADER and MESH follow in their own PRs).

Spec reference

§20.4.38 VIEWPORT ENTITY (34): centre, width, height; R2000+ the view block (target, direction, twist, view height, lens, clip planes, snap angle, then four 2RDs and the circle zoom); R2007+ BS grid major; R2000+ frozen-layer count, status flags, TV style sheet, RC render mode, the two UCS flags and the UCS block; R2004+ BS shade plot mode; R2007+ the lighting block ending in a CMC. The decoder previously read the first three fields only, so every R2000+ record reported delta -819 (the old 9 errored records of sample_AC1032.dwg include its 6).

Nothing is measured against the spec and nothing is added to it: the list closes exactly as printed.

Records it was measured on

examples/probe_viewport.rs (new) prints every VIEWPORT with its values keyed by the DXF group §20.4.38 gives each field and, given the DXF twin, reports every disagreement:

File (~/Library/Caches/dwg-corpus/acadsharp, pinned by #225) Release Records Close Values compared with the DXF twin Differ
sample_AC1014.dwg R14 6 6 no twin
sample_AC1015.dwg R2000 6 6 252 0
sample_AC1018.dwg R2004 6 6 258 0
sample_AC1021.dwg R2007 6 6 294 0
sample_AC1024.dwg R2010 6 6 294 0
sample_AC1027.dwg R2013 6 6 294 0
sample_AC1032.dwg (= ../../samples/sample_AC1032.dwg, same sha256) R2018 6 6 294 0
export_sample.dwg R2018 9 9 no twin

sample_AC1032.dwg does have a DXF twin: ACadSharp's sample_AC1032_ascii.dxf, pinned by #225, is AutoCAD's export of the file whose sha256 (0e8faaca…) is our local R2018 sample. Values no default could produce agree: status flags 819232 / 819808 (group 90), circle zoom 1000, lens 50, every view centre and view height, and the ambient light colour 0xC2333333, i.e. group 421 3355443. The comparator was checked by tampering one significant digit of group 41 and the status word in a copy of the twin: it reported both.

Not measured: the 15 records of the R14 save and export_sample.dwg close but have no twin; no R13 file exists; every style sheet name in the corpus is empty; every snap angle and view twist angle is 0 (45 of 45 R2000+ records), so groups 50/51 agree only trivially; every ambient light colour is the true colour 0xC2333333 (33 of 33 R2007+ records), so an indexed colour has not been seen.

Review fixes (b3f0625): the probe now converts the stored radians to the degrees DXF writes for groups 50/51, and compares an indexed (0xC3) ambient colour through group 63 using the index in the BL word's low byte, not the BS (§2.11: always 0). Re-run on every VIEWPORT with a twin gives the same table: 252 / 258 / 294 / 294 / 294 / 294 values, 0 differ. Neither fix changes a number, for the reasons in the paragraph above.

C=~/Library/Caches/dwg-corpus/acadsharp   # python3 -I tools/corpus/fetch.py --dest ... (from #225)
cargo run --release --example probe_viewport -- $C/sample_AC1032.dwg $C/sample_AC1032_ascii.dxf
for v in 1015 1018 1021 1024 1027; do cargo run --release --example probe_viewport -- $C/sample_AC$v.dwg $C/sample_AC${v}_ascii.dxf; done
cargo run --release --example probe_viewport -- $C/export_sample.dwg

Coverage, ../../samples (the 19-file corpus)

cargo run --release --example coverage_report -- ../../samples

                          before (main 91eeae8)              after
sample_AC1032.dwg     776  57  9  92.2 %          782  57  3  92.9 %
TOTAL                3911 525  9  88.0 %         3917 525  3  88.1 %

Every other row is unchanged. Error histogram after: MESH 2, LEADER 1.

Coverage, public corpus (acadsharp/; nextgis/ unchanged, it holds no VIEWPORT)

file before deco / skip / err after deco / skip / err
export_sample.dwg 453 / 11 / 14 462 / 11 / 5
sample_AC1015.dwg 914 / 82 / 51 920 / 82 / 45
sample_AC1018.dwg 850 / 74 / 90 856 / 74 / 84
sample_AC1021.dwg 834 / 76 / 15 840 / 76 / 9
sample_AC1024.dwg 851 / 57 / 15 857 / 57 / 9
sample_AC1027.dwg 799 / 57 / 9 805 / 57 / 3
sample_AC1032.dwg 776 / 57 / 9 782 / 57 / 3
TOTAL (10 files) 6438 / 885 / 308 6483 / 885 / 263

empty.dwg, geoloc.dwg and sample_AC1014.dwg are unchanged (the R14 VIEWPORTs already closed on their 3-field list). These are the decoded/skipped/errored columns of tools/corpus/baseline.tsv (#225); no other column moves for a decoder-only change. baseline.tsv is not in this PR because #225 is not on main yet; it needs regenerating (measure.py run + measure.py baseline) once #225 lands.

Class census and reference closure

probe_class_census <f> and probe_reference_closure <f> on all 19 files of ../../samples: every census RESULT: every class reached its declared num_objects, every closure RESULT: the walk is closed, reference counts unchanged (573 / 542 / 507 / 491 / 369 per R2000-R2013 file, 2852 with the 6 known soft danglers on sample_AC1032.dwg, R14 0 with 292 no-boundary records). Both probes are walk-level and do not run entity decoders.

Docs

  • docs/data/spec-coverage.tsv §20.4.38 partial → closes (not complete: R14 has no twin, there is no R13 file, and the promotion goes through the oracle scorer of Epic: AutoCAD's own DXF export as the value oracle #99); docs/spec-coverage.md regenerated with tools/ci/spec_coverage.py --write.
  • ARCHITECTURE.md: new §7k with the table above; the §7i VIEWPORT row points at it.
  • examples/dump_decoded_entities.rs prints the VIEWPORT values instead of "(stub)".

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • RUSTFLAGS="-D warnings" cargo test --release --all-features (real-file tests ran against ../../samples; nothing printed "skipping")
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
  • Shown on real files: the tables above. No unit tests added; the existing roundtrip_viewport_header test only follows the new signature (it builds the R14 shape, which is still the three fields).

Source-provenance declaration

By submitting this PR I certify that my contribution does not incorporate executable code from any source whose license is incompatible with Apache-2.0. Specifically:

  • No Autodesk DWG SDK source (RealDWG, ObjectARX, ObjectDBX) or NDA-protected Autodesk documentation was consulted or imported.
  • No Open Design Alliance Teigha / Drawings SDK source was consulted or imported. The ODA's public Open Design Specification for .dwg files PDF is explicitly allowed (see CLEANROOM.md).
  • No GPL-licensed DWG implementation source (LibreDWG, etc.) was consulted or imported.

My contribution is based on §20.4.38 (field list, types, DXF group codes) and §20.4.75 (group 421 pairs with a CMC's BL RGB word) of the ODA's freely-redistributable Open Design Specification for .dwg files (v5.4.1), on the corpus bytes, and on AutoCAD's DXF exports of the same drawings read as data files (ACadSharp samples/ at c30a97ce, MIT, pinned by #225). No third-party code or comments were read.

Developer Certificate of Origin

By submitting this PR, I certify that the contribution complies with the Developer Certificate of Origin 1.1.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T16:23:52.535099Z 47b2264 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a0152dff99

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread examples/probe_viewport.rs Resolved
Comment thread examples/probe_viewport.rs Resolved
…ease (#71)

The decoder read only the centre, width and height, so every R2000+
VIEWPORT failed the exact-boundary check (delta -819 on the six records
of sample_AC1032.dwg). The field list §20.4.38 prints, with its R2000+,
R2004+ and R2007+ branches, closes at delta 0 on all 51 VIEWPORT
records of the public corpus, R14 to R2018, and on the 36 that have
AutoCAD's DXF export of the same drawing every value equals the DXF,
matched by handle (1,686 values).

examples/probe_viewport.rs prints each record's values by DXF group and
compares them with a DXF twin; ARCHITECTURE.md §7k records the
measurement. §20.4.38 moves to closes.
… by their index

DXF writes groups 50 and 51 in degrees where the record stores radians,
and an indexed CMC (0xC3) keeps its index in the low byte of the BL word,
not in the BS that §2.11 says is always 0. Every corpus viewport has
zero angles and a true-colour ambient light, so the numbers do not move;
ARCHITECTURE.md §7k now says those fields are exercised only trivially.
@DrunkOnJava
DrunkOnJava force-pushed the fix/71-viewport-r2018 branch from b3f0625 to 5cde06e Compare October 26, 2026 11:13

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5cde06e573

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread examples/probe_viewport.rs Resolved
# Conflicts:
#	tools/corpus/baseline.tsv
@DrunkOnJava
DrunkOnJava disabled auto-merge October 26, 2026 11:49
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 12:01
# Conflicts:
#	ARCHITECTURE.md
#	docs/data/spec-coverage.tsv
#	docs/spec-coverage.md
# Conflicts:
#	ARCHITECTURE.md
#	docs/data/spec-coverage.tsv
#	docs/spec-coverage.md
#	tools/corpus/baseline.tsv
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 15:40
@DrunkOnJava
DrunkOnJava disabled auto-merge October 26, 2026 15:43
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 16:26
@DrunkOnJava
DrunkOnJava merged commit d65d1ad into main Oct 26, 2026
26 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/71-viewport-r2018 branch October 26, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant