Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upIntegrate the units system proposed in issue #144 into Euclid types. #148
Conversation
9f729fc
to
3178c36
|
r? @metajack |
|
@SimonSapin told me to r? @pcwalton instead. |
| } | ||
|
|
||
| // Convenient aliases for TypedPoint2D with typed units | ||
| impl<T:Copy, Src, Dst> TypedMatrix2D<T, Src, Dst> { |
This comment has been minimized.
This comment has been minimized.
| PartialOrd + | ||
| Sub<T, Output=T> + | ||
| Trig + | ||
| Zero, Src, Dst> TypedMatrix4D<T, Src, Dst> { |
This comment has been minimized.
This comment has been minimized.
pcwalton
Jul 27, 2016
•
Contributor
Please use a where clause here :)
i.e. impl<T> TypedMatrix<T, Src, Dst> where T: Add<T, Output=T> + ... {
And that reminds me, I should write an RFC to enhance Rust to allow typedefing this away. Sheesh :)
|
|
||
| impl<T: Copy+fmt::Debug, Src, Dst> fmt::Debug for TypedMatrix4D<T, Src, Dst> { |
This comment has been minimized.
This comment has been minimized.
|
|
||
| // Convenient aliases for TypedPoint2D with typed units | ||
|
|
||
| impl<T:Clone, U> TypedPoint2D<T, U> { |
This comment has been minimized.
This comment has been minimized.
| } | ||
| } | ||
|
|
||
| impl<T: Copy + Clone + PartialOrd + Add<T, Output=T> + Sub<T, Output=T> + Zero> Rect<T> { | ||
| impl<T: Copy + Clone + PartialOrd + Add<T, Output=T> + Sub<T, Output=T> + Zero, U> TypedRect<T, U> { |
This comment has been minimized.
This comment has been minimized.
| use num::Zero; | ||
| use length::{ Length, Untyped }; |
This comment has been minimized.
This comment has been minimized.
| @@ -7,117 +7,158 @@ | |||
| // option. This file may not be copied, modified, or distributed | |||
| // except according to those terms. | |||
|
|
|||
| use length::Length; | |||
| use length::{ Length, Untyped }; | |||
| use scale_factor::{ ScaleFactor }; | |||
This comment has been minimized.
This comment has been minimized.
pcwalton
Jul 27, 2016
Contributor
nit: no spaces after { and before }, and also no need to brace {ScaleFactor}
|
Thanks for the quick review! I addressed all of the review items and also changed "Untyped" into "UnknownUnit" Sorry I did that so late in the review process. I just realized gecko had renamed its default unit this way a while ago and the name is more understandable I think. |
|
Looks good! Squash the commits together if you'd like and I'll r=me. To anyone interested: If there are any comments about this change, speak now or forever hold your peace :) |
|
Commits squashed! |
|
@bors-servo: r+ |
|
|
Integrate the units system proposed in issue #144 into Euclid types. Here is the implementation of the units system from issue #144. Other than changing how units are expressed, I took the liberty to change the convention ```Typed<Unit, ScalarType>``` into ```Typed<SalarType, Unit>```. This is to be able to use default generic parameters for the units. Default generics in rust are not quite where they should be yet, so the library does not take full advantage of it. When the language issues get resolved, there are some simplifications that can be made to the library (for instance not need both a TypedPoint2D and a Point2D alias). Member access (```foo.x```) provides scalars (like f32) by default, and there are a few ```_typed``` convenience methods to access members as a Length (```foo.x_typed()```). converting rust-layers to this system, I haven't come across places where the members were accessed without unwrapping the Length right away, which tends to confirm that scalar member access should be what is convenient to write by default. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/euclid/148) <!-- Reviewable:end -->
|
|
This comment has been minimized.
This comment has been minimized.
|
Euclid is already at 0.9. This will need to be incremented before merging. |
nical commentedJul 26, 2016
•
edited
Here is the implementation of the units system from issue #144.
Other than changing how units are expressed, I took the liberty to change the convention
Typed<Unit, ScalarType>intoTyped<SalarType, Unit>. This is to be able to use default generic parameters for the units. Default generics in rust are not quite where they should be yet, so the library does not take full advantage of it. When the language issues get resolved, there are some simplifications that can be made to the library (for instance not need both a TypedPoint2D and a Point2D alias).Member access (
foo.x) provides scalars (like f32) by default, and there are a few_typedconvenience methods to access members as a Length (foo.x_typed()). converting rust-layers to this system, I haven't come across places where the members were accessed without unwrapping the Length right away, which tends to confirm that scalar member access should be what is convenient to write by default.This change is