Skip to content

refactor(collision): remove dead falsy guards in shape implementations#8884

Merged
willeastcott merged 2 commits into
mainfrom
refactor-collision-dead-guards
Jun 12, 2026
Merged

refactor(collision): remove dead falsy guards in shape implementations#8884
willeastcott merged 2 commits into
mainfrom
refactor-collision-dead-guards

Conversation

@willeastcott

Copy link
Copy Markdown
Contributor

Continues the component-consistency series (#8871, #8876, #8878-#8882). Sibling of #8883.

Changes

  • Removes the falsy guards in the box/capsule/cylinder/cone createPhysicalShape implementations (he ? he.x : 0.5, component.axis ?? 1, component.radius ?? 0.5, component.height ?? 2). These are fossils from the ComponentData era:
    • The component declares class-field defaults (_axis = 1, _radius = 0.5, _height = 2), which initialize before any system code can run.
    • _halfExtents is structurally never null - the setter only ever copies into the existing Vec3.
    • The sphere implementation has always read component.radius unguarded, so the guards were an inconsistency, not a safety net.
    • The cylinder/cone guards even defaulted height to 1 while the class default is 2 - proof they were never live.
  • Removes the unreachable else branches in Trigger.initialize and Trigger._getEntityTransform: this.component is assigned unconditionally in the constructor and never cleared, so the entity-transform fallback could never execute. initialize now reuses _getEntityTransform instead of duplicating its live branch.

Caveat

The only path that ever reached the numeric guards was an out-of-contract assignment like collision.radius = null after initialization - and spheres already passed that straight to Ammo. JSDoc declares these properties as number.

These lines sit inside Ammo-gated paths the unit tests cannot reach, so this was verified by review plus npm test / npm run lint / npm run build / npm run build:types + npm run test:types.

🤖 Generated with Claude Code

The box/capsule/cylinder/cone implementations still guarded against
missing component values (`he ? he.x : 0.5`, `?? 1`, `?? 0.5`, `?? 2`).
These are fossils from the ComponentData era: the component now declares
class-field defaults that initialize before any system code runs, the
halfExtents setter only ever copies into the existing Vec3, and the
sphere implementation has always read `component.radius` unguarded. The
cylinder/cone guards even defaulted height to 1 while the class default
is 2 - proof they were never live.

Also removes the unreachable `else` branches in Trigger.initialize and
Trigger._getEntityTransform: `this.component` is assigned unconditionally
in the constructor and never cleared, so the entity-transform fallback
could never execute. Trigger.initialize now reuses _getEntityTransform
instead of duplicating its live branch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors the collision Ammo-backed shape creation paths to remove dead nullish/falsy fallbacks and unreachable branches, aligning collision shape implementations with the post-ComponentData CollisionComponent defaults and invariants.

Changes:

  • Simplifies Trigger.initialize() by delegating transform setup to _getEntityTransform() and removes the unreachable this.component fallback logic.
  • Removes nullish/falsy guard defaults in box/capsule/cylinder/cone createPhysicalShape() implementations, relying on CollisionComponent’s class-field defaults and non-null halfExtents.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/framework/components/collision/trigger.js Removes unreachable fallback branch and reuses _getEntityTransform() for trigger initialization.
src/framework/components/collision/system.js Removes dead guards in Ammo shape creation for box/capsule/cylinder/cone to match component invariants/defaults.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@willeastcott willeastcott merged commit 2043503 into main Jun 12, 2026
10 checks passed
@willeastcott willeastcott deleted the refactor-collision-dead-guards branch June 12, 2026 12:03
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