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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jgcodes2020
Copy link

@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
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 ?

graphene/src/matrix.rs Outdated Show resolved Hide resolved
@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
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants