-
Notifications
You must be signed in to change notification settings - Fork 155
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
Mint flavour integration #418
Conversation
Why the 👎 @tomaka? Would like to know your reasoning on this! |
#[cfg(feature = "mint")] | ||
mint_conversions!(Matrix3 { x, y, z }, ColumnMatrix3); | ||
#[cfg(feature = "mint")] | ||
mint_conversions!(Matrix4 { x, y, z, w }, ColumnMatrix4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is nice that mint has a ColumnMatrix
type! I think that is potentially a good distinction to make... so many folks get tripped up by it. :(
@brendanzab if you don't mind some reading, here is the IRC discussion: https://botbot.me/mozilla/rust-gamedev/2017-06-14/?msg=87250505&page=4 |
Cheers, that is very helpful 🤔 ... will have to consider this. What does @sebcrozet think? |
@brendanzab I think something like mint, that simplifies the task of converting between types of different linear algebra crates, is useful, especially when one user wants to use one crate depending on, e.g., nalgebra, and another built with, e.g., cgmath. On the other hand, I am against the use of mint on APIs, i.e., it should not be a public dependency: this would force the user to add boilerplate for conversions. For example, let say I rewrite the nphysics public API to expose only mint types instead of nalgebra types (though nalgebra is still used internally). Let say there is a method that returns a vector of rigid bodies positions (using homogeneous coordinates) So I think mint is useful for converting types locally, when needed, but not to be used on API directly. |
@sebcrozet thanks for chiming in and expressing your opinion/concerns!
This is quite opposite to the original goal of
I'd argue that when you want to do anything with an array of matrices, the conversion cost, if any, can be neglected.
Given |
In addition to what @kvark said, I'd say that you don't have to convert always. Because as soon as you use another library, you can just pass the mint stuff, so it's less boilerplate because you don't have to convert between math libraries (or seen in another way, libraries dealing with math aren't specific to one math library, but rather have it as an internal dependency). I don't think the conversion is more than a copy most of the time, probably except for quaternions which can be represented as (w, x, y, z) or (x, y, z, w). |
@brendanzab what's your opinion about this PR? I would like to see it merged, but I don't see any discussion lately. |
IMO a few
Yes that's less boilerplate in this specific case. But as long as we are not just passing data between libraries, this becomes much more boilerplaty. Also, this adds a lot of boilerplate for the libraries authors because he would have to systematically convert mint types to its own.
What about more complex structure that contain a quaternion (e.g. Vec)? The library writer would have to copy/clone the whole structure every time the user calls its api? I'm aware that the initial goal of |
IMO there is some misunderstanding between us.
Again,
Well, what is your suggestion? You're game engine developer, (like |
An alternative is to make Amethyst just stick with one math lib and let the user convert types from other math libs (using something like mint for example). But that's just a matter of taste; I understand that having mint types on the API would avoid those conversions. But a mint API is at the cost of requiring the user to convert mint type back to cgmath/nalgebra/etc. whenever he wants to do any computation with them outside of Amethyst. By the way, none of my arguments are against the merge of this PR. I'm just discussing about the use of mint types on public APIs. |
@sebcrozet I see your point.
Yes, that is the downside of this approach. But I'm sure compiler can (and would) optimize all those conversations well, most of them aren't more than simple conversion |
FWIW, I made a nalgebra PR here - dimforge/nalgebra#270 |
Since the discussion is going on in here, I am just going to voice my doubts here to keep in one place. I am not sure, what use case You are trying to provide a common language for APIs dealing with linear algebra in terms of data structures. Why do we need a new crate for this instead of just using plain old Rust arrays? If all things would be equal between those two approaches, I would much rather opt for not having to interface with a new crate, because it is simpler and therefore easier to maintain. Both Am I missing something here? edit: reading up on the IRC discussion, I mostly agree with @tomaka on the issue of adding dependencies. writing a bit of boilerplate here and there is usually an acceptable price for flatter dependency trees. mostly that is, because it is trivial to maintain, if it is under your control, but much more of a hassle, if it is an external dependency. |
@aepsil0n thanks for chiming in! Mint has been rigorously discussed on IRC and elsewhere, but I don't mind re-iterating some of the arguments here.
The most important thing about interop between libraries/users is preservation of semantics:
You don't have any guarantee that these libraries would agree on how exactly they represent their types in fixed-size arrays.
Increased maintenance burden is a valid concern, even though there is not much code. I do see more value in semantically strong Having a separate crate dependency in Rust is really easy, as long as it doesn't have much logic in it, thus compiling fast. Users don't even need to use |
@kvark thanks for the explanation, I have not been following IRC much, but only read up on the discussion between @tomaka and you. Thus the summary is much appreciated. :) Boiling it down to one sentence, I am still not entirely convinced that the benefits are worth the cost of having an extra dependency. Apparently we have a different intuitive estimate of that cost and I guess it is hard to argue about it, since it involves speculation about uncertain data and future developments. I guess, my worry that this might be a very theoretical issue and 99% of applications are going use exactly one library at the end. Nonetheless, if there is demand for this, I would not object to adding it as an optional feature like in your PR. This way the stability of the library without the feature would not be affected. One other thought: do the orphan rules prevent Compared to something like |
@aepsil0n I'm glad to hear that mint started to make some sense to you :)
Good thing is - mint is not tightly integrated. Removing support for it, if needed eventually, or declaring
I don't think this is going to work. We don't want |
True. I did not think that through. If that's really all we need for a long time, I guess it will turn into 1.0 comparatively soon then? |
I think we need to solve a few issues beforehand. |
@aepsil0n
I think that it might be very helpful. For now, the only thing discussed was interoperability between math libraries, but that's not interesting for me at all. I want to write a game, so I will probably just roll with whatever math lib my game engine (Amethyst) uses. However, I might decide to switch out certain parts of Amethyst, or add things which it does not provide. Something like the physics engine, VR motion tracking, etc. those things might use other math libraries or expose entirely custom structures, hence I'd be forced to do the conversion. If all libraries, however, expose a Mint interface (which is easy to implement and add/remove via a feature-switch), then I can plug them together in whatever way I like without thinking much about differences and boilerplate. Imho, it would be a big win for projects which need to put together multiple solutions to form an end-user product. |
@minecrawler here is an example of the interaction of lib - user is going to look like (from three-rs): impl OrbitControls {
pub fn new<P>(object: &Object, position: P, target: P) -> OrbitControlsBuilder
where P: Into<mint::Point3<f32>> {..}
} So the user would then do: let orbital = OrbitalControl::new(&camera,
cgmath::Point3::new(0.0, 0.0, 1.0),
target_position); // supposedly, also `cgmath::Point3` As you can see, user doesn't need to know about |
This is implemented as a feature, so I'm thinking I will unblock the ecosystem for now and merge. I also want to experiment with switching to |
Includes #417
r? @brendanzab
Notice how matrix and Euler conversions have stronger types (to
ColumnMatrix*<>
andEulerAngles<, IntraXYZ>
respectively).