Skip to content

Conversation

@nical
Copy link
Contributor

@nical nical commented Jul 29, 2016

This is a big PR, beware that it has a lot of breaking changes in the matrix types.
It implements what I propose in issue #145 and issue #146, namely:

  • Remove mul for matrices in favor of explicit pre_mul and post_mul (similar to what we have in gecko).
  • Add Row-major and column-major serializers and constructors to matrices to help interfacing with dom matrices and external libs such as skia (the actual layout of the matrix types stays row-major but that's an implementation detail that only matters to the people looking at the memory in a debugger).
  • Add a whole bunch of methods that are used a lot in gecko.
  • Add a lot of documentation.

This is still a work in progress but it's almost ready, so interested parties can start looking at it give feedback.


This change is Reviewable

@nical
Copy link
Contributor Author

nical commented Aug 2, 2016

The PR is in a good state now (modulo making the git history pretty once eventual review comments have been addressed). Here is a summary of what's in there:

  • make pre and post multiplication explicit (removing mul in favor of pre_mul/post_mul
  • implement the common pre/post operations (translation, scale, rotation), using translated instead of translate in the terminology to avoid immutable methods looking like they are in-place transformations (and let the names available for in-place operations if we ever find out that it helps with code-gen in the future). see post_translated, pre_rotated, etc.
  • add explicit row-major/column-major constructors and serializers (row_major replaces new, column_major is added, to_array becomes to_row_major_array and to_column_major_array complements it. With this, the internal layout is completely irrelevant unless you are looking at your stack in a debugger.

The above changes make it hard to fall into any trap by habit of using a convention or another.
Additionally, I added methods that are used all over the place in gecko:

  • float to integer conversion for points/sizes/etc. without these people tend to just use casts but truncating decimals towards zero doesn't always make sense from a geometrical point of view. See floor, ceil and round.
  • Similar methds for rects, see round_in and round_out. They are used so much in gecko that I am surprised servo doesn't have equivalents already, or perhaps it is outside of euclid.
  • Lots and lots of documentation all over euclid.

And last but not least, I made a lot of code that was relying on Clone, rely on Copy instead. This simplifies things a great deal and I don't think anyone will ever use euclid with scalar types that are not Copy, although that's debatable. A lot of code was already only implemented for Copy types, especially in matrices, so I just generalized it to the rest of the library.

@nical
Copy link
Contributor Author

nical commented Aug 2, 2016

I realize that's a lot for one PR, sorry. We can discuss, the different aspects of it here and I'll remove things if need be.

src/matrix2d.rs Outdated
impl<T: Copy, Src, Dst> TypedMatrix2D<T, Src, Dst> {
pub fn to_array(&self) -> [T; 6] {
/// Create a matrix specifying its components in column-major order.
pub fn colum_major(m11: T, m21: T, m31: T, m12: T, m22: T, m32: T) -> TypedMatrix2D<T, Src, Dst> {
Copy link

Choose a reason for hiding this comment

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

column

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #150) made this pull request unmergeable. Please resolve the merge conflicts.

@peterjoel
Copy link

I'm curious why the change to make various types implement Copy. Is that being tracked or discussed in an issue?

@peterjoel
Copy link

Never mind: somehow I thought you had made the matrix types implement Copy. I see now that it's just a constraint on the scalar type parameter. It's hard to imagine how that would be a problem.


Comments from Reviewable

@peterjoel
Copy link

Is there any reason not to also change the Clone constraint to Copy for Length?

#[inline]
pub fn from_lengths(x: Length<T, U>, y: Length<T, U>) -> TypedPoint2D<T, U> {
TypedPoint2D::new(x.get(), y.get())
TypedPoint2D::new(x.0, y.0)

Choose a reason for hiding this comment

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

x.get() actually feels cleaner to me.

@nical
Copy link
Contributor Author

nical commented Aug 8, 2016

Since a lot of methods were already implemented on top of Copy scalar types, having the other half of the library implemented on top of (the less constrained) Clone trait was not particularly useful. Basing everything on top of Copy simplified the code quite a bit.

No particular reason for Length's Clone constraint being left to Clone instead of Copy. For vector/matrix types the incentive was to make the methods easier to write and more readable while Length doesn't do anything fancy with its value. I can change it to use Copy as well If you prefer.

@peterjoel
Copy link

It might be a bit neater though to have the same constraints everywhere. But it probably doesn't matter too much either way.

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #153) made this pull request unmergeable. Please resolve the merge conflicts.

@peterjoel
Copy link

I tried applying this to servo. The only thing missing is that TypedMatrix2D needs Copy and Clone impls for T: Copy.

@peterjoel
Copy link

peterjoel commented Aug 13, 2016

When this is merged, I have made the relevant changes to Servo, which I'll make follow-on PRs for:

src/matrix4d.rs Outdated
/// https://drafts.csswg.org/css-transforms/#funcdef-skew
///
/// See https://drafts.csswg.org/css-transforms/#funcdef-skew
pub fn create_skew(alpha: T, beta: T) -> TypedMatrix4D<T, Src, Dst> {

Choose a reason for hiding this comment

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

Shouldn't alpha and beta be Radians<T> here?

@nical
Copy link
Contributor Author

nical commented Aug 16, 2016

Hi, I'm just back from holiday, I'll catch up with this asap, probably tomorrow, address comments, and rebase the PR.
@peterjoel thanks a lot for the followup PRs! I can take care of the rest if you want (I don't mean to have you spend your time cleaning after my breaking changes).

@peterjoel
Copy link

@nical No worries. I need to keep my unmerged DOMMatrix branch up to date, so I'm applying those changes anyway.

@nical
Copy link
Contributor Author

nical commented Aug 17, 2016

I just rebased the branch, squashed it into a single commit fixed the skew parameters to use radians explicitly. I also rolled back the part where Point::zero() was renamed into Point::origin() which had landed in this branch accidentally.

@nical
Copy link
Contributor Author

nical commented Aug 17, 2016

r? @pcwalton

@pcwalton
Copy link
Contributor

@bors-servo: r+

Very nice to see more work being done on euclid :)

@bors-servo
Copy link
Contributor

📌 Commit fe20f19 has been approved by pcwalton

@bors-servo
Copy link
Contributor

⚡ Test exempted - status

@bors-servo bors-servo merged commit fe20f19 into servo:master Aug 18, 2016
bors-servo pushed a commit that referenced this pull request Aug 18, 2016
Expose pre/post operations and transpositions explicitly, and add documentation.

This is a big PR, beware that it has a lot of breaking changes in the matrix types.
It implements what I propose in issue #145 and issue #146, namely:

* Remove mul for matrices in favor of explicit pre_mul and post_mul (similar to what we have in gecko).
* Add Row-major and column-major serializers and constructors to matrices to help interfacing with dom matrices and external libs such as skia (the actual layout of the matrix types stays row-major but that's an implementation detail that only matters to the people looking at the memory in a debugger).
* Add a whole bunch of methods that are used a lot in gecko.
* Add a lot of documentation.

This is still a work in progress but it's almost ready, so interested parties can start looking at it give feedback.

<!-- 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/149)
<!-- Reviewable:end -->
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.

5 participants