-
Notifications
You must be signed in to change notification settings - Fork 212
[discussion] Moving away from euclid in favor of local types #594
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
Comments
Has anyone started working on this yet? If not, I'm willing to give it a go. |
Thanks for offering help! Before delving straight into an implementation, we should probably discuss the
part 🙂 |
True. I think Other popular libraries include |
Just quickly made a test: Huge difference, and I'm definitely a fan of lightweight libraries 🙂 it also seems to be specifically for game development, not a general-purpose linear algebra package. What would the general approach be?
|
Indeed, I wasn't considering compile time in my previous comment. If we take that into consideration then
Good idea! Direct field access is definitely something good to have. We can have private methods for value and reference conversion to
Indeed. That's what we're trying not to do here. |
Sounds good! Since vector types are used across the entire library, such a refactoring is quite an endeavour. Maybe it would make sense to split the efforts into steps, with intermediate working versions? I could imagine something like this:
Also, the above parts could be done first for Then @Demindiro would also be more free to choose if he still wants to work on it, and if yes on what parts. |
Thinking about this a bit more, if we provide our own types, we still need to deal with a lot of code duplication just for delegating (just from the operators alone). It would be almost as much as providing our own implementation, since most vector operations are one-liners. But if it helps for clarity and consistency with Godot, it's probably worth it. Regarding back-end math library, there are a few contenders:
There's also Also, arewegameyet provides an overview of crates, and mathbench-rs some benchmarks. I think the API and "bloatedness" is more decisive for our use case, but having good performance is definitely a nice to have. |
Since Demindiro has made a PR based on glam I think it's fine to go with it for now. We can switch to another implementation any time later.
While I still prefer nominal type systems for most use cases, this is one of the niches where a structural typing system would really shine. Without a "standard" implementation widely agreed upon, we're bound to repeat the old problem if we want to provide at least some ease of use. If we ignore that though, there's the |
713: Replace euclid with glam (proof-of-concept) r=toasteater a=Demindiro I had some time to take a look at #594. I decided to go with `glam` since it compiles the fastest. I went with the "front-end" approach as I believe that is the most flexible approach. I did rename a few things (like `zero()` to `ZERO`, `quaternion()` to `new()`, ...) but that is easy to revert if required. It doesn't seem like many changes are required. Wrapping all the methods in `glam` is easy to do with extensive use of `glam()` and `into()`. The crate does seem to miss implementations for a few types and methods like `Rect2` and `rotated`, so we'll have to implement those from scratch. the `impl Mul/Div/Add/...`s for `Vector2` and `Vector3` are pretty much identical, maybe there is some way to reduce duplication? Closes #594 Closes #670 (`Vector3` is fully implemented) Co-authored-by: David Hoppenbrouwers <[email protected]> Co-authored-by: toasteater <[email protected]>
On multiple occasions, there were users complaining on GitHub and Discord about how
euclid
's typed interface, with its distinction betweenPoint
s,Vector
s,Size
s andScale
s, gets in the way when the Godot API itself is untyped. While there is the simple solution of conversion (amongeuclid
types, or throughmint
to types from another library), new users often aren't aware of them, and the method calls can get quite verbose at times. There is also the issue with porting, where someone will attempt to port some GDScript code to Rust, and want to access the Godot versions of vector methods. We're currently handling those with extension traits, but local types can do that a little bit better.The use of
euclid
types in the public interface also caused version conflict problems in user code, leading to recurring PRs to bump them: #216, #523, #588Therefore, I think it might be valuable to eventually replace
euclid
types with local newtypes in our public interface instead. This is not a suggestion that we should reinvent the wheel: we can just pick any vector math library we want to use as the underlying implementation, as long as its types have the correct layout. For conversion to types from other libraries, we can add (optional?)mint
support.This is obviously too late for inclusion in 0.9, but we can consider it for 0.10.
The text was updated successfully, but these errors were encountered: