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

Implement some missing convenience traits. #200

Merged
merged 1 commit into from May 31, 2017
Merged

Conversation

@nical
Copy link
Collaborator

nical commented May 29, 2017

Implement From<[T; N]> and Into<[T; N]> for points and vectors, Implement Hash for rects, and add some helper methods to convert transforms from and to arrays.


This change is Reviewable

@nical
Copy link
Collaborator Author

nical commented May 29, 2017

r? @kvark

@@ -633,6 +633,23 @@ where T: Copy + fmt::Debug +
}
}

impl<T: Copy, Src, Dst> Into<[T; 16]> for TypedTransform3D<T, Src, Dst> {

This comment has been minimized.

@kvark

kvark May 29, 2017

Member

weird. Why is 2D transform just 6 floats but 3D is full 16?

This comment has been minimized.

@nical

nical May 29, 2017

Author Collaborator

2D transforms don't need to implement perspective or other weird operations, so you only need the 2x2 matrix which can encode the scale and rotation, plus the two components that have the transform this gives you a 3x3 matrix where all of the missing components are zero.
3D transforms have a richer set of operation that require all of the components of the 4x4 matrix.

This comment has been minimized.

@kvark

kvark May 29, 2017

Member

don't you see it somewhat inconsistent? it's almost asking for AffineTransform3D being different from just Transform3D.

This comment has been minimized.

@nical

nical May 30, 2017

Author Collaborator

In practice, most 2d rendering libraries (cairo, skia, moz2d, etc.) store 2d transforms the way we do, so using arrays of 6 elements is what's most consistent in a useful way.
If we added the implicit components we could serialize but not deserialize since we would not know what to do with the extra values if they are not zero.

@kvark
Copy link
Member

kvark commented May 29, 2017

Another concern is the choice of [f32; 6] and [f32; 16] for the transform conversion. I don't see where those will be useful. Perhaps, doing [[f32; 2;] 3] and [[f32; 4]; 4] would make more sense?

@nical nical force-pushed the nical:from-into branch from a7f7287 to b85a752 May 30, 2017
@nical
Copy link
Collaborator Author

nical commented May 30, 2017

Another concern is the choice of [f32; 6] and [f32; 16] for the transform conversion. I don't see where those will be useful. Perhaps, doing [[f32; 2;] 3] and [[f32; 4]; 4] would make more sense?

That comes down to personal taste, I have a tendency to favor flat arrays because it subjectively feels simpler, but I an see why some may want to structure that into row arrays. I don't see a reason to not do both, so I added [[T; N]; M] conversions to the PR.

@nical nical changed the title Implement From and Into [T; N]. Implement some missing convenience traits. May 30, 2017
@@ -54,6 +55,14 @@ impl<T: Serialize, U> Serialize for TypedRect<T, U> {
}
}

impl<T: Hash, U> Hash for TypedRect<T, U>
{

This comment has been minimized.

@kvark

kvark May 30, 2017

Member

style nit: opening bracket on the new line?

@kvark
Copy link
Member

kvark commented May 30, 2017

That comes down to personal taste, I have a tendency to favor flat arrays because it subjectively feels simpler, but I an see why some may want to structure that into row arrays. I don't see a reason to not do both, so I added [[T; N]; M] conversions to the PR.

To be honest, I was thinking that since it's not obvious, we should rather not provide any conversions.

@nical nical force-pushed the nical:from-into branch from 6d068a9 to 0e9bf89 May 30, 2017
@kvark
Copy link
Member

kvark commented May 30, 2017

@bors-servo
Copy link
Contributor

bors-servo commented May 30, 2017

📌 Commit 0e9bf89 has been approved by kvark

@bors-servo
Copy link
Contributor

bors-servo commented May 30, 2017

Testing commit 0e9bf89 with merge c496ec3...

bors-servo added a commit that referenced this pull request May 30, 2017
Implement some missing convenience traits.

Implement `From<[T; N]>` and `Into<[T; N]>` for points and vectors, Implement Hash for rects, and add some helper methods to convert transforms from and to arrays.

<!-- 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/200)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented May 30, 2017

💔 Test failed - status-travis

@nical
Copy link
Collaborator Author

nical commented May 31, 2017

@bors-servo retry

1 similar comment
@nox
Copy link
Member

nox commented May 31, 2017

@bors-servo retry

@bors-servo
Copy link
Contributor

bors-servo commented May 31, 2017

Testing commit 0e9bf89 with merge 78e8695...

bors-servo added a commit that referenced this pull request May 31, 2017
Implement some missing convenience traits.

Implement `From<[T; N]>` and `Into<[T; N]>` for points and vectors, Implement Hash for rects, and add some helper methods to convert transforms from and to arrays.

<!-- 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/200)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented May 31, 2017

☀️ Test successful - status-travis
Approved by: kvark
Pushing 78e8695 to master...

@bors-servo bors-servo merged commit 0e9bf89 into servo:master May 31, 2017
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@nical nical deleted the nical:from-into branch May 31, 2017
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.