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

Operator overloads for Graphene #1604

Merged
merged 5 commits into from
Jan 27, 2025
Merged

Conversation

jgcodes2020
Copy link
Contributor

@jgcodes2020 jgcodes2020 commented Dec 16, 2024

Currently includes:

  • vector addition, subtraction, scaling, component-wise multiply/divide
  • matrix scaling, matrix multiplication, matrix-vector multiplication
  • quaternion addition, multiplication

Semantics follow GLSL: vector * vector is component-wise multiplication, scalar * vector is scaling.

Only thing I haven't implemented is dividing a vector by a scalar, since Graphene for whatever reason doesn't have that as a function.

@sdroege
Copy link
Member

sdroege commented Dec 17, 2024

Only thing I haven't implemented is dividing a vector by a scalar, since Graphene for whatever reason doesn't have that as a function.

That's just 1.0/scalar * vector or not?

@jgcodes2020
Copy link
Contributor Author

Only thing I haven't implemented is dividing a vector by a scalar, since Graphene for whatever reason doesn't have that as a function.

That's just 1.0/scalar * vector or not?

Sure that works, but it can lose accuracy because of the limited precision of floating-point numbers.

Copy link
Member

@sdroege sdroege 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 in general. @bilelmoussaoui ?

@sdroege
Copy link
Member

sdroege commented Dec 19, 2024

Sure that works, but it can lose accuracy because of the limited precision of floating-point numbers.

Indeed. Maybe better to keep that explicit then that there's no direct division and leave the choice to the caller

@sdroege
Copy link
Member

sdroege commented Dec 19, 2024

The clippy warnings need some fixing

@jgcodes2020
Copy link
Contributor Author

The clippy warnings need some fixing

Do I just explicitly specify the method names (i.e. Self::add(&self, &rhs)?) If I remove the borrow, Rust selects add from std::ops::Add instead of add from graphene::Vec2, since it prefers to take by value.

@sdroege
Copy link
Member

sdroege commented Dec 20, 2024

Do I just explicitly specify the method names (i.e. Self::add(&self, &rhs)?

I think that would make it most clear

@jgcodes2020 jgcodes2020 marked this pull request as ready for review January 14, 2025 02:28
@jgcodes2020 jgcodes2020 force-pushed the operator-overloads branch 2 times, most recently from 6455f98 to 5ab5eff Compare January 14, 2025 02:35
@sdroege
Copy link
Member

sdroege commented Jan 14, 2025

clippy is still unhappy :)

Copy link
Contributor Author

@jgcodes2020 jgcodes2020 left a comment

Choose a reason for hiding this comment

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

clippy is still unhappy :)

That should be fixed now.

@sdroege sdroege merged commit 35e15b7 into gtk-rs:main Jan 27, 2025
47 of 48 checks passed
@sdroege sdroege added the needs-backport PR needs backporting to the current stable branch label Jan 27, 2025
@jgcodes2020 jgcodes2020 deleted the operator-overloads branch January 27, 2025 14:00
@sdroege sdroege added backported PR was backported to the current stable branch and removed needs-backport PR needs backporting to the current stable branch labels Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported PR was backported to the current stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants