Skip to content

[Bugs] ifc-converter: overflowed normals take the unit fallback; keep the bench unpublished - #1166

Merged
Aymericr merged 1 commit into
mainfrom
cursor/ifc-normal-overflow-fallback-31b3
Oct 27, 2026
Merged

Aymericr merged 1 commit into
mainfrom
cursor/ifc-normal-overflow-fallback-31b3

Conversation

@Aymericr

@Aymericr Aymericr commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #1165.

  • The normal recompute also checks 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.
  • New tests/geometry-validity.test.ts: on a four-vertex quad with two NaN normals, replaced.normals is exactly 2. A vertex with a NaN position isn't counted.
  • src/__bench__ is excluded from tsconfig.json, and package.json files has !dist/__bench__. npm pack --dry-run lists no bench file, and bun run bench:normals still 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.ts covering 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 npm files list so benchmarks stay dev-only while bench:normals still runs from source.

Reviewed by Cursor Bugbot for commit aa0effd. Bugbot is set up for automated code reviews on this repo. Configure here.

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T01:38:11.694389Z aa0effd PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Aymericr Aymericr added the bot:bugs label Oct 27, 2026 — with Cursor

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 || 0 rounding turned into a zero normal. It now takes the (0,0,1) fallback.
  • Both tests check the right things: exact replaced.normals counts, 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 by tsc. That's fine as long as bench:normals keeps running.

No visible UI change, so no screenshots needed. I'll merge it on the next triage pass if checks pass.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 Aymericr left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

[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, a NaN length (an Inf - Inf sum), and an Infinity length. 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), and Math.hypot gives Infinity, 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.normals is 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) and v = (1,0,0), and u × 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.json now excludes src/__bench__, so tsc --build doesn't emit it to dist. No file under src/ imports it, so nothing pulls it back in.
  • package.json files adds !dist/__bench__ as a second guard. Negated files entries are supported by npm ≥ 7.
  • bench:normals still runs from source through bun run.
  • I didn't rerun npm pack --dry-run myself. 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.

@Aymericr
Aymericr merged commit 8be3bf9 into main Oct 27, 2026
4 checks passed
@Aymericr
Aymericr deleted the cursor/ifc-normal-overflow-fallback-31b3 branch October 27, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants