refactor(collision): remove dead falsy guards in shape implementations#8884
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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 unreachablethis.componentfallback logic. - Removes nullish/falsy guard defaults in box/capsule/cylinder/cone
createPhysicalShape()implementations, relying on CollisionComponent’s class-field defaults and non-nullhalfExtents.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continues the component-consistency series (#8871, #8876, #8878-#8882). Sibling of #8883.
Changes
createPhysicalShapeimplementations (he ? he.x : 0.5,component.axis ?? 1,component.radius ?? 0.5,component.height ?? 2). These are fossils from the ComponentData era:_axis = 1,_radius = 0.5,_height = 2), which initialize before any system code can run._halfExtentsis structurally never null - the setter only ever copies into the existingVec3.component.radiusunguarded, so the guards were an inconsistency, not a safety net.1while the class default is2- proof they were never live.elsebranches inTrigger.initializeandTrigger._getEntityTransform:this.componentis assigned unconditionally in the constructor and never cleared, so the entity-transform fallback could never execute.initializenow reuses_getEntityTransforminstead of duplicating its live branch.Caveat
The only path that ever reached the numeric guards was an out-of-contract assignment like
collision.radius = nullafter initialization - and spheres already passed that straight to Ammo. JSDoc declares these properties asnumber.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