Skip to content

fix(tables): VPORT's aspect ratio and view mode in AutoCAD's terms (§20.4.64) - #238

Merged
DrunkOnJava merged 2 commits into
mainfrom
fix/vport-dxf-values
Oct 26, 2026
Merged

DrunkOnJava merged 2 commits into
mainfrom
fix/vport-dxf-values

Conversation

@DrunkOnJava

Copy link
Copy Markdown
Owner

Summary

VPORT's aspect ratio and view mode in AutoCAD's terms, as §20.4.64 prescribes: the stored second BD is the view width (view_width, with aspect_ratio() dividing by the height), and view_mode is the group-71 value assembled from the four stored bits and UCSFOLLOW.

Spec reference

§20.4.64 VPORT:

  • "Aspect ratio BD 41: The number stored here is actually the aspect ratio times the view height (40), so this number must be divided by the 40-value to produce the aspect ratio that entget gives." VportEntry::aspect_ratio held the stored product (the module docs already noted it "observes as the view width").
  • "View mode X 71, 4 bits: 0123 — 0: 71's bit 0 (1), 1: 71's bit 1 (2), 2: 71's bit 2 (4), 3: OPPOSITE of 71's bit 4 (16)", with "UCSFOLLOW B 71 … bit 3 (8) of the 71-group". view_mode held the four raw bits packed first-read-high.

aspect_ratio (the field) is renamed view_width and gains the method; view_mode keeps its name and now holds the DXF 71 value. The one existing assertion on the field is renamed; no test added. examples/dump_decoded_entities prints the ratio.

Test plan

cargo run --release --features dxf-reader --example dxf_oracle -- <corpus-dir>

Before (main), the VPORT table:

  field                                    group            R14   R2000   R2004   R2007   R2010   R2013   R2018   total
  aspect_ratio                             41                      ≠8/8    ≠8/8    ≠8/8    ≠8/8    ≠8/8    ≠2/2   0/0/42/0
  view_mode                                71                      ≠8/8    ≠8/8    ≠8/8    ≠8/8    ≠8/8    ≠2/2   0/0/42/0
  arc_2013.dwg                57 VPORT          aspect_ratio                       41         DWG 603.8576017130621  DXF 2.033190578158458
  arc_2013.dwg                57 VPORT          view_mode                          71         DWG 1  DXF 0

After (this branch):

  aspect_ratio() (view_width / view_height) 41                         =       =       =       =       =       =   42/0/0/0
  view_mode                                71                         =       =       =       =       =       =   42/0/0/0

603.8576017130621 / 297.0 is the 2.033190578158458 the R2013 export writes; the stored bits 0001 (front clip at the eye) give 71 = 0. Every other VPORT field the decoder surfaces agrees on all 42 records except geoloc.dwg's view height and centre, which differ as a view does between two saves and are listed on #99 as open.

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.

Based on ODA spec v5.4.1 §20.4.64 and AutoCAD's own DXF exports in nextgis/dwg_samples and the ACadSharp samples/ directory, read as data. No permissively-licensed project's 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.

Refs #99

…20.4.64)

§20.4.64 says VPORT's second BD is the aspect ratio times the view
height, to be divided by the height, and that the view mode is four
bits mapping to group 71 bits 1, 2, 4 and the opposite of 16, with
UCSFOLLOW giving bit 8. VportEntry surfaced both as stored: an
aspect_ratio of 603.86 where AutoCAD exports 2.0332, and a view_mode of
1 where it exports 0. The DXF value oracle found both disagreeing on
all 42 VPORTs of the nextgis and ACadSharp exports.

The stored BD is now view_width, with aspect_ratio() dividing by the
height, and view_mode is the group-71 value assembled as §20.4.64
prescribes, UCSFOLLOW included. Both now equal the export on all 42.

Refs #99
@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-26T10:32:17.359649Z 269a176 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.

