Skip to content

Fix DWG attribute coordinates, DXF FIELD writing, hatch angles and writer performance - #13

Merged
jogibear9988 merged 2 commits into
node-projects:masterfrom
jip8:fix/dwg-dxf-fidelity-and-writer-performance
Oct 28, 2026
Merged

jogibear9988 merged 2 commits into
node-projects:masterfrom
jip8:fix/dwg-dxf-fidelity-and-writer-performance

Conversation

@jip8

@jip8 jip8 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

DWG-to-DXF conversion can apply INSERT transforms twice to attributes, write hatch pattern lines at the wrong angle, and fail when referenced FIELD objects have no owner. Large writer queues also incur repeated array shifts, and minification renames classes used by runtime DXF type lookup.

This change:

  • Preserves stored attribute coordinates in both CadInsertTemplate attribute lookup paths by removing the additional INSERT transformation.
  • Converts hatch pattern line angles from radians to degrees for DXF group code 53, with a regression test for a 45-degree line.
  • Uses indexed traversal for entity and object writer queues, retaining traversal of newly appended objects and clearing queues afterward.
  • Preserves class and function names in the published minified bundle using esbuild --keep-names.
  • Assigns missing owners to FIELD objects referenced by FieldList.fields and Field.children while preserving existing owners. Nested child fields are also queued for serialization.

Validation:

  • 665 tests passed, 16 skipped.
  • TypeScript typecheck and build passed.
  • Minified bundle built successfully and passed a DXF-writing smoke test.
  • FIELD regression tests cover three nested levels and preservation of an existing owner.

The full external DWG corpus described during investigation was not rerun as part of this change; the results above are from the repository test suite and local smoke test.

@jogibear9988

Copy link
Copy Markdown
Member

Review of head 5bf4c0e: 673 tests passed, 8 skipped; typecheck, build, and minified bundle creation passed locally. Both GitHub CI jobs are green. The queue traversal, hatch-angle conversion, and keep-names changes look consistent with the surrounding implementation. A DXF round trip with a translated, rotated, scaled INSERT preserved stored attribute coordinates and height.

I reproduced two FIELD issues:

  1. [P2] Allocate handles for newly queued child fields (lines 799–801). Setting owner does not register a Field or allocate its handle. Add a parent Field to rootDictionary, then push new Field() children/grandchildren into parent.children: their handles remain 0, the output contains only the parent FIELD, and its child reference is 0. Handle-based deduplication suppresses descendants. Could you register the graph before HANDSEED/references are emitted and test default-constructed fields? The new test masks this by manually assigning handles 10000/10001/10002.

  2. [P2] Resolve child-field ownership before FIELDLIST fallback owners (line 834). With distinct nonzero handles, parent.children = [child], initially null owners, and list.fields = [child, parent], child.owner becomes the list. The later item.owner ??= field preserves that synthetic owner, so the child is emitted with the wrong owner despite the parent's hard ownership link. I reproduced owner handle 39 instead of parent handle 10000. Could missing owners be derived from hard child links before list fallbacks, with coverage for both child and parent appearing in the list? Autodesk describes FIELDLIST as an index of fields, and FIELD group 360 is a hard ownership link.

Could you also add attribute-loading regression tests covering both linked first/end handles and ownedObjectsHandlers? The existing InsertAttributeTransform test calls applyAttributeTransform directly, so it still passes with the old reader behavior. An independently generated DWG fixture with nonidentity INSERT translation/rotation/scale and expected attribute coordinates would help verify the DWG side of this change.

@jogibear9988
jogibear9988 merged commit cbf3639 into node-projects:master Oct 28, 2026
2 checks passed
@jogibear9988

Copy link
Copy Markdown
Member

Merged into master in cbf3639 and pushed, with follow-up fixes in 60b9201.

Both FIELD issues from my review are resolved:

  • Discover/register nested fields and allocate unique handles before writing the header and references, so HANDSEED includes all fields.
  • Resolve missing hard child owners before applying FIELDLIST fallback owners, preserving existing owners and making list ordering irrelevant.
  • Refresh DXF class metadata after registering fields.

Added regression coverage for default-constructed nested fields, both FIELDLIST orderings, existing owners, emitted handles/owner references, HANDSEED, repeat writes, and both attribute-loading paths with translated/rotated/scaled INSERTs. Updated the original FIELD test to count object records rather than matching the FIELD class name.

Validation: 680 tests passed, 8 skipped; typecheck, build, bundle, changed-file ESLint, git diff --check, and a minified-bundle FIELD serialization smoke test all passed. The external DWG corpus was not rerun.

Thanks for the contribution. This PR is now incorporated into master.

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.

2 participants