Repository navigation
feat(DXF): export triangulated surfaces as DXF - #237
francoisbonneau wants to merge 2 commits into
Conversation
Write an ASCII DXF (R12) with one 3DFACE per triangle, on a layer named after the surface. Forbidden layer characters are replaced by '_' and non-ASCII characters are written as \U+XXXX escapes, decoded by the DXF reader. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
francoisbonneau
left a comment
There was a problem hiding this comment.
Cross-repo review — feat/dxf_triangles_export
This is the only open PR on this branch, so there is nothing to check across repos. No other workspace repo depends on the TriangulatedSurface3D output extension list or on DXF.
Overall the writer is clean: it is short, uses the classic locale and max_digits10, checks the stream state after writing, and round-trip tests use the existing DXF reader. Nothing blocks the merge; points 2 and 4 are worth fixing first.
Design
- The
\U+XXXXescape is encoded in one file and decoded in another.dxf_input.cppalready hasappend_utf8/decode_unicode_escapes.dxf_triangulated_output.cppreimplements the reverse UTF-8 decoding. A small internaldxf_stringsheader holding both directions would keep them consistent and let one test cover both. - The declared version does not match the layer names written. The header sets
$ACADVER = AC1009(R12). R12 limits layer names to 31 characters fromA-Z 0-9 $ - _, with no spaces. Yet the test writesGalerie \U+00E9_1. Lenient readers accept it, but a strict R12 reader may not. Either declare a newer version (e.g. AC1015, which accepts such names and\U+escapes) or document that names are not strictly R12. - The reader and writer cover different types. The reader produces
PolygonalSurface3D, but onlyTriangulatedSurface3Dcan be exported. Since3DFACEalso handles quads, aPolygonalSurface3Doutput limited to polygons with 3 or 4 vertices would be almost free. Follow-up only, not blocking.
Readability / robustness
- Forbidden characters are incomplete.
FORBIDDEN_LAYER_CHARACTERSlacks the comma,, which AutoCAD also forbids in symbol table names. - UTF-8 continuation bytes are not validated.
layer_namedoes not check that the bytes after a leading byte match10xxxxxx. A truncated sequence such as\xC3followed byAswallows the ASCII character into a bogus code point. Checking(b & 0xC0) == 0x80and falling back to_would fix it. Bytes>= 0xF8are also treated as 4-byte leaders. - Tests and includes. No test covers "empty name → layer
0" or "code point > U+FFFF →_".dxf_triangulated_output.hppusesstd::string_viewwithout including<string_view>.
Performance
- Large test file.
tests/data/galeries_and_cylinder.og_tsf3dadds a 675 KB binary to a public repo. The in-memory test already covers precision and naming, so a much smaller mesh would probably do for the round trip, unless this file reproduces a specific real case.
The writer itself has no performance issue: one pass over triangles, no per-face allocation (the layer name is computed once), and no std::endl.
|
🤖 claude-cross-repo-review: complete |
Polygonal surfaces with polygons of 3 or 4 vertices are written as 3DFACE, like triangulated surfaces, by a shared writer. Polygons with more vertices raise a data error before the file is created. The \U+XXXX encoding and decoding of DXF strings, and the number of 3DFACE corners, are shared by the reader and the writers. The layer names not being strictly R12 is documented. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
francoisbonneau
left a comment
There was a problem hiding this comment.
Cross-repo review, 2nd pass — feat/dxf_triangles_export @ 17e0b19
This is still the only open PR on this branch. The new commit adds PolygonalSurface3D export and refactors the writer. Note that the existing approval predates this commit, and the diff has roughly doubled since then.
Follow-up on the previous review
| # | Point | Status |
|---|---|---|
| 1 | Duplicated \U+XXXX escape logic |
✅ Factored into dxf_common.hpp/.cpp |
| 2 | R12 declared, but layer names are not R12 | ✅ Documented in write_dxf_surface |
| 3 | No PolygonalSurface3D output |
✅ Added through the shared write_dxf_surface(SurfaceMesh3D) |
| 4 | Comma , missing from forbidden layer characters |
❌ Still missing in FORBIDDEN_LAYER_CHARACTERS |
| 5 | UTF-8 continuation bytes not validated | ❌ Not fixed, and now contradicted by the docs (see A) |
| 6 | Tests for empty name / > U+FFFF, <string_view> include |
dxf_triangulated_output.hpp and dxf_polygonal_output.hpp still use std::string_view without <string_view>, and both test cases are still missing |
| 7 | 675 KB binary test file | ❌ Unchanged |
New findings
A. Readability / robustness: docs and code disagree (dxf_common.hpp). The encode_unicode_escapes doc says "Invalid UTF-8 sequences … are replaced by '_'". In fact only stray continuation bytes and sequences truncated at the end of the string are replaced. \xC3 followed by A gives \U+00C1 and swallows the A. Overlong sequences and bytes >= 0xF8 also pass through. Checking (b & 0xC0) == 0x80 on each continuation byte would make the code match the docs. Since this is now a shared utility, fixing the code is better than weakening the doc.
B. Design (minor): unneeded check for triangulated surfaces. The DXFSurfaceWriter constructor walks every polygon to check that none has more than 4 vertices before opening the file. This is a good choice: no partial file is left, and it is tested. For TriangulatedSurface3D the check can never fail, but it costs one O(n) pass with no allocation, so it can stay as is.
C. Readability (minor): layer_name filters characters below 0x20 but not DEL (0x7F).
The rest looks good. The refactor removes about 170 duplicated lines, and the dxf_input.cpp changes are mechanical. The new tests cover a quad plus a triangle, a 3-byte UTF-8 name round trip, and the pentagon error with no file left behind.
Summary: nothing blocks the merge. I recommend fixing A and 4 before merging (both are small), then getting a fresh approval, since it predates this commit.
|
🤖 claude-cross-repo-review: complete |
Summary
Adds a
dxfwriter forTriangulatedSurface3DandPolygonalSurface3D.$ACADVER=AC1009), one3DFACEper polygon. A triangle repeats its third corner as fourth one.PolygonalSurface3D: polygons with 3 or 4 vertices. A polygon with more vertices raises a data error before the file is created.3DFACErather than a polyface mesh: polyface vertex indices are 16-bit in strict readers (max 32,767 vertices). The DXF reader merges the colocated corners back on load.0if unnamed). Characters forbidden in layer names are replaced by_; non-ASCII characters are written as\U+XXXX, which the DXF reader decodes.A-Z 0-9 $ - _), so that the surface name is kept. Lenient readers accept them. A newer version (e.g. AC1015) is not declared, because it requires handles and complete TABLES, BLOCKS and OBJECTS sections.max_digits10precision.Code organization
internal/dxf_surface_output: single writer for both surface types (takes aSurfaceMesh3D).internal/dxf_common:\U+XXXXencoding and decoding, and the number of3DFACEcorners, shared by the reader and the writer.Tests
test-dxf: round trip of the newgaleries_and_cylinder.og_tsf3d(17,072 triangles): same vertex and triangle counts, same positions.test-dxf: small triangulated surface with large coordinates and nameGalerie é:1, reloaded exactly, namedGalerie é_1.test-dxf: polygonal surface with a quad and a triangle, namedBaie €(3-byte UTF-8 character), reloaded exactly with the same name.test-dxf: a pentagon raises a data error and no file is written.dxflisted as an output extension ofTriangulatedSurface3DandPolygonalSurface3D.Not checked in a CAD tool (AutoCAD, etc.).
🤖 Generated with Claude Code