Skip to content

New API: add a scaled vector #5702

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

Merged
merged 10 commits into from
Oct 5, 2023
Merged

New API: add a scaled vector #5702

merged 10 commits into from
Oct 5, 2023

Conversation

LeXXik
Copy link
Contributor

@LeXXik LeXXik commented Oct 1, 2023

Fixes #5114

Adds a new API to vectors: add a scaled vector. Adds a scaled vector to the current instance and returns itself as result. Does not modify the vector being added.

const vec = new pc.Vec3();
vec.addScaled(pc.Vec3.UP, 2); // [0, 2, 0]

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

@LeXXik LeXXik changed the title New API : add a scaled vector New API: add a scaled vector Oct 1, 2023
@willeastcott
Copy link
Contributor

I guess my only slight hesitation is the naming of addScalar and addScaled....just wondering if that is the best option....

LeXXik and others added 3 commits October 3, 2023 18:28
Co-authored-by: Will Eastcott <[email protected]>
Co-authored-by: Will Eastcott <[email protected]>
Co-authored-by: Will Eastcott <[email protected]>
@LeXXik
Copy link
Contributor Author

LeXXik commented Oct 3, 2023

I've also considered addScaledVector, similar to threejs, but its too long for my taste, so I went with a shorter version. Suggestions welcome.

@marklundin
Copy link
Member

I've seen addScaledVec and addScaledVector in other api's which is more descriptive and easier to distinguish against addScalar

@LeXXik
Copy link
Contributor Author

LeXXik commented Oct 3, 2023

Added a poll for voting #5707

@willeastcott
Copy link
Contributor

@marklundin It does make it clearer. But at the same time, the VecX APIs are so terse/succinct. Looks down the API page and it's really very concise (and guessable, I'd argue). So I'd probably err on a short option over a longer one in this case. It's just the minor clash with addScalar that make me pause. I'm very, very torn.

@marklundin
Copy link
Member

Yep agree, it's just that slight collision with addScalar that gives hesitation. However there's no real ambiguity what addScalar does, so maybe it's a non issue?

@willeastcott
Copy link
Contributor

Yes, I guess so. @mvaligursky, thoughts?

@mvaligursky
Copy link
Contributor

I'm happy with addScaled I think. even though my mind calls this mad from old shader assembly instruction (multiply and add), even though that instruction handles vector being multiplied by both scalar or another vector.

@willeastcott
Copy link
Contributor

OK, agreed. Once that JSDoc is updated to number, we can merge.

Copy link
Contributor

@mvaligursky mvaligursky left a comment

Choose a reason for hiding this comment

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

Thanks!

@mvaligursky mvaligursky merged commit 8891ba7 into playcanvas:main Oct 5, 2023
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.

Add vector + scaled vector math
4 participants