-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add static versions of existing mutable vector functions #5044
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
Conversation
🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page! |
An ongoing branch for development of the static functions and supporting materials. The existing test suites for |
For unit tests you can start by looking at here and if there's anything missing or unclear (whether to use |
Codecov Report
@@ Coverage Diff @@
## main #5044 +/- ##
==========================================
+ Coverage 68.09% 68.57% +0.47%
==========================================
Files 79 79
Lines 12286 12327 +41
Branches 2720 2733 +13
==========================================
+ Hits 8366 8453 +87
+ Misses 3920 3874 -46
Continue to review full report at Codecov.
|
This is a bit of a looong one, but I've done my best to keep each individual commit mostly clean and self-contained, so it may be easier to review this commit-by-commit. This should implement class/static methods for all outstanding Vector functions, except for |
Thank you @weslord. I am inviting more Math stewards to review this PR @limzykenneth, @jeffawang, @AdilRabbani @davepagurek. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just going through and reading everything! Overall this looks good, just a few comments!
src/math/p5.Vector.js
Outdated
* Calculate the angle of rotation for this vector (only 2D vectors). | ||
* p5.Vectors created using <a href="#/p5/createVector">createVector()</a> | ||
* will take the current <a href="#/p5/angleMode">angleMode</a> into | ||
* consideration, and give the angle in radians or degree accordingly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nitpick, for here and line 2466: this should probably be "degrees" instead of "degree"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see this is actually a typo in the existing docs for the instance methods too 😅 Maybe worth fixing there too, although it's not urgent for this PR
expect(v3.angleBetween(v4)).to.be.closeTo(180, 0.00001); | ||
}); | ||
test('should not trip on rounding issues in 2D space', function() { | ||
v1 = new p5.Vector(-11, -20); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there a reason to switch to new p5.Vector()
here over myp5.createVector()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a bit of an old PR I would suggest for us to just test changing these back to using myp5.createVector()
and see if it is working. If that works fine, we can revert this locally then merge this PR so as not to hold things up for much longer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Half the file already used new p5.Vector()
, and half used myp5.createVector()
(one of the many inconsistencies that inspired this query: #5044 (comment)).
My preference is new p5.Vector()
because it seems more pure and less stateful. If myp5
has some influence, we probably don't want that. If it doesn't, why use it? Right?
But ultimately it's not a strong preference. I've checked "allow edits by maintainers". Make whatever changes you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion either way either, I just wanted to make sure there wasn't anything that wasn't working when using createVector
. I think since the docs mostly describe using createVector
, it's maybe best that we make sure we test that primarily, although it's also good to know that new p5.Vector
works too!
Thanks for making the other updates, I'll pull your branch and double check that createVector
works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirmed that createVector
works locally! I'll merge your PR as-is though, you're right that the tests are currently very inconsistent with what form it uses, but it does seem to use new p5.Vector
slightly more in the tests, so this adds a bit more consistency (and we can always discuss standardizing on something else in another issue.)
v1 = new p5.Vector(1, 2, 3); | ||
}); | ||
|
||
suite('p5.Vector.prototype.magSq() [INSTANCE]', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making tests for these methods too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for making these changes!
@all-contributors please add @weslord for doc, test |
I've put up a pull request to add @weslord! 🎉 |
Resolves #4852
Changes:
Updated functions, docs and unit tests for:
PR Checklist
npm run lint
passes