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

Use proper type for scratch variables #11700

Merged
merged 2 commits into from
Jan 12, 2024
Merged

Conversation

javagl
Copy link
Contributor

@javagl javagl commented Dec 16, 2023

Fixes #11685

It is not really "required", and does not solve "problem" (except for that itchy feeling in the head of people who usually use typed languages): The scratchVariable that was used either as a Cartesian3 or as a Quaternion has now been split into a scratchCartesian3 and scratchQuaternion that are used depending on the animated path (i.e. the cartesian for "translation" and "scale", and the quaternion for the "rotation").

Should this be mentioned in CHANGES.md? It seems like something that is "too internal" to be mentioned...

I considered to add a unit test - basically consisting of

    // Create rotation and translation (leaving the scratch variable to be a Cartesian3)
    const runtimeChannelRotation = new ModelAnimationChannel({.,.});
    const runtimeChannelTranslation = new ModelAnimationChannel({...});
...
    // Animate rotation (using the Cartesian3 scratch variable...)
    runtimeChannelRotation.animate(time);

But none of that is "visible" at the outside: The runtimeNode["rotation"] is still a Quaternion, because the setter in ModelRuntimeNode clones the input value - which is a Cartesian3, but it does have that .w component, so ... it happens to work 😬 If anyone has an idea for how to "test" this, I'd add the tests accordingly...

@@ -240,10 +241,10 @@ function initialize(runtimeChannel) {
switch (path) {
case AnimatedPropertyType.TRANSLATION:
case AnimatedPropertyType.SCALE:
scratchVariable = new Cartesian3();
scratchCartesian3 = new Cartesian3();
Copy link
Contributor

Choose a reason for hiding this comment

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

@javagl Correct me if I'm wrong, but is this switch statement needed anymore? We can just initialize the scratch variables at the module scope, as we do for most cases.

const scratchCartesian3 = new Cartesian3();
const scratchQuaternion = new Quaternion();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I misinterpreted the comment at #11685 (comment)

When it's OK that both are initialized (even if one of them may remain unused), then the switch statement can indeed be removed.

@ggetz
Copy link
Contributor

ggetz commented Jan 12, 2024

Great, thanks @javagl!

@ggetz ggetz merged commit c7edfae into main Jan 12, 2024
13 checks passed
@ggetz ggetz deleted the consistent-scratch-variable-type branch January 12, 2024 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants