Skip to content

fix(dxf): preserve LEADER vertex Z coordinates (#2245) - #2397

Merged
tanish2k09 merged 1 commit into
storytold:mainfrom
Zaxaerith:fix/2245-leader-vertex-elevation
Oct 31, 2026
Merged

tanish2k09 merged 1 commit into
storytold:mainfrom
Zaxaerith:fix/2245-leader-vertex-elevation

Conversation

@Zaxaerith

@Zaxaerith Zaxaerith commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Saving and reopening a LEADER flattens its vertex elevations to zero through both DXF and the DWG bridge (#2238 A7).

Root cause

The LEADER DXF reader uses the two-dimensional T::pts(10) helper and then calls to3(0.0), discarding group 30. The writer already emits group 10/20/30 for each vertex. Autodesk's LEADER DXF reference identifies those as the vertex's X/Y/Z coordinates.

Changes

  • Limit the production change to the LEADER arm in dxf_read/entities.rs.
  • Pair each group-10 X with the following vertex tag slice, bounded by the next group 10. Read Y and Z from that slice using the existing T lookup helpers.
  • Default an omitted Z to zero for that vertex only, rather than zipping a sparse list of group-30 values onto unrelated vertices.
  • Keep the shared two-dimensional helper, the writer, Common-property parsing, and all other entity readers unchanged.

Regression coverage

Added three default-enabled, synthetic tests (authored, not executed locally):

  • Exact XYZ values (1, 2, 4), (5, 6, 7), (9, 10, -3), plus wholly planar controls.
  • All arrow/spline flag combinations, a named dimension style, non-default color/lineweight/linetype scale and visibility, with exact Common-property comparisons.
  • Two saves compared against the original Drawing, retaining handles, vertex count/order and every modeled LEADER property.
  • All six supported save versions (R2000–R2018); DXF ASCII/binary and native-target DWG through existing IO APIs.
  • Independent synthetic DXF groups for all eight Z-presence patterns, including no group 30 at all and missing first/middle/last Zs. These also exercise Y/Z ordering within each vertex.

DXF/DWG compatibility

The reader handles the interleaved vertex groups written by CADCraft and the existing DWG bridge. An absent Z remains zero without consuming a subsequent vertex's Z. Ordinary 2D LEADERs keep their coordinates. No DWG codec, third-party source, dependency, format marker or external asset is changed.

This addresses the shared DXF-path loss; it does not claim two independent codec fixes or independent DWG interoperability. No SPLINE, MLINE, MULTILEADER, DIMENSION, extrusion or unrelated preservation changes are included.

Verification

Passed locally: git diff --check, staged diff whitespace checks, strict UTF-8 inspection and full diff review. Checked test registration, the public IO/type signatures, per-vertex scoping, unchanged writers/Common parsing, and absence of new unwrap/expect/panic/unsafe or ignored tests.

No local Rust/Cargo compilation, tests, rustfmt, Clippy, xtask, WASM builds or dependency downloads were performed. Regression tests were added but not executed locally; runtime behavior and formatting remain subject to GitHub CI. No first-save normalization or comparison tolerance was added.

Focused check for CI/maintainers (not run locally):

cargo test -p cadcraft-io --test it leader_vertex_elevation

Related

Fixes #2245. Related: #2238 A7 and #2237.

At review time #2237 remains open at ed37a1c8f83d7d995afacc4ace6dae32dd1f9483. Its roundtrip::dxf::extended::leaders_3d and roundtrip::dwg::extended::leaders_3d are still ignored and absent from this branch's test tree. This PR does not cherry-pick its framework or modify that PR.

When the matrix is available with this fix, review enabling those two regressions and execute them together with neighboring families across the applicable save-version/encoding domains. The Issue's full matrix acceptance has not been run or claimed complete here. Only in an environment containing those tests are these exact commands applicable:

cargo test -p cadcraft-io --test it 'roundtrip::dxf::extended::leaders_3d' -- --ignored --exact
cargo test -p cadcraft-io --test it 'roundtrip::dwg::extended::leaders_3d' -- --ignored --exact

Prepared with AI assistance for @Zaxaerith.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected LEADER vertex coordinate handling so each vertex retains its own Y and Z values. Missing coordinates now default to zero for that vertex.
  • Tests

    • Added coverage for LEADER vertex coordinates and properties across DXF and DWG formats, including missing elevations and varied coordinate tag order.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 5654240 and d13d087.

Files selected for processing: 3
  • crates/io/src/dxf_read/entities.rs
  • crates/io/tests/it/leader_vertex_elevation.rs
  • crates/io/tests/it/main.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

The LEADER parser now reads Y and Z coordinates from each vertex’s tag segment. Missing values default to zero. Integration tests cover DXF and DWG round trips and missing Z values.

Changes: LEADER Vertex Elevation Parsing

Layer / File(s) Summary
Scope coordinates to each LEADER vertex
crates/io/src/dxf_read/entities.rs
Each group 10 coordinate now uses group 20 and 30 values from the same vertex segment. Missing Y or Z values default to zero.
Verify LEADER vertex elevations
crates/io/tests/it/leader_vertex_elevation.rs, crates/io/tests/it/main.rs
Integration tests check vertex order and coordinates, LEADER and common properties, and entity metadata across DXF and DWG round trips. They also test eight patterns of present or missing Z values in authored DXF tags.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: aiongg

Merge Risk: Minimal · up to d13d0

LEADER elevations are parsed per vertex. No merge-blocking risk was identified; normal CI checks should run before merge.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning #2245 requires preservation of each LEADER XYZ vertex without normalization or tolerance. The parser change scopes group 20 and group 30 values to each group 10 vertex and defaults a missing Z to zero… Add or enable the corresponding #2237 regressions when they are available in this test tree. Run both listed DXF and DWG regression commands, the neighboring families, and the applicable save-version and encoding matrix. Record passing re…
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preserving LEADER vertex Z coordinates in DXF parsing.
Out of Scope Changes check Passed The production change is limited to the LEADER arm in crates/io/src/dxf_read/entities.rs. The new integration tests directly verify #2245 behavior and related LEADER and Common properties. No unrela…
Full details: Out of Scope Changes check

Explanation

The production change is limited to the LEADER arm in crates/io/src/dxf_read/entities.rs. The new integration tests directly verify #2245 behavior and related LEADER and Common properties. No unrelated entity reader, writer, codec, dependency, format marker, or external asset changes are present.

Full details: Linked Issues check

Explanation

#2245 requires preservation of each LEADER XYZ vertex without normalization or tolerance. The parser change scopes group 20 and group 30 values to each group 10 vertex and defaults a missing Z to zero. The added default-enabled tests cover XYZ values, missing-Z patterns, properties, repeated saves, DXF ASCII/binary, and native-target DWG across Version::ALL. However, the PR states that the regression tests were not executed locally. The corresponding #2237 regression tests remain absent and ignored, and the required listed checks, neighboring families, and applicable matrix have not been run or shown as passing.

Resolution

Add or enable the corresponding #2237 regressions when they are available in this test tree. Run both listed DXF and DWG regression commands, the neighboring families, and the applicable save-version and encoding matrix. Record passing results.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@assamaral assamaral left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested with a local build of this PR (d13d087) and ZWCAD 2025, DXF and DWG sides. All data synthetic (ezdxf, DXF 2018).

Fixture: four LEADERs in model space: vertices (0,0,4) (5,5,7) (10,5,7); a planar control; one with negative/mixed Z (-3.5, 0, 12.25); one with four vertices (Z 1,2,3,4).

  • cadcraft-cli convert to DXF and DWG with this build, then both files opened in ZWCAD 2025 and re-exported with _DXFOUT 2018: groups 10/20/30 of every vertex are identical to the control (the source DXF opened and re-exported by ZWCAD the same way), for all four leaders, from both the DXF and the DWG route. The same conversion with main (5654240) gives Z = 0 for every vertex of every leader, through DXF and DWG, as the issue says.
  • Sparse Z: a 4-vertex LEADER with group 30 removed from vertices 1 and 3 (raw edit). This build writes Z = 0, 2, 0, 4, and so does ZWCAD's own reading of the source (control): the omitted Z does not shift the next vertex's Z onto the previous one. Both ZWCAD re-exports (from the DXF and the DWG written by this build) match the control.
  • Regression: a real production drawing (private, ~10 MB DXF, 1.7k TEXT, no LEADER in it) converted to DXF and DWG with this build and with main: the files are byte-identical (same MD5 for DXF and for DWG). So the only change is the LEADER arm, as the description says.
  • Reading the diff: tags.split(|t| t.code == 10).skip(1) gives each vertex the slice up to the next group 10, which for the last vertex also covers the trailing LEADER groups (71/72/76/340/77/210…). That is fine because no other LEADER group uses 20 or 30, so the last vertex cannot pick up a foreign Y/Z; worth a one-line comment if you touch it again.
  • cargo test -p cadcraft-io --test it leader_vertex_elevation on this head: 3 passed. Not exercised: how ZWCAD draws the leaders (I compared exported groups only).

Verdict: APPROVE.

@SnotacusNexus

Copy link
Copy Markdown

Independently verified on Linux x86_64 (Arch, current Rust stable) against main at 336243e (0.14.0), with origin/main merged into the branch locally (clean). Your body says the three tests were authored but not executed locally — they run, and they do what you say.

The tests prove the bug. Plain main + only your crates/io/tests/it/leader_vertex_elevation.rs and the mod line:

test leader_vertex_elevation::dxf_preserves_leader_vertex_elevations ... FAILED
test leader_vertex_elevation::dwg_preserves_leader_vertex_elevations ... FAILED
test leader_vertex_elevation::missing_z_defaults_only_the_corresponding_vertex ... FAILED
assertion `left == right` failed: XYZ/order: leader.dxf R2000, pass=1, Handle(256)
  left:  [z: 0.0, 0.0, 0.0]
 right:  [z: 4.0, 7.0, -3.0]
test result: FAILED. 0 passed; 3 failed

That is #2245 exactly: every vertex flattened, not just a mis-ordered list.

On the branch (merged with main):

test result: ok. 239 passed; 0 failed

The mixed set (one LEADER at Z 4/7/-3, one wholly planar at Z 0) is what makes this a real test rather than a coincidence — a fix that copied Z from a neighbour would fail the planar control, and missing_z_defaults_only_the_corresponding_vertex is the one I'd keep permanently, since a sparse group-30 list zipped onto the wrong vertices is the tempting wrong fix here.

Useful context for the reviewer: #2238 A7 currently has no default-enabled coverage on main — the reproduction lives in the --ignored tests in #2237 — so this is the first thing that will actually go red-to-green when the fix lands.

Confidence: 99% (negative control and branch run both clean, full io suite unchanged otherwise).

@austin62jake austin62jake left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested on Windows 10 Pro x64 (Rust 1.99.1, cargo-nextest 0.9.150), with this PR merged onto current main (336243e). It merges cleanly, and it works.

The description says the tests weren't run locally, so I ran them:

  • All 3 leader_vertex_elevation tests pass with the fix and all 3 fail on main: DXF (ASCII and binary) and DWG, every version in Version::ALL, two saves each, and all eight Z-presence patterns.
  • cargo xtask ci passes all 7 steps (2622 tests) with this PR merged onto main together with five other small, unrelated PRs I tested at the same time (#2406, #2408, #2417, #2418, #2404, #2397), and #2198 so the gate runs on Windows.

The slice for the last vertex runs to the end of the record, but no LEADER group after the vertices uses code 20 or 30 (the normal and direction vectors are 210-233), so it can't pick up a stray Y or Z.

@tanish2k09
tanish2k09 merged commit 7cee285 into storytold:main Oct 31, 2026
6 checks passed
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.

DXF/DWG round trip flattens LEADER vertex elevations to zero

5 participants