-
Notifications
You must be signed in to change notification settings - Fork 20
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
Default impl? #58
Comments
See #38 (comment) TL;DR: implementing this is possible for some but not the others. So we can't universally provide |
I'm not sure I understand. I think the default at least for Vector and
Matrix is obvious: fill the container with T::default(). If T doesn't
implement default, then Vector and Matrix shouldn't, but as I understand it
this will be the automatic behavior of derive(Default) anyway:
https://stackoverflow.com/a/48045960/50385
…On Tue, Jul 28, 2020, 9:45 AM Dzmitry Malyshau ***@***.***> wrote:
See #38 (comment)
<#38 (comment)>
TL;DR: implementing this is possible for some but not the others. So we
can't universally provide Default, and therefore we should consider not
providing it at all.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#58 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAY7MSEAQFOEWG6UWBJ7YLR53P7XANCNFSM4PKDHSWA>
.
|
I disagree that |
That would be inconsistent with i32::default() and the like. Pretty sure in
every math context in the standard library default is a null element, never
an identity element.
…On Tue, Jul 28, 2020, 8:02 PM Dzmitry Malyshau ***@***.***> wrote:
I disagree that impl Default for Matrix is obvious to be all-zeroes
(filled with T::default()). If I see that a matrix type in a math library
implements default, I'll first think about an identity matrix.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#58 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAY7MVZGSCSYCMNPNTBVWTR55YJRANCNFSM4PKDHSWA>
.
|
(thank you for bearing with me on this question!) The standard library doesn't have math vectors and matrices, so it hardly sets up an example here. If we look at default implementations in the math libraries, they appear to be all over the place:
And that's the reason why I'm hesitating to add anything to |
Having dog-fooded Now, it would be good to have a consistent policy for implementing defaults. I'd argue that initializing quaternions and matrices with "identity" poses the minimal surprise factor for all the users. If the user code expects an identity, they get it. If they don't expect anything useful (e.g. all zeroes), the identity isn't going to screw them over. To re-iterate on this line of thought:
|
For comparison, nalgebra's default is zeroes for matrices, vectors, and general quaternions, and the identity rotation for There doesn't seem to be a drawback to going with identity for square matrixes, but what should non-square matrices have? |
I still think zeroes is the most natural choice in a programming context:
|
I'm not keen on the argument that matrices should be naturally analogous to scalars or Is there a concern with going for identity-ish non-square matrices? E.g.
and
Basically, treat them as parts of a bigger square matrix for cases where the remainder is well known and doesn't need to be stored. |
Adding and subtracting matrices is also a typical matrix operation, and there 0 is a sane default. Also it avoids needing a separate solution for non-square. |
I suppose the non-square matrixes you generally see in games/graphics are truncations of homogeneous matrices or their transpose, for which that makes perfect sense. Certainly holds for most of what I've done.
Not in linear algebra for computer graphics, I don't think. |
It would be convenient if
mint::Vector2::default()
worked (giving zeros) so my own structs could#[derive(Default)]
.The text was updated successfully, but these errors were encountered: