-
Notifications
You must be signed in to change notification settings - Fork 103
Make accessing members as lengths more ergonomic. #206
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
Conversation
An alternative is to use the r? @kvark |
☔ The latest upstream changes (presumably #207) made this pull request unmergeable. Please resolve the merge conflicts. |
@nical I feel like accessing the untyped components (currently, |
Accessing the untyped component is the most ergonomic way and I doubt we'll manage to make working with members as nice as plainly accessing the underlying f32. I prefer not to compromise on ergonomics for this specifically because any small annoyance adds up very quickly when you write even simple vector math computations. So, for now I would much rather keep untyped member access easy and simple, and work on making typed member access more ergonomic. If we get to a point where typed member access is (almost) as nice and natural to use, and servo (and other notable euclid users) mostly uses that painlessly, we can look into making raw access opt-in. |
@nical I see your point. We have to draw the line somewhere between types and ergonomics, and you think that fields should be on the latter side. |
I don't know how to give you numbers or even precise pointers but while converting webrender and servo to euclid 0.14 I ran into quite a lot of code that does non-trivial math with the point/vector members (more than I expected). Another example is my own code in the lyon crates that tend to do have a lot of that as well. There are places where mint would be nice in servo, but the places where we do a lot of math is typically where I think we should keep euclid and push towards more strongly typed units (In particular our layout code could use a lot more strong typing). |
@nical I like |
☔ The latest upstream changes (presumably #225) made this pull request unmergeable. Please resolve the merge conflicts. |
I'll close this for now, I'll probably come back a some point and extract the least controversial (and non-breaking) parts of this PR. |
We don't ever use the
_typed
versions of euclid methods which work withLength<T, U>
instead ofT
. I believe that this is for a large part because it is simpler and more ergonomic to work directly with the scalar type (say, floats) and access it through shorter notations (foo.x
vsfoo.x_typed()
).We can certainly improve on the ergonomics of manipulating lengths:
foo.x
) should have very short getters for lengths (foo.x()
instead offoo.x_typed()
)get_
instead of the the suffix_typed
(for example 'rect.get_min_x()instead of
rect.min_x_typed()since
rect.min_x()` already exists for the non-length version)T
as parameter (for examplerect.inflate
) can takeT2: Into<Length<T, U>>
which works with bothT
andLength<T, U>
.::new
) are more troublesome, because if we make them generic like regular methods, the compiler can easily run into cases where it does not know which type to infer if the static method is called in generic code. Non-static methods don't usually have this problem because theself
part of the method carries enough information for the compiler to know what to infer.While this is technically a breaking change (some function names change), it breaks nothing since these methods aren't ever used a far as I can tell, perhaps we could get away without the huge pain that bumping major versions of euclid is...
This change is