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

chore(core): added Matrix4.fromTranslationQuaternion #345

Closed
wants to merge 2 commits into from
Closed

chore(core): added Matrix4.fromTranslationQuaternion #345

wants to merge 2 commits into from

Conversation

jfayot
Copy link

@jfayot jfayot commented Jan 19, 2024

Added Matrix4.fromTranslationQuaternion.
And updated Matrix4.getScale, getTranslation, getRotation and getRotationMatrix3 to return same type as input. This allows the following kind of construct:
new Matrix4().getRotationMatrix3().invert()

ibgreen
ibgreen previously approved these changes Jan 19, 2024
Copy link
Collaborator

@ibgreen ibgreen left a comment

Choose a reason for hiding this comment

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

Much appreciated.

getTranslation(result: NumericArray = [-0, -0, -0]): NumericArray {
getTranslation(): Vector3;
getTranslation<T extends NumericArray>(result: T): T;
getTranslation(result = new Vector3()): Vector3 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we change the return type here in the implementation, as it is not always a Vector3?

Copy link
Author

Choose a reason for hiding this comment

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

Well, I guess we can keep the NumericArray return type in the default case, that still allows to chain calls if a Vector3 is provided as input... I'll update that !

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks. My understanding when using overloaded signatures is that the "implementation" signature doesn't become visible to the user. Only the overloaded signatures without implementation become part of the public API.

If I am correct, the change I am proposing is more a matter of making the code a little clearer to maintain.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

@@ -42,6 +42,11 @@ test('Matrix4#fromQuaternion', (t) => {
t.end();
});

test('Matrix4#fromTranslationQuaternion', (t) => {
tapeEquals(t, new Matrix4().fromTranslationQuaternion([0, 0, 0], [0, 0, 0, 1]), IDENTITY_MATRIX);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Appreciate the test case. Maybe add one test case with non-zero vectors to test the non-trivial case?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, a litlle bit lazy here !!! Just inspired myself from the test case Matrix4#fromQuaternion. I'll do my best to update that !

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks, admit that our existing tests are not always that good. But that seems like a poor reason for keeping a bad habit in new code....

Copy link
Author

Choose a reason for hiding this comment

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

Done ! Tell me what you think

@coveralls
Copy link

coveralls commented Jan 19, 2024

Coverage Status

coverage: 88.918% (+0.03%) from 88.888%
when pulling f170b20 on jfayot:matrix4_from_translation_quaternion
into 186e349 on uber-web:master.

…mproved Matrix4#fromTranslationQuaternion test case
@jfayot
Copy link
Author

jfayot commented Jan 20, 2024

Much appreciated.

Hi again ! Sorry, I just realized that this repo has moved to visgl/math.gl.
Do you want me to submit this PR to the new repo and delete this one ?

@ibgreen
Copy link
Collaborator

ibgreen commented Jan 20, 2024

I just realized that this repo has moved to visgl/math.gl

Sorry I din't notice that this was in the uber-web repo. Yes, that would be good.

(We are having a discussion with Uber to see if we can solve this split but for now we need to work in the vis.gl fork. )

@jfayot jfayot closed this by deleting the head repository Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants