-
-
Notifications
You must be signed in to change notification settings - Fork 852
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
Improve the Transform API #775
Conversation
Codecov Report
@@ Coverage Diff @@
## master #775 +/- ##
==========================================
+ Coverage 88.57% 88.61% +0.04%
==========================================
Files 1005 1008 +3
Lines 42859 42959 +100
Branches 3162 3162
==========================================
+ Hits 37961 38067 +106
+ Misses 4203 4191 -12
- Partials 695 701 +6
Continue to review full report at Codecov.
|
Bump 😉 |
@JimBobSquarePants I will review this during the weekend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! Can't spot anything fundamentally wrong here, but I think we need to address a few points before merging this:
- API suggestions (simplification, completeness)
- Something's wrong on .NET 4.6.2 (on my
I7-7700HQ
machine) - Moar and better tests for transform builders
/// <summary> | ||
/// A helper class for constructing <see cref="Matrix4x4"/> instances for use in projective transforms. | ||
/// </summary> | ||
public class ProjectiveTransformBuilder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All my review comments for AffineTransfrormBuilder
are also valid for ProjectiveTransformBuilder
.
this.matrices.Add(matrix); | ||
return this; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to also add the Rotate/Scale/Translate/Skew methods already present in AffineTransformBuilder
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are they possible with Matrix4x4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, Affine is a subset of Projective. Not sure about the details with the Matrix4x4
class, but I guess you need to use the 3D API-s with Z=0
for translation and Z=1
for scale-like stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theoretically yeah I guess. Feel free to have a pop.
@@ -17,7 +17,8 @@ public class AffineTransformTests | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
Assert.Equal(b1.BuildMatrix(), b2.BuildMatrix()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need better coverage for both AffineTransformBuilder
and ProjectiveTransformBuilder
! Common features could be tested with the same test code. I'll see whether I can help here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both have 100% coverage as far as I’m aware.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The specific creation methods (rotate etc.) seem uncovered for me + we can have a bit more semantical testing.
An idea that's easy to implement: a point transformed by a matrix created with the builder using a series of basic transforms should get to the expected position.
this.TransformMatrix = matrix; | ||
this.TargetDimensions = targetDimensions; | ||
this.TargetDimensions = TransformUtils.GetTransformedSize(sourceSize, matrix); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure whether the logic implemented in GetTransformedSize(...)
fits the needs of all users. Maybe we should expose a AffineTransformProcessor(matrix, sampler, targetSize)
constructor instead, and deal with the rest in the extension methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s seems to cover everything I could throw at it, shrinking and growing when need be. There’s actually similar code for handling free transforms in the net framework.
@JimBobSquarePants one other API suggestion (which is pretty much related to my previous suggestions): Asking the user to feed the source image size to Transform Builders seems unnecessary to me. The size is available on |
@JimBobSquarePants OK, how about this: I push some more tests + extend the projective API right now, you deal with the rest? How about the method namings? Should I change them? Still feel the word |
Thanks for the review. Yeah sounds good. Let’s go ahead with naming changes, it is awfully wordy just now. |
@JimBobSquarePants I also implemented my size-decoupling idea within the Affine API-s, but this is all for today. Projective API-s still need to be adapted. And we still may want to find a workaround for the .NET 4.6.2 issue, however it's debug-only. (I think it is Vector2 tricking us again.) |
…dians back to PrependRotationRadians
@antonfirsov When you have time could you check this again? When I updated Core etc I think I got an implicit upgrade to System.Numerics.Vectors 4.5.0 so I want to see if there's any changes. Otherwise we may have to do something like the following which is super crappy. ImageSharp/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs Line 145 in 12a5fdf
|
@antonfirsov Aside from the alpha issue in debug I think we're done here. |
@JimBobSquarePants checking it now. Is the issue reproducible on your PC? (.NET 4.6.2/4.7.2 test execution + Debug) |
@JimBobSquarePants for me it still fails. We either should do the |
@JimBobSquarePants what is still missing:
|
@antonfirsov I get 283 failed tests running in debug on net472. Even things as simple as Just tried to create a reduced sample for the |
You're a hard taskmaster you know that right? 😝 |
Opend #780 to "deal" with the Debug mode issues, we probalby shouldn't bother working around this in product code any longer. I don't want to be too hard at this PR, up to you to decide. I'm just trying to save our future selves from writing these tests when we touch the code again 😄 |
@antonfirsov I've added all the Skew overloads to both builders and relevant additional tests for them also. Any additional tests we can add when cleaning up. |
Improve the Transform API
Prerequisites
Description
This PR dramatically simplifies all affine and projective transforms and fixes some issues we had with affine transforms.
Two new classes have been introduced into the public domain which allow the composition of matrices:
AffineTransformBuilder
ProjectiveTransformBuilder
All
Transform<TPixel>
methods now utilize these two classes which allows us to automatically resize canvases to cater for the transformed vectors.For example an affine transform can be composed in the following manner:
Both classes also have a
Rectangle
constructor overload that allows the transforming of areas of interest in the source image.Additionally several layers of abstraction have now been removed. And performance of transforms improved by around 10%.