fu5ha / ultraviolet

A wide linear algebra crate for games and graphics.
https://crates.io/crates/ultraviolet
741 stars 76 forks source link

Geometric multiplication for bivectors #146

Open AnIrishDuck opened 2 years ago

AnIrishDuck commented 2 years ago

Add a GeometricMul trait for geometric multiplication. Implement it for vector.gmul(vector) and bivector.gmul(bivector).

Ideally it'd be implemented across all types, which I may get to. I wanted to double check that this is an agreeable direction first.

Also, fixed an apparent bug in the Div impl for bivectors. I also think there's a bug in the dot method of bivectors, but am less confident on that. I'm working on double checking against literature / other libraries.

The test here uses quickcheck; I've found property-based testing to be nice for "abstract" math libraries. It also demonstrates the utility of defining the geometric product across types. It's theoretically possible to generate a multiplicative inverse for anything in G3. Specifically, in rust, all we need is something that implements GeometricMul and has a reverse.

If this looks good, I'll work on adding a Reverse trait next. I can then easily add property tests to check inversion of other types. This may catch further errors, like the div issue in bivectors.

fu5ha commented 2 years ago

Hey, thanks for working on this. I've looked over it a couple times and thought it over in my head. I am not sure that this is the direction I want to take the library or not. The trait-with-associated-types style is not really where it started, and though I definitely want to have a more "real" geometric multiplication (and other associated geometric algebra methods) in the future, I've sort of been filing these under the "to-add-in-GA-rewrite" category. Unfortunately, since most of my development bandwidth is taken up by work these days, I'm not sure when that will happen either 😓

AnIrishDuck commented 2 years ago

No worries! This wasn't much work; I'm definitely glad to know early in the process.

In the interim, I've started thinking about whether it makes more sense to add onto / create an extension library for nalgebra instead. Bivector operations in particular are super useful for my current hobby domain (orbital transfer calculations).

Hope you can find more time to work on this library, but I know how that goes with work :)