Skip to content
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

Integrate the units system proposed in issue #144 into Euclid types. #148

Merged
merged 1 commit into from Jul 29, 2016

Conversation

@nical
Copy link
Collaborator

nical commented Jul 26, 2016

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.


This change is Reviewable

@nical nical force-pushed the nical:units branch 2 times, most recently from 9f729fc to 3178c36 Jul 26, 2016
@nical
Copy link
Collaborator Author

nical commented Jul 26, 2016

@nical nical force-pushed the nical:units branch from 3178c36 to 066e83b Jul 27, 2016
@nical
Copy link
Collaborator Author

nical commented Jul 27, 2016

@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.

@pcwalton

pcwalton Jul 27, 2016

Contributor

nit: put a space after :

PartialOrd +
Sub<T, Output=T> +
Trig +
Zero, Src, Dst> TypedMatrix4D<T, Src, Dst> {

This comment has been minimized.

@pcwalton

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.

@pcwalton

pcwalton Jul 27, 2016

Contributor

uber-nit: Put spaces around +


// Convenient aliases for TypedPoint2D with typed units

impl<T:Clone, U> TypedPoint2D<T, U> {

This comment has been minimized.

@pcwalton

pcwalton Jul 27, 2016

Contributor

nit: space after :

}
}

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.

@pcwalton

pcwalton Jul 27, 2016

Contributor

While you're here, could you change this to use a where clause?

use num::Zero;
use length::{ Length, Untyped };

This comment has been minimized.

@pcwalton

pcwalton Jul 27, 2016

Contributor

nit: no spaces after { and before }

src/size.rs Outdated
@@ -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.

@pcwalton

pcwalton Jul 27, 2016

Contributor

nit: no spaces after { and before }, and also no need to brace {ScaleFactor}

@nical
Copy link
Collaborator Author

nical commented Jul 28, 2016

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.

@pcwalton
Copy link
Contributor

pcwalton commented Jul 28, 2016

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 :)

@nical nical force-pushed the nical:units branch from c719433 to 6205104 Jul 28, 2016
@nical
Copy link
Collaborator Author

nical commented Jul 29, 2016

Commits squashed!

@pcwalton
Copy link
Contributor

pcwalton commented Jul 29, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Jul 29, 2016

📌 Commit 6205104 has been approved by pcwalton

@bors-servo
Copy link
Contributor

bors-servo commented Jul 29, 2016

Testing commit 6205104 with merge 547b5c3...

bors-servo added a commit that referenced this pull request Jul 29, 2016
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 -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 29, 2016

☀️ Test successful - travis

@bors-servo bors-servo merged commit 6205104 into servo:master Jul 29, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@bors-servo bors-servo mentioned this pull request Jul 29, 2016
@peterjoel

This comment has been minimized.

Copy link
Contributor

peterjoel commented on Cargo.toml in 6205104 Aug 13, 2016

Euclid is already at 0.9. This will need to be incremented before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.