Skip to content

fix(entities): read §20.4.47 LEADER's end point projection and tails on every release (#71) - #249

Merged
DrunkOnJava merged 6 commits into
mainfrom
fix/71-leader
Oct 26, 2026
Merged

DrunkOnJava merged 6 commits into
mainfrom
fix/71-leader

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Decode the whole §20.4.47 LEADER record on every release. The decoder read four 3BDs after the points where the section has five, then stopped. With the fifth one (the R14+ end point projection) and the section's own R13-R14 and R2000+ branches read, all 7 LEADER records of the public corpus close at delta 0, R14 to R2018. There is one measured departure from the spec: from R2010 the record does not write the box height and width. Part of #71; VIEWPORT is #247 and MESH follows.

Spec reference

§20.4.47 LEADER (45): unknown B, BS annotation type, BS path type, BL numpts, the points, then origin, extrusion, x direction and offset to block insertion point as 3BDs, R14+ 3BD end point projection, R13-R14 BD dimgap, box height and box width BDs, hook line and arrowhead Bs, then the R13-R14 tail (BS arrowhead type, BD dimasz, B, B, BS, BS byblock colour, B, B) or the R2000+ tail (BS, B, B).

What the old list called the end projection was the origin. It equals the first point, which is the default §20.4.47 gives the origin.

Measured departure: no box from R2010

Release Delta before Closes as Box height / width
R14 −282 R13-R14 branch 1.844821… / 16.374004…
R2000 / R2004 / R2007 −144 R2000+ branch 1.844821… / 16.374004…, equal to DXF 40 / 41
R2010 / R2013 / R2018 −12 R2000+ branch without the box not in the record

On R2010+ the record is exactly 132 bits shorter than on R2007, which is two non-default BDs. The six bits after the end point projection are 011000, the same six bits that follow the box width on R2000-R2007: hook line on x 0 (DXF 74 = 0), arrowhead on 1, BS 0, B 0, B 0. The R2010+ DXF exports still carry 40/41, so AutoCAD stores them elsewhere, not in this record. On R14 the creation-time values are the drawing's ISO-25 DIMSTYLE: dimgap 0.625 = DIMGAP (147) and dimasz 2.5 = DIMASZ (41).

Records it was measured on

examples/probe_leader.rs (new) prints each LEADER and compares it with its DXF twin by handle. AutoCAD's export inserts a hook-line vertex before the last point (75 = 1). The probe states that rule and compares the remaining vertices; groups the DXF omits (71, 72) are listed as omitted, not compared against assumed defaults.

$ C=~/Library/Caches/dwg-corpus/acadsharp   # fetched by #225's tools/corpus/fetch.py
$ cargo run --release --example probe_leader -- $C/sample_AC1014.dwg      # R14: no DXF twin, checked by close only
$ for v in 1015 1018 1021 1024 1027 1032; do cargo run --release --example probe_leader -- $C/sample_AC$v.dwg $C/sample_AC${v}_ascii.dxf; done
sample_AC1014.dwg (AC1014 (R14)) 0x512 closes  annot 0 path 0 points 3 ... box 1.844821309997273 x 16.37400410337938 dimgap 0.625 arrowhead_type 0 dimasz 2.5 unknown (false, true, 256) byblock_color 256 tail (false, false)
sample_AC1015.dwg (AC1015 (2000)) 0x512 closes  ... box 1.844821309997273 x 16.37400410337938 unknown (0, false, false)
  DXF: 13 values compared, 0 differ, omitted groups [72, 71]
sample_AC1018.dwg (AC1018 (2004)) ... DXF: 13 values compared, 0 differ
sample_AC1021.dwg (AC1021 (2007)) ... DXF: 13 values compared, 0 differ
sample_AC1024.dwg (AC1024 (2010)) 0x512 closes  ... box (not in record) unknown (0, false, false)
  DXF: 11 values compared, 0 differ, omitted groups [72, 71]
sample_AC1027.dwg (AC1027 (2013)) ... DXF: 11 values compared, 0 differ
sample_AC1032.dwg (AC1032 (2018)) ... DXF: 11 values compared, 0 differ

(R14 has no twin, so it is checked by close only. No other file of either corpus holds a LEADER. This is one leader saved seven times: the field order is pinned across releases, but the box departure rests on one drawing.)

Coverage, ../../samples

cargo run --release --example coverage_report -- ../../samples, base 240f376:

                       before                        after
sample_AC1032.dwg   776  57  9  92.2 %          777  57  8  92.3 %
TOTAL              3911 525  9  88.0 %         3912 525  8  88.0 %

The error histogram loses LEADER (0x002D) → 1.

Coverage, public corpus (acadsharp/; nextgis/ unchanged at 7343 / 1100 / 0)

file before deco / skip / err after
sample_AC1014.dwg 676 / 461 / 105 677 / 461 / 104
sample_AC1015.dwg 914 / 82 / 51 915 / 82 / 50
sample_AC1018.dwg 850 / 74 / 90 851 / 74 / 89
sample_AC1021.dwg 834 / 76 / 15 835 / 76 / 14
sample_AC1024.dwg 851 / 57 / 15 852 / 57 / 14
sample_AC1027.dwg 799 / 57 / 9 800 / 57 / 8
sample_AC1032.dwg 776 / 57 / 9 777 / 57 / 8
TOTAL (10 files) 6438 / 885 / 308 6445 / 885 / 301

These are the decoded/skipped/errored columns of tools/corpus/baseline.tsv. The file is not in this PR because #225 is not on main; it will be regenerated in the serial rebase after #247.

Class census and reference closure

probe_class_census and probe_reference_closure on all 19 files of ../../samples give output identical to the run before the change: every census reaches its declared counts, every walk is closed, and the reference counts are unchanged.

Docs

  • docs/data/spec-coverage.tsv §20.4.47 partial → closes, with the departure in the note; docs/spec-coverage.md regenerated.
  • ARCHITECTURE.md new §7l (table and evidence above); the §7i LEADER row points at it.
  • Leader fields are renamed to the spec's vocabulary (origin, x_direction, end_point_projection) and gain the box, flags and both tails.

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)
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
  • Shown on real files: the records above. No unit tests were added. The existing roundtrip_3pt_leader now also writes the fields the corrected R2010+ list reads after its four 3BDs, so that it still builds a whole record.

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.47 of the ODA's freely-redistributable Open Design Specification for .dwg files (v5.4.1). Every field name comes from it, including the DXF codes 40, 41, 210, 211 and 212. It also uses the corpus bytes and AutoCAD's DXF exports of the same drawing, read as data files (ACadSharp samples/ at c30a97ce, MIT, pinned by #225). The R2010+ absence of the box is measured, not taken from any source. 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.

…on every release (#71)

The decoder read four 3BDs after the points where §20.4.47 has five, so
the field it called the end projection was the origin, and it stopped
before the box and the flags: delta -282 on R14, -144 on R2000-R2007,
-12 on R2010+. With the R14+ end point projection read and the
section's R13-R14 and R2000+ tails, the one LEADER of each of seven
saves of a drawing closes at delta 0, R14 to R2018.

One departure is measured: from R2010 the box height and width are not
written. The R2010+ record is exactly two non-default BDs shorter than
the R2007 one, and the six bits after the end point projection equal
the six after the box width on R2000-R2007. Values equal the DXF twin on
R2000 to R2018; on R14 dimgap and dimasz equal the ISO-25 DIMSTYLE's
DIMGAP and DIMASZ.

examples/probe_leader.rs reproduces it; ARCHITECTURE.md §7l records
it. §20.4.47 moves to closes.
@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-26T18:15:12.690990Z c96c706 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.

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