@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 10:31
@DrunkOnJava
DrunkOnJava merged commit 21d423b into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/vport-dxf-values branch October 26, 2026 10:53
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
The pre-R2007 VIEW decoder read the view centre as two BDs, the view
mode as a BS and stopped after the associated-UCS bit. §20.4.60 gives a
2RD centre ("not bit-pair coded"), a 4-bit view mode (the encoding
VPORT uses), an RC render mode from R2000, the paper-space bit, and
from R2000 the associated-UCS bit followed, when set, by the UCS origin,
axes, elevation and orthographic type. The three ACadSharp VIEW records
of the R14, R2000 and R2004 saves errored on a reserved BD code; with
the spec's list all three close on their boundary (ACadSharp errors
308 -> 305, decoded 6438 -> 6441; nextgis unchanged, it has no VIEW).

The view mode stays the stored four bits, as on R2007+; surfacing it as
group 71 for VIEW and VPORT alike follows #238. The pre-R2007 synthetic
test writes the spec's layout.

Refs #256
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
The pre-R2007 VIEW decoder read the view centre as two BDs, the view
mode as a BS and stopped after the associated-UCS bit. §20.4.60 gives a
2RD centre ("not bit-pair coded"), a 4-bit view mode (the encoding
VPORT uses), an RC render mode from R2000, the paper-space bit, and
from R2000 the associated-UCS bit followed, when set, by the UCS origin,
axes, elevation and orthographic type. The three ACadSharp VIEW records
of the R14, R2000 and R2004 saves errored on a reserved BD code; with
the spec's list all three close on their boundary (ACadSharp errors
308 -> 305, decoded 6438 -> 6441; nextgis unchanged, it has no VIEW).

The view mode stays the stored four bits, as on R2007+; surfacing it as
group 71 for VIEW and VPORT alike follows #238. The pre-R2007 synthetic
test writes the spec's layout.

Refs #256
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
The pre-R2007 VIEW decoder read the view centre as two BDs, the view
mode as a BS and stopped after the associated-UCS bit. §20.4.60 gives a
2RD centre ("not bit-pair coded"), a 4-bit view mode (the encoding
VPORT uses), an RC render mode from R2000, the paper-space bit, and
from R2000 the associated-UCS bit followed, when set, by the UCS origin,
axes, elevation and orthographic type. The three ACadSharp VIEW records
of the R14, R2000 and R2004 saves errored on a reserved BD code; with
the spec's list all three close on their boundary (ACadSharp errors
308 -> 305, decoded 6438 -> 6441; nextgis unchanged, it has no VIEW).

The view mode stays the stored four bits, as on R2007+; surfacing it as
group 71 for VIEW and VPORT alike follows #238. The pre-R2007 synthetic
test writes the spec's layout.

Refs #256
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
The pre-R2007 VIEW decoder read the view centre as two BDs, the view
mode as a BS and stopped after the associated-UCS bit. §20.4.60 gives a
2RD centre ("not bit-pair coded"), a 4-bit view mode (the encoding
VPORT uses), an RC render mode from R2000, the paper-space bit, and
from R2000 the associated-UCS bit followed, when set, by the UCS origin,
axes, elevation and orthographic type. The three ACadSharp VIEW records
of the R14, R2000 and R2004 saves errored on a reserved BD code; with
the spec's list all three close on their boundary (ACadSharp errors
308 -> 305, decoded 6438 -> 6441; nextgis unchanged, it has no VIEW).

The view mode stays the stored four bits, as on R2007+; surfacing it as
group 71 for VIEW and VPORT alike follows #238. The pre-R2007 synthetic
test writes the spec's layout.

Refs #256
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
* fix(tables): read the pre-R2007 VIEW record as §20.4.60 gives it

The pre-R2007 VIEW decoder read the view centre as two BDs, the view
mode as a BS and stopped after the associated-UCS bit. §20.4.60 gives a
2RD centre ("not bit-pair coded"), a 4-bit view mode (the encoding
VPORT uses), an RC render mode from R2000, the paper-space bit, and
from R2000 the associated-UCS bit followed, when set, by the UCS origin,
axes, elevation and orthographic type. The three ACadSharp VIEW records
of the R14, R2000 and R2004 saves errored on a reserved BD code; with
the spec's list all three close on their boundary (ACadSharp errors
308 -> 305, decoded 6438 -> 6441; nextgis unchanged, it has no VIEW).

The view mode stays the stored four bits, as on R2007+; surfacing it as
group 71 for VIEW and VPORT alike follows #238. The pre-R2007 synthetic
test writes the spec's layout.

Refs #256

* test(corpus): record the three VIEW records #256's fix decodes

