Skip to content

[code-simplifier] Simplify GeospatialCamera flyTo logic and improve consistency#17991

Open
github-actions[bot] wants to merge 1 commit intomasterfrom
code-simplifier/geospatial-camera-2026-02-28-89b6dadbf1d4f351
Open

[code-simplifier] Simplify GeospatialCamera flyTo logic and improve consistency#17991
github-actions[bot] wants to merge 1 commit intomasterfrom
code-simplifier/geospatial-camera-2026-02-28-89b6dadbf1d4f351

Conversation

@github-actions
Copy link
Contributor

Code Simplification - 2026-02-28

This PR simplifies recently modified code in the GeospatialCamera system to improve clarity, consistency, and maintainability while preserving all functionality.

Files Simplified

  • packages/dev/core/src/Cameras/geospatialCamera.ts - Extracted duplicate flyTo logic, fixed comparison operator
  • packages/dev/core/src/Cameras/geospatialCameraMovement.ts - Simplified zoom speed calculation

Improvements Made

1. Reduced Duplication (DRY Principle)

  • Issue: Identical 6-line block for setting up flyTo targets was duplicated in updateFlyToDestination() and flyToAsync()
  • Solution: Extracted common logic into private helper method _setFlyToTargets()
  • Impact: Eliminates 6 lines of duplicate code, single source of truth, easier maintenance

2. Fixed Inconsistent Comparison Operator

  • Issue: Line 232 used != while line 264 used !== for undefined checks
  • Solution: Changed targetPitch != undefined to targetPitch !== undefined
  • Impact: Consistent strict equality checks throughout the codebase

3. Simplified Zoom Speed Calculation

  • Issue: Intermediate variable zoomTargetDistance used only once with nullish coalescing
  • Solution: Calculate distance inline using ternary operator, assign directly to multiplier
  • Impact: Clearer logic flow, fewer lines, reduced cognitive load

Changes Based On

Recent changes from PR #17990 (merged 2026-02-28):

  • GeospatialCamera API improvements
  • Method renaming for consistency (calculateUpVectorFromPointToRef)
  • Yaw direction fix
  • Removal of @experimental tags

Testing

The simplifications preserve exact functionality:

  • ✅ No behavioral changes - logic is identical
  • ✅ All method signatures unchanged
  • ✅ Test file exists: packages/dev/core/test/unit/Cameras/geospatialCamera.test.ts
  • ✅ Code follows TypeScript best practices

Review Focus

Please verify:

  • Functionality is preserved (no behavioral changes)
  • Simplifications improve code quality
  • Changes align with project conventions
  • The extracted _setFlyToTargets() method correctly handles all cases

Statistics

  • Files changed: 2
  • Lines added: 24
  • Lines removed: 21
  • Net change: +3 lines (but eliminates duplication)

Automated by Code Simplifier Agent - analyzing code from the last 24 hours

AI generated by Code Simplifier

  • expires on Mar 1, 2026, 12:54 AM UTC

- Extract duplicate flyTo target setup logic into private _setFlyToTargets() method
- Fix inconsistent undefined check (use !== instead of !=) in updateFlyToDestination
- Simplify zoom speed calculation by removing unnecessary intermediate variable
- Improves DRY principle by eliminating 6 lines of duplicated code

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sebavan sebavan marked this pull request as ready for review February 28, 2026 01:19
Copilot AI review requested due to automatic review settings February 28, 2026 01:19
@sebavan sebavan enabled auto-merge (squash) February 28, 2026 01:19
@sebavan
Copy link
Member

sebavan commented Feb 28, 2026

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR simplifies the GeospatialCamera system by extracting a repeated code block into a private helper, fixing an inconsistent comparison operator, and inlining a single-use intermediate variable in the zoom speed calculation. It is part of a series of cleanups following the recent PR #17990 which introduced API improvements.

Changes:

  • Extracted duplicated fly-to target setup logic from updateFlyToDestination() and flyToAsync() into a new private _setFlyToTargets() helper method
  • Fixed != undefined (loose equality) to !== undefined (strict equality) in the pitch comparison
  • Simplified zoom speed calculation by inlining the zoomTargetDistance variable using a ternary instead of a let + nullish coalescing pattern

Reviewed changes

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

File Description
packages/dev/core/src/Cameras/geospatialCamera.ts Introduces _setFlyToTargets() private helper, delegates from updateFlyToDestination() and flyToAsync(); fixes strict equality for targetPitch check
packages/dev/core/src/Cameras/geospatialCameraMovement.ts Simplifies zoom speed multiplier calculation by replacing let + nullish coalescing with a const + ternary

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 28, 2026

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 28, 2026

Snapshot stored with reference name:
refs/pull/17991/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/17991/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/17991/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/17991/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/17991/merge
https://gui.babylonjs.com/?snapshot=refs/pull/17991/merge
https://nme.babylonjs.com/?snapshot=refs/pull/17991/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/17991/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 28, 2026

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 28, 2026

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 28, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants