Skip to content

fix(entities): keep the entity colour's true colour and transparency words, RGB first (§2.11) (#126) - #359

Merged
DrunkOnJava merged 4 commits into
mainfrom
fix/entity-colour-words
Oct 27, 2026
Merged

DrunkOnJava merged 4 commits into
mainfrom
fix/entity-colour-words

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

read_common_entity_data read an R2004+ entity colour's two optional BL words in the wrong order and dropped both. This keeps them (CommonEntityData::color_raw, color_rgb, color_alpha) with the RGB word first, as §2.11 lists them, and adds probe_entity_colour, which compares them with AutoCAD's own export of the corpus drawings. Split out of #358 (the ENTITIES writer, #126) at the integrator's request so the finding lands on its own before the writer.

What this changes and what it does not, measured on main (b9beccb): the two BLs are 32 bits each, so reading them in either order leaves the cursor in the same place, and the old code discarded both. No decoded count, no decoded entity value and no consumer moves: the entity structs carry no colour, SVG, glTF and DXF export read none of it, and nothing in examples/dxf_oracle reads CommonEntityData. The order became observable only once the words were kept; the first cut of #358 kept them in the order main read them and disagreed with the export on every entity that carries both. What is new is the public data: three fields on CommonEntityData, which #358 writes as DXF groups 62, 420 and 440.

Spec reference

ODA v5.4.1 §2.11 CMC: the BS colour index, whose high byte flags a true colour BL (0x80), a colour book handle (0x40, the RGB and name are then in the AcDbColor object) and a transparency BL (0x20), read in that order after the BS, followed by the names when flagged. §20.4.1 puts the CMC in the common entity data.

  • src/common_entity.rs: the three fields, and the read order.
  • examples/probe_entity_colour.rs: the probe, wired into the Corpus job (.github/workflows/ci.yml, Cargo.toml).
  • ARCHITECTURE.md 7al: the finding with its evidence table.

Test plan

  • cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings, RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
  • Shown working on real files, no new unit tests: cargo run --release --features dxf-reader --example probe_entity_colour -- <dwg-corpus> pairs every entity of the 42 corpus drawings that have an AutoCAD export (R2000 to R2018, 2,579 entities) with the export's record of the same handle. Exit 0, 0 disagree:
release        entities     index  agree true col  agree  book   transp  agree  both    agree  exchanged
AC1015 (2000)       437       437    437        0      0     0        0      0     0        0          0
AC1018 (2004)       437       403    403       33     33     1      148    148    14       14          0
AC1021 (2007)       437       403    403       33     33     1      148    148    14       14          0
AC1024 (2010)       437       403    403       33     33     1      148    148    14       14          0
AC1027 (2013)       437       403    403       33     33     1      148    148    14       14          0
AC1032 (2018)       394       360    360       33     33     1      148    148    14       14          0

The both column is the entities that carry both words, the only ones the order can touch. Read RGB first (agree), all 14 per release match the export's 420 and 440. With the two words exchanged, which is what the old order would have produced had it kept them (exchanged), none does. Before and after on one real entity, the LINE 9D4 of sample_AC1032.dwg: the export reads 62 183, 420 8404418, 440 16777216; the stream holds 0xC2802142 then 0x01000000. After: color_rgb = 0xC2802142 (low 24 bits 8404418), color_alpha = 0x01000000 (16777216). Before, in the old order: transparency 0xC2802142, colour 0x01000000.

  • The DXF oracle: no row of it scores an entity's common colour (it scores LAYER, MTEXT, table style and dimension colours), and it reads none of CommonEntityData, so its baseline cannot move; the Corpus job checks that. The new probe is the measurement against the same AutoCAD exports.
  • An entity whose common data does not read is a failure (drawing, kind and handle named, exit 1), not a dropped record, and a run that reads and pairs no entity prints NOT MEASURED. The real corpus run above reads all 2,579 with 0 unread. Negative run, PROBE_ENTITY_COLOUR_TRUNCATE=4 (cuts every record to 4 bytes): 2,609 entities named unreadable, NOT MEASURED, exit 1.
  • The colour book entity (one per R2004+ drawing, CIRCLE 99F of sample_AC1018.dwg and its re-saves) is counted and not compared: its 420 is in the AcDbColor object, not in the entity.
  • cargo test --release --all-features --lib common_entity: 4 passed (the preamble round-trips), on this head.
  • The full cargo test --release --all-features runs in CI; I did not run it locally on this head.
  • Not measured on the corpus: R13 and R14 (their colour is the bare index; AC1014 drawings are skipped).

Existing tests and code changed

CommonEntityData gains three public fields (nothing outside read_entity_mode_onwards builds one). No existing test changed.

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 (v5.4.1) is the source for §2.11 and §20.4.1.
  • No GPL-licensed DWG implementation source (LibreDWG, etc.) was consulted or imported.

The only other inputs are the public corpus and AutoCAD's own DXF exports of its drawings. No algorithm-description comments in other projects were read.

Developer Certificate of Origin

I affirm the contribution is my own work and may be distributed under the project's Apache-2.0 license.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T03:59:41.845759Z d39998d 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: 8fe0fac281

ℹ️ 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_entity_colour.rs Resolved
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 27, 2026 04:01
@DrunkOnJava
DrunkOnJava merged commit cd31538 into main Oct 27, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/entity-colour-words branch October 27, 2026 04:09
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