sample_AC1014, sample_AC1015 and sample_AC1018 each decode one more
record (their VIEW) and error one fewer; measure.py check passes.
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
§20.4.60 stores VIEW's view mode as four bits, "0: 71's bit 0 (1), 1:
71's bit 1 (2), 2: 71's bit 2 (4), 3: OPPOSITE of 71's bit 4 (16)", and
notes that bit 3 (8) of group 71 "can not be specified". Both VIEW paths
surfaced the raw bits; they now surface the group-71 value through the
conversion VPORT uses (§20.4.64, #238), with no UCSFOLLOW bit.

The DXF value oracle compares ViewEntry::view_mode with group 71
directly now, instead of converting the stored bits in its scorer: equal
on all 6 VIEW records, R2000 to R2018. Its baseline row is renamed from
"view_mode (stored bits, as group 71)" to "view_mode". The two VIEW
round-trip tests write the bits 0001, whose group-71 value is 0.

Refs #256
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
§20.4.60 stores VIEW's view mode as four bits, "0: 71's bit 0 (1), 1:
71's bit 1 (2), 2: 71's bit 2 (4), 3: OPPOSITE of 71's bit 4 (16)", and
notes that bit 3 (8) of group 71 "can not be specified". Both VIEW paths
surfaced the raw bits; they now surface the group-71 value through the
conversion VPORT uses (§20.4.64, #238), with no UCSFOLLOW bit.

The DXF value oracle compares ViewEntry::view_mode with group 71
directly now, instead of converting the stored bits in its scorer: equal
on all 6 VIEW records, R2000 to R2018. Its baseline row is renamed from
"view_mode (stored bits, as group 71)" to "view_mode". The two VIEW
round-trip tests write the bits 0001, whose group-71 value is 0.

Refs #256
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
§20.4.60 stores VIEW's view mode as four bits, "0: 71's bit 0 (1), 1:
71's bit 1 (2), 2: 71's bit 2 (4), 3: OPPOSITE of 71's bit 4 (16)", and
notes that bit 3 (8) of group 71 "can not be specified". Both VIEW paths
surfaced the raw bits; they now surface the group-71 value through the
conversion VPORT uses (§20.4.64, #238), with no UCSFOLLOW bit.

The DXF value oracle compares ViewEntry::view_mode with group 71
directly now, instead of converting the stored bits in its scorer: equal
on all 6 VIEW records, R2000 to R2018. Its baseline row is renamed from
"view_mode (stored bits, as group 71)" to "view_mode". The two VIEW
round-trip tests write the bits 0001, whose group-71 value is 0.

Refs #256
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
§20.4.60 stores VIEW's view mode as four bits, "0: 71's bit 0 (1), 1:
71's bit 1 (2), 2: 71's bit 2 (4), 3: OPPOSITE of 71's bit 4 (16)", and
notes that bit 3 (8) of group 71 "can not be specified". Both VIEW paths
surfaced the raw bits; they now surface the group-71 value through the
conversion VPORT uses (§20.4.64, #238), with no UCSFOLLOW bit.

The DXF value oracle compares ViewEntry::view_mode with group 71
directly now, instead of converting the stored bits in its scorer: equal
on all 6 VIEW records, R2000 to R2018. Its baseline row is renamed from
"view_mode (stored bits, as group 71)" to "view_mode". The two VIEW
round-trip tests write the bits 0001, whose group-71 value is 0.

Refs #256
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
§20.4.60 stores VIEW's view mode as four bits, "0: 71's bit 0 (1), 1:
71's bit 1 (2), 2: 71's bit 2 (4), 3: OPPOSITE of 71's bit 4 (16)", and
notes that bit 3 (8) of group 71 "can not be specified". Both VIEW paths
surfaced the raw bits; they now surface the group-71 value through the
conversion VPORT uses (§20.4.64, #238), with no UCSFOLLOW bit.

The DXF value oracle compares ViewEntry::view_mode with group 71
directly now, instead of converting the stored bits in its scorer: equal
on all 6 VIEW records, R2000 to R2018. Its baseline row is renamed from
"view_mode (stored bits, as group 71)" to "view_mode". The two VIEW
round-trip tests write the bits 0001, whose group-71 value is 0.

Refs #256
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
§20.4.60 stores VIEW's view mode as four bits, "0: 71's bit 0 (1), 1:
71's bit 1 (2), 2: 71's bit 2 (4), 3: OPPOSITE of 71's bit 4 (16)", and
notes that bit 3 (8) of group 71 "can not be specified". Both VIEW paths
surfaced the raw bits; they now surface the group-71 value through the
conversion VPORT uses (§20.4.64, #238), with no UCSFOLLOW bit.

The DXF value oracle compares ViewEntry::view_mode with group 71
directly now, instead of converting the stored bits in its scorer: equal
on all 6 VIEW records, R2000 to R2018. Its baseline row is renamed from
"view_mode (stored bits, as group 71)" to "view_mode". The two VIEW
round-trip tests write the bits 0001, whose group-71 value is 0.

Refs #256
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
§20.4.60 stores VIEW's view mode as four bits, "0: 71's bit 0 (1), 1:
71's bit 1 (2), 2: 71's bit 2 (4), 3: OPPOSITE of 71's bit 4 (16)", and
notes that bit 3 (8) of group 71 "can not be specified". Both VIEW paths
surfaced the raw bits; they now surface the group-71 value through the
conversion VPORT uses (§20.4.64, #238), with no UCSFOLLOW bit.

The DXF value oracle compares ViewEntry::view_mode with group 71
directly now, instead of converting the stored bits in its scorer: equal
on all 6 VIEW records, R2000 to R2018. Its baseline row is renamed from
"view_mode (stored bits, as group 71)" to "view_mode". The two VIEW
round-trip tests write the bits 0001, whose group-71 value is 0.

Refs #256
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
§20.4.60 stores VIEW's view mode as four bits, "0: 71's bit 0 (1), 1:
71's bit 1 (2), 2: 71's bit 2 (4), 3: OPPOSITE of 71's bit 4 (16)", and
notes that bit 3 (8) of group 71 "can not be specified". Both VIEW paths
surfaced the raw bits; they now surface the group-71 value through the
conversion VPORT uses (§20.4.64, #238), with no UCSFOLLOW bit.

The DXF value oracle compares ViewEntry::view_mode with group 71
directly now, instead of converting the stored bits in its scorer: equal
on all 6 VIEW records, R2000 to R2018. Its baseline row is renamed from
"view_mode (stored bits, as group 71)" to "view_mode". The two VIEW
round-trip tests write the bits 0001, whose group-71 value is 0.

Refs #256
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
§20.4.60 stores VIEW's view mode as four bits, "0: 71's bit 0 (1), 1:
71's bit 1 (2), 2: 71's bit 2 (4), 3: OPPOSITE of 71's bit 4 (16)", and
notes that bit 3 (8) of group 71 "can not be specified". Both VIEW paths
surfaced the raw bits; they now surface the group-71 value through the
conversion VPORT uses (§20.4.64, #238), with no UCSFOLLOW bit.

The DXF value oracle compares ViewEntry::view_mode with group 71
directly now, instead of converting the stored bits in its scorer: equal
on all 6 VIEW records, R2000 to R2018. Its baseline row is renamed from
"view_mode (stored bits, as group 71)" to "view_mode". The two VIEW
round-trip tests write the bits 0001, whose group-71 value is 0.

Closes #256 (with #263, #279 and #293, every decoded VIEW value now equals the export).
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
§20.4.60 stores VIEW's view mode as four bits, "0: 71's bit 0 (1), 1:
71's bit 1 (2), 2: 71's bit 2 (4), 3: OPPOSITE of 71's bit 4 (16)", and
notes that bit 3 (8) of group 71 "can not be specified". Both VIEW paths
surfaced the raw bits; they now surface the group-71 value through the
conversion VPORT uses (§20.4.64, #238), with no UCSFOLLOW bit.

The DXF value oracle compares ViewEntry::view_mode with group 71
directly now, instead of converting the stored bits in its scorer: equal
on all 6 VIEW records, R2000 to R2018. Its baseline row is renamed from
"view_mode (stored bits, as group 71)" to "view_mode". The two VIEW
round-trip tests write the bits 0001, whose group-71 value is 0.

Closes #256 (with #263, #279 and #293, every decoded VIEW value now equals the export).
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