Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fitToSphere support for orthographic camera #159

Merged
merged 3 commits into from
Feb 23, 2021
Merged

Conversation

ervinoro
Copy link
Contributor

Really a very simple change to use zoom instead of dolly in fitToSphere in the case of orthographic camera.

Additionally, it includes a bit of refactoring:

  • use type guards for camera type
  • run eslint autofix
  • run npm update (outdated eslint had a bug with type guards)

( this._camera as THREE.PerspectiveCamera ).isPerspectiveCamera ? ACTION.DOLLY :
( this._camera as THREE.OrthographicCamera ).isOrthographicCamera ? ACTION.ZOOM :
isPerspectiveCamera( this._camera ) ? ACTION.DOLLY :
isOrthographicCamera( this._camera ) ? ACTION.ZOOM :
Copy link
Owner

Choose a reason for hiding this comment

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

Function call could be slightly costy. Could we just use the property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe that using the type guards instead of type casting improves code clarity and helps to avoid errors. I'm not quite sure about the function call overhead. https://jsbench.me/lyklgbaglm/1 this extremely simplistic benchmark reports the property being actually 17% slower than function call on Firefox, and both as being equal on Chrome (for me). There is some conflicting information online, apparently function calls are slower on Internet Explorer.

I have rebased the PR such that the commit "add type guards for camera type" is last. Feel free to exclude it if you want to keep using the property.

Copy link
Owner

@yomotsu yomotsu Feb 23, 2021

Choose a reason for hiding this comment

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

Thanks for understanding, and the test😊

improves code clarity and helps to avoid errors

You are right! However, three.js tends to avoid using functions such as mrdoob/three.js#19997 (comment)
therefore, let me revert a9a53c9 ("add type guards for camera type") at this moment.

@ervinoro ervinoro force-pushed the dev branch 2 times, most recently from 4c1120c to 9815b4d Compare February 22, 2021 08:34
@yomotsu yomotsu merged commit 4fd90fc into yomotsu:dev Feb 23, 2021
@yomotsu
Copy link
Owner

yomotsu commented Feb 23, 2021

Merged.
Thank you for your first contribution!

@Houssk
Copy link

Houssk commented Feb 23, 2021

thanks @ervinoro !

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.

3 participants