Repository navigation
[Bugs] ifc-converter: overflowed normals take the unit fallback; keep the bench unpublished - #1166
Conversation
…nch unpublished - A summed normal whose length overflows to Infinity (coordinates around 1e154 or more) now gets the (0, 0, 1) fallback instead of [0, 0, 0]. - tests/geometry-validity.test.ts: an exact replaced.normals count on a small mesh, and the overflow case. - src/__bench__ is out of the typecheck include and out of the published files.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Aymericr
left a comment
There was a problem hiding this comment.
Maintainer review: looks good to merge once CI is green.
- The
Number.isFinite(length)guard is correct. Before it, a sum like (0, 0, Infinity) gave Infinity/Infinity = NaN, which the|| 0rounding turned into a zero normal. It now takes the (0,0,1) fallback. - Both tests check the right things: exact
replaced.normalscounts, and the vertex with a NaN position is skipped rather than counted. - The bench is kept out of the package twice over, through the tsconfig exclude and
!dist/__bench__. One small trade-off:src/__bench__is no longer type-checked bytsc. That's fine as long asbench:normalskeeps running.
No visible UI change, so no screenshots needed. I'll merge it on the next triage pass if checks pass.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aa0effd3a2
ℹ️ 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".
| @@ -0,0 +1,38 @@ | |||
| import { describe, expect, test } from 'bun:test' | |||
| import { emptyConversionReport, keepValidTriangles } from '../src/geometry-validity' | |||
There was a problem hiding this comment.
Exercise the regression through the package API
This newly created bug-fix test imports an internal source module, bypassing the package export surface and coupling the test to implementation placement. T-001 requires tests through package exports and bug regressions in the existing feature test file; since keepValidTriangles is not exported from src/index.ts, reproduce this overflow through the existing imported-mesh conversion tests rather than importing ../src/geometry-validity directly.
AGENTS.md reference: AGENTS.md:L5-L5
Useful? React with 👍 / 👎.
Aymericr
left a comment
There was a problem hiding this comment.
[Maintainer] Cross-review at aa0effd
Approved at aa0effd.
CI at this head: quality ✅, cli-smoke ✅, Changed paths ✅, Cursor Bugbot ✅ (no findings). mergeable_state is clean.
1. Overflowed normals take the fallback (packages/ifc-converter/src/geometry-validity.ts:186-188)
length > 0 && Number.isFinite(length)now routes every unusable sum to(0,0,1): a zero length, aNaNlength (anInf - Infsum), and anInfinitylength. A finite, non-zero sum is normalised exactly as before, so ordinary meshes get the same results as #1165.- The 1e155 test is real. That triangle sums to
(0, 0, Infinity), andMath.hypotgivesInfinity, which I checked in Node. #1165 turned that into[0,0,0], so the test fails on the old code and passes here. - Non-blocking: in this particular test the true direction happens to be +z, so the fallback and the correct normal coincide. Scaling the edge vectors before the cross product would recover a real direction in overflow cases. That isn't worth doing for coordinates no real IFC file reaches.
2. Exact count (tests/geometry-validity.test.ts)
I checked the quad by hand:
- Triangles
(0,1,2)and(2,1,3)are kept.(2,3,4)uses vertex 4, whose position is NaN, so it's dropped:vertices: 1,triangles: 1. - Of the four kept vertices, 0 and 2 had NaN normals, so
replaced.normalsis exactly 2. The dropped vertex 4 isn't counted, because the recompute runs on the compacted buffers. - For
(0,1,2),u = (0,0,1)andv = (1,0,0), andu × v = (0,1,0). So the expected[0,1,0]normals are the true face normal, not just the input's. - The overflow test's count is exactly 3, which pins the count as well.
3. Bench stays unpublished
tsconfig.jsonnow excludessrc/__bench__, sotsc --builddoesn't emit it todist. No file undersrc/imports it, so nothing pulls it back in.package.jsonfilesadds!dist/__bench__as a second guard. Negatedfilesentries are supported by npm ≥ 7.bench:normalsstill runs from source throughbun run.- I didn't rerun
npm pack --dry-runmyself. The config makes Bugs' result follow. - Non-blocking: the bench file is now outside every typecheck, so it can bit-rot silently. If that matters, give it its own
tsconfig.bench.json, or include it in the test typecheck.
No merge from me.
Follow-up to #1165.
Number.isFinite(length), so a summed normal that overflows to Infinity gets (0,0,1) instead of [0,0,0]. The test uses a triangle with coordinates around 1e155.tests/geometry-validity.test.ts: on a four-vertex quad with two NaN normals,replaced.normalsis exactly 2. A vertex with a NaN position isn't counted.src/__bench__is excluded fromtsconfig.json, andpackage.jsonfileshas!dist/__bench__.npm pack --dry-runlists no bench file, andbun run bench:normalsstill runs.All 106 converter tests pass.
Note
Low Risk
Shading-only edge case for extreme coordinates plus packaging excludes; core geometry stripping logic is unchanged aside from the overflow guard.
Overview
Follow-up to normal recomputation in IFC mesh cleanup: when area-weighted normal sums overflow to Infinity (very large vertex coordinates, ~1e155), normalization now requires a finite length and uses the existing (0,0,1) fallback instead of producing invalid zero normals.
Adds
geometry-validity.test.tscovering NaN normal replacement counts on a quad with a bad vertex, and the overflow fallback path.Publishing:
src/__bench__is excluded from TypeScript build and!dist/__bench__is omitted from the npmfileslist so benchmarks stay dev-only whilebench:normalsstill runs from source.Reviewed by Cursor Bugbot for commit aa0effd. Bugbot is set up for automated code reviews on this repo. Configure here.