Commit 4a606d6
authored
fix(export,drawing-2d): stop writing NaN/Infinity into GLB, COLLADA, KMZ and SVG (#3329)
* fix(export,drawing-2d): stop writing NaN/Infinity into GLB, COLLADA, KMZ and SVG
Neither format has a lexical form for a non-finite number, and four writers
wrote one anyway. Observed on main, per value, by running each writer:
export_glb_from_meshes +/-Inf position -> "min":[null,-0.5,0.0] and
"translation":[null,0.5,0.0] (serde_json renders a
non-finite float as null); NaN position reached the
BIN chunk while min/max stayed finite, because
NaN < min and NaN > max are both false.
export_collada_from_meshes a triangle whose first X was -Infinity came out
as `NaN 0 0 inf 0 0 inf 0 1` -- the AABB re-centring
spread one bad vertex over every good one, and
`inf` is not even an xs:float lexical form.
export_kmz_collada_from_meshes same, through COLLADA.
exportToSVG x1="NaN" / x1="-Infinity" at thirteen unguarded
.toFixed(3) interpolations, and one non-finite
corner of the bounds moved every finite line in the
drawing via boundsCenter -> offsetX.
The three exporters that take the viewer's flattened MeshData now pass all
four float arrays (positions, normals, colours, per-mesh origins) through one
gate, mesh_input::scrub_nonfinite, before either per-mesh loop reads any of
them -- one emitter rather than a guard at each point a value becomes bytes.
Non-finite becomes 0.0, matching usd::fmt::fmt_f32; alpha becomes 1.0, since
scrubbing it to 0 would turn a colour defect into an invisible mesh. An
all-finite input is passed through borrowed: no copy, byte-identical output.
The SVG exporter gains the same shape: one svgNum(), mirroring the DXF
writer's fmt() in the same package, which had guarded these values all along
-- two writers of the same drawing disagreeing about the same input was the
defect. computeTransform sanitises the bounds before deriving anything from
them, so a degenerate corner no longer relocates the rest of the drawing.
collada.rs's float formatting moves to collada_fmt.rs to stay under its
module-size budget; the emitted text is unchanged.
* refactor(drawing-2d): split the paper transform out of svg-exporter.ts
The `svgNum()` guard and the `computeTransform` bounds sanitising added by
this PR took `svg-exporter.ts` to 652 lines against a budget of 613, failing
the module-size ratchet. Split rather than raise.
`computeTransform`, `scaleLabel` and `transformPoint` move to a new
`svg-transform.ts` alongside `Transform2D` and `finiteOr0`. Fitting a
drawing's world bounds onto a sheet — and reporting the scale actually used —
is one cohesive job, separable from turning the fitted geometry into markup.
None of the three ever read `this`, so they become plain functions and the
call sites drop the `this.` prefix.
`createTitleBlock`'s `scaleLabel` parameter is renamed `scaleText`: that name
now belongs to the imported function, and shadowing it there would read as a
call site.
A pure move, proven rather than asserted: the moved bodies `diff` clean
against the originals modulo the dedent and the `private` -> `export
function` keyword swap, and the `Transform2D` body is byte-identical. Full
`packages/drawing-2d` suite green (518 tests, 39 files), as is
`packages/export`.
The `svg-exporter.ts` row ratchets DOWN 613 -> 537 to the new measured count,
with `packages/drawing-2d`'s ALLOWLIST_DIGESTS entry re-pinned in the same
commit. Edited by hand rather than with `--update`, which would also have
ratcheted the unrelated headroom rows the gate notes for
`packages/export/src/schema-converter.ts` and
`packages/server-client/src/parquet-tables.ts` — those belong to other PRs.
No row moved up.1 parent e8c0d71 commit 4a606d6
12 files changed
Lines changed: 849 additions & 166 deletions
File tree
- .changeset
- packages/drawing-2d/src
- rust/export
- src
- gltf
- tests
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
0 commit comments