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

#290: Adding missing methods. #373

Merged
1 commit merged into from
May 29, 2020
Merged

Conversation

halzy
Copy link
Member

@halzy halzy commented May 26, 2020

Adding to Basis:

  • invert()
  • inverse()
  • transpose()
  • transposed()
  • flip_x()
  • flip_y()
  • flip_z()

@halzy
Copy link
Member Author

halzy commented May 26, 2020

Looking for a touch of feedback before getting too far into the changes. Is this the right direction? I've yet to add tests to compare with the functions from Godot.

I'm not sure if flip_x/y/z() are expected to be like this, or if they are useful.

@ghost
Copy link

ghost commented May 26, 2020

Thanks for the PR! I thought FLIP_* are constants in the GDScript interface, so maybe they can be implemented as associated constants if you want to add them?

impl Basis {
    ///  The basis that will flip something along the X axis when used in a transformation.
    pub const FLIP_X: Basis = Basis {
        elements: [
            Vector3 { /* .. */ },
            Vector3 { /* .. */ },
            Vector3 { /* .. */ },
        ],
    };

    // - snip -
}

It's annoying that you can't use Vector3 constructors here because const fns aren't stabilized yet.

@ghost
Copy link

ghost commented May 26, 2020

However, identity is also implemented as a function, so functions could work as well. I don't think I'm particularly favoring either of them to the other.

@ghost ghost added c: core Component: core (mod core_types, object, log, init, ...) feature Adds functionality to the library labels May 26, 2020
@halzy halzy force-pushed the halzy/290-basis-transform branch from 3e0f04c to 02a8e9b Compare May 26, 2020 21:13
@halzy
Copy link
Member Author

halzy commented May 26, 2020

Added:

  • determinant()
  • get_euler()
  • get_rotation_quat()
  • is_equal_approx()
  • orthonormalized()
  • scaled()
  • xform()
  • xform_inv()

Not sure on the need for

  • get_orthogonal_index(), seems to be used by the editor.

Still needed:

  • get_scale()
  • rotated()
  • slerp()

@ghost
Copy link

ghost commented May 26, 2020

On the clippy errors: approx wss added to current master as an optional dependency. If you need approximate float comparisons, consider rebasing on master and making approx unconditional.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Thanks for putting in the work! Just read through the code, and found a few classes of problems that probably resulted from my expression being imprecise. My apologizes! I left review comments on a few instances, but not all of them because that will clutter up the view. To clarify:

Generally, when adding extra methods on core types:

  • Unlike in generated bindings, where we have to use the original names, it's not required to match the Godot method / argument names exactly. If there's a better, Rust-y name that can be considered, use that instead.
  • You may feel free to expose useful methods that aren't present on the Godot types.
  • If you can afford to use a regular assertion, do not use a debug assertion.
  • It's better to be explicit about the costs of method calls. Take self if you're going to Copy or Clone it anyway.
  • Add doc-comments to methods, not normal comments.

I understand that this is a lot of changes to do, along with the sanity tests that need to be added. There is no need to hurry, though! Even if the PR misses 0.8.1, it can still get into future versions.

gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
@halzy halzy force-pushed the halzy/290-basis-transform branch from 02a8e9b to f22f43f Compare May 27, 2020 17:25
@halzy
Copy link
Member Author

halzy commented May 27, 2020

Thank you for your feedback! I'll go through it today.

I've added some sanity tests. The one for invert() is commented out, only 5 of the 9 values are calculated correctly. I've had extra eyes on it and we haven't figured out where it is breaking. Could you take a look or suggest someone that could help?

Thanks!

@ghost
Copy link

ghost commented May 28, 2020

I will take a look later!

As an aside, please don't work around the CI by commenting out code and tests. Having broken code in comments accidentally merged can complicate maintenance later. If you want to get other methods merged first, take the code out and put it in a new PR instead.

@ghost
Copy link

ghost commented May 28, 2020

You might have seen other commented code in the repo while working on it, but keep in mind that these are relics from the early days. We don't do that anymore.

@halzy halzy force-pushed the halzy/290-basis-transform branch from 8806209 to accee38 Compare May 28, 2020 22:22
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Sorry for the long comments, but apparently some of the issues were missed the last time, so I've left review comments on each of the cases this time. Please make sure to check the comments folded by GitHub as well.

gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
gdnative-core/src/geom/basis.rs Outdated Show resolved Hide resolved
@halzy halzy force-pushed the halzy/290-basis-transform branch from accee38 to 15465f0 Compare May 29, 2020 14:35
@halzy
Copy link
Member Author

halzy commented May 29, 2020

@toasteater Thank you for the detailed review! Updated and squashed.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks!

@ghost ghost merged commit e3fcd20 into godot-rust:master May 29, 2020
@halzy halzy deleted the halzy/290-basis-transform branch May 29, 2020 17:06
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: core Component: core (mod core_types, object, log, init, ...) feature Adds functionality to the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant