Skip to content

Conversation

@nical
Copy link
Contributor

@nical 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
Contributor Author

nical commented May 29, 2017

r? @kvark

}
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

@nical nical May 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor 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
}

impl<T: Hash, U> Hash for TypedRect<T, U>
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kvark
Copy link
Member

kvark commented May 30, 2017

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit 0e9bf89 has been approved by kvark

@bors-servo
Copy link
Contributor

⌛ Testing commit 0e9bf89 with merge c496ec3...

bors-servo pushed 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

💔 Test failed - status-travis

@nical
Copy link
Contributor Author

nical commented May 31, 2017

@bors-servo retry

1 similar comment
@nox
Copy link
Contributor

nox commented May 31, 2017

@bors-servo retry

@bors-servo
Copy link
Contributor

⌛ Testing commit 0e9bf89 with merge 78e8695...

bors-servo pushed 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

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

@bors-servo bors-servo merged commit 0e9bf89 into servo:master May 31, 2017
@nical nical deleted the from-into branch May 31, 2017 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants