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
Immutable Vector 2D #161
Immutable Vector 2D #161
Conversation
Looking good so far, thank you for working on the tests right away. KVector does sound non-obvious, but it is Kotlin's convention to prefer immutability and prefix mutable variants with typealias Vec2 = ImmutableVector2
typealias KVector2 = ImmutableVector2
If you consider 2D vector implementation feature complete, I don't see why we wouldn't release a snapshot release with what we've got so far. |
Yes. However when not possible, even the Kotlin team prefix with Using proper explicit name and propose the user to create typealiases is a great solution, I love it! Thanks. |
I have a concern about the I made this choice in order to make it consistent with But I wonder if I shouldn't rename them |
I prefer more explicit names either way, so I don't see a problem with |
Good idea to add a deprecated |
I think I'm done @czyzby. Please let me know if you find any potential issue, if you want me to add more test, or if you have any question about the code I wrote. |
Please tell me what you think about the examples I added in the readme. |
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.
Great so far, thanks again. When you fix the issues with the documentation, we can definitely merge it.
Quick update to say I didn't forget this PR. I just lack of free time at the moment. I'll try to address the remaining issues next weekend. |
@jcornaz It's OK, you've already done a lot, and I'm also pretty busy recently. I could take over the extra tests, but I'm not sure if I'll be able to make it this week. Just let me know if you won't have time to finish it after all. |
* hasSameDirection, hasOppositeDirection, isOnLine, isCollinear, isCollinearOpposite, isPerpendicular Also fix related errors found when using vector zero (which should have undefined direction)
I finally addressed the requested changes. In a nutshell:
While writing the new tests, I actually noticed a problem in LibGDX vector when it comes to orientation of the vector zero and with many orientation comparison ( LibGDX is not consistent accross theses functions when the vector zero is involved. I opted for correctness instead of replicating errors of LibGDX. The orientation of a zero vector is undefined therefore:
Other direction-related functions ( |
I'll review the changes and update KTX to LibGDX 1.9.9 in the week after this one after I'm done with a conference and a hackathon. Thanks again for the contribution! |
Note this PR contains too many commits. I'd recommend to squash before merge. (Either by choosing squash-merge in github, or I may rebase if you prefer) |
But 36 commits would move you to the top of the contribution statistics. ;) I honestly don't mind either way - the extra commits make it easier to see how the code progressed and normally I'm a fan of "commit early, commit often". Squashed commits make it easier to create changelogs based on the history, but then again - we usually do it manually as the changes are added either way. |
It is as you prefer. I like to "commit early, commit often" when working on a feature (which explains my 36 commits^^). But once the feature is merged I no longer care that It took x commits to be written. I only care about the changes made by the feature as whole. And the original commits are never lost with squash-commit anyway. They stay attached to the PR, and may still be anylized independently if needed (but I never came back a specific PR commit personally). But at the end it's up to you, of course. ;-) |
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.
This is a great contribution, thanks. If you still have the time, please apply some minor changes in the docs and the tests - otherwise we can merge it as is and I'll do a slight refactoring after merging.
Thanks for your valuable review @czyzby. I addressed the requested changes. |
I think this is among the biggest contributions to KTX. Thanks for your work and putting up with my nitpicking. :) |
Contributes to #152
I open this pull request, because I consider
ImmutableVector2
to be feature-complete.Before merge I want to:
ImmutableVectorN
(0.001, -0.001)
) in the list of vector to testVector2
Open questions and points to notice :
What name should we choose? I know I proposed it, but I don't likeKVector
, because theK
means nothing, and certainly not "immutable". I think I'd preferImVector
orImmutableVector
ImmutableVectorN
and write in the doc that one can create typealiases for shorter namesShould the 3D vectors be part of this PR?I intentionnaly chose to makeangle()
return values between-180
and180
instead of between0
and360
like LibDGX does. I chose that to be consistent withangle(Vector2)
,angleRad()
andangleRad(Vector2)
.angleDeg
functions and deprecateangle
to make the difference in behavior clearer and less error-proneVector2
. Exceptions to this rule are setter and functions which became Kotlin operators:setLength
andsetLength2
becamewithLength
andwithLegnth2
setToRandomRotation
becamewithRandomRotation
scl
became the operatortimes
:v * 3
orv1 * v2
unaryMinus
is the equivalent ofscl(-1f)
:-v == v * -1
add
became the operatorplus
:v1 + v2
sub
became the operatorminus
:v1 - v2