Closed leftiness closed 8 years ago
Arrays. Arrays are obviously the answer. An array is an immutable collection of values with a length defined in the type declaration. All elements of an array are the same type. You can array.iter().map()
. point.array().iter().map()
. impl From<[i32;3]> for Point
.
asdf. Asdf! You can't collect back into an array because array doesn't implement Iterator. I just spent a bunch of time writing some array functions for HasValues, and it doesn't work. You collect back into a vector. I'd still be stuck writing functions to check vector sizes and manually convert from vec to point.
Big sigh. Maybe I can avoid the worst of the problem with #52.
Yeah. It's not as bad now: https://github.com/leftiness/hex_math/commit/0f811d43642690d93ac129857f332c7964d8de16?diff=split
Closing. Issue is circumvented.
I wrote a HasValues#into_vec(). I'm not so sure that's the proper solution here.
For example, the work I'm doing for ray() has a step where I need to do A + B * C where A: i32, B: f32, C: f32 for each element of three structs (A, A, A, A), (B, B, B, B), (C, C, C, C). So A0 + B0 * C0, A1 + B1 * C1, etc.
I can't use HasValues#into_vec() here even if I wanted to. This isn't a HasValues. It's a tuple of f32.
Here's some primitive work:
I don't like that either. I'd have to write a lot of functions, and I'd have to duplicate the work for tuples of three, tuples of four... Just no.
So maybe a HasValues should be different. It could be a struct which is backed by a private vector. I don't want someone adding or removing or even altering values in this vector. If I give someone access to it, I would just provide an iterator and let them do map(), collect(), etc.
This HasValues would need to be
HasValues<T>
. It would implFrom<(T, T, T, T)>
.Maybe it wouldn't even be the HasValues trait but maybe more of a struct. It could still implement HasValues. So... maybe this work would be done on the Point struct. With the ability to provide a function for mapping, I could iterate over a
Point<f32>
, convert from f32 to i32, and collect back into aPoint<i32>
.Idk though. I kind of appreciate the idea of having a Point.q property, but at the same time I've been using point.values() and stuff like that. I'm not even using that Point.q property.