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

fix(v6): 4th PR of Group Rewrite πŸŽ›οΈ nested controls 😜 #7861

Merged
merged 44 commits into from
May 2, 2022

Conversation

ShaMan123
Copy link
Contributor

@ShaMan123 ShaMan123 commented Apr 4, 2022

This PR fixes control rendering.
There are a few unresolved comments in the original PR, please take a look.

Main Changes

commit

This PR ports #7758 to master

Visuals

controls12.png
controls13.png

@ShaMan123
Copy link
Contributor Author

ShaMan123 commented Apr 9, 2022

@melchiar the changes you are suggesting belong to #7859

src/shapes/group.class.js Outdated Show resolved Hide resolved
src/shapes/group.class.js Outdated Show resolved Hide resolved
src/shapes/group.class.js Outdated Show resolved Hide resolved
@melchiar
Copy link
Member

melchiar commented Apr 9, 2022

@melchiar the changes you are suggesting belong to #7859

ugh...just saw this now

@ShaMan123
Copy link
Contributor Author

Continue there, I'll patch up what you've suggested later on.
Regarding nesting if statements I don't really like it. You prefer it because of perf?

@melchiar
Copy link
Member

melchiar commented Apr 9, 2022

Continue there, I'll patch up what you've suggested later on. Regarding nesting if statements I don't really like it. You prefer it because of perf?

I try to avoid multiple checks for the same conditions.

@ShaMan123
Copy link
Contributor Author

I dislike nesting logic, I prefer it flat as possible

@melchiar
Copy link
Member

melchiar commented Apr 9, 2022

fair enough. this is excellent by the way πŸ‘

@stale
Copy link

stale bot commented Apr 25, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue marked as stale by the stale bot label Apr 25, 2022
@ShaMan123 ShaMan123 removed the stale Issue marked as stale by the stale bot label Apr 25, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.04 |    75.97 |    85.7 |   82.76 |                                               
 fabric.js |   83.04 |    75.97 |    85.7 |   82.76 | ...,30844,30918,30929-30994,31117,31216,31452 
-----------|---------|----------|---------|---------|-----------------------------------------------

@asturur
Copy link
Member

asturur commented May 1, 2022

Catching up with this.

ShaMan123 added a commit that referenced this pull request May 1, 2022
Some logic is leaking between PRs. this belongs to #7861
return util.calcRotateMatrix(this);
_calcRotateMatrix: function (absolute, accountForFlipping) {
var angle = absolute ? this.getTotalAngle() : this.angle;
accountForFlipping && this.flipX && (angle -= 180);
Copy link
Member

Choose a reason for hiding this comment

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

i wonder how nested flippings behave.

Copy link
Contributor Author

@ShaMan123 ShaMan123 May 2, 2022

Choose a reason for hiding this comment

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

I wonder/forgot why I accounted for flipX only for nested objects, why not for all objects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's bad. Good catch.
Isn't flipX/flipY a z plane transformation? If so wouldn't it be better to multiply 3d matrices?

Copy link
Contributor Author

@ShaMan123 ShaMan123 May 2, 2022

Choose a reason for hiding this comment

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

rotation as used by fabric is a 2d plane transformation. So it shouldn't relate to z plane transformations. I think this is the cause of the problem (in all flipX/Y logic)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@ShaMan123 ShaMan123 May 2, 2022

Choose a reason for hiding this comment

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

@asturur Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess we can use matrix projection from 3d -> 2d...

Copy link
Contributor Author

@ShaMan123 ShaMan123 May 2, 2022

Choose a reason for hiding this comment

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

But it opens up 3d and I'm not sure we want that.
So I vote to remove flip props as they are broken

Copy link
Contributor Author

@ShaMan123 ShaMan123 May 2, 2022

Choose a reason for hiding this comment

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

remove `_calcRotateMatrix`, `_calcTranslateMatrix`
@github-actions
Copy link
Contributor

github-actions bot commented May 2, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.05 |    75.98 |   85.69 |   82.78 |                                               
 fabric.js |   83.05 |    75.98 |   85.69 |   82.78 | ...,30850,30924,30935-31000,31123,31222,31458 
-----------|---------|----------|---------|---------|-----------------------------------------------

Comment on lines +575 to +583
var vpt = this.getViewportTransform(),
center = this.getCenterPoint(),
tMatrix = [1, 0, 0, 1, center.x, center.y],
rMatrix = util.calcRotateMatrix({ angle: this.getTotalAngle() - (!!this.group && this.flipX ? 180 : 0) }),
positionMatrix = multiplyMatrices(tMatrix, rMatrix),
startMatrix = multiplyMatrices(vpt, positionMatrix),
finalMatrix = multiplyMatrices(startMatrix, [1 / vpt[0], 0, 0, 1 / vpt[3], 0, 0]),
transformOptions = this.group ? fabric.util.qrDecompose(this.calcTransformMatrix()) : undefined,
dim = this._calculateCurrentDimensions(transformOptions),
Copy link
Member

Choose a reason for hiding this comment

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

Just to be clear, i m sure there are bugs with angle compensation but is not important. This PR improves the situation anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(!!this.group && this.flipX ? 180 : 0)
I can't imagine this is good enough for sure.

@asturur
Copy link
Member

asturur commented May 2, 2022

For the reader of the future.
If the controlbox of an object appear different when is inside a group from when is outside, that is probably possible and is not considered a bug. As long as controls works in both situation that is considered an acceptable quirk.

@ShaMan123
Copy link
Contributor Author

For the reader of the future. If the controlbox of an object appear different when is inside a group from when is outside, that is probably possible and is not considered a bug. As long as controls works in both situation that is considered an acceptable quirk.

😨

I see it as a bug in qrDecompose. Fixing it means moving to 3d transformation matrix or dropping flipX/Y for good (I think that's not a bad idea - very strange feature)

For the reader of the future - We are sorry this is how it is. STAY AWAY from flipX/Y.

@ShaMan123 ShaMan123 merged commit b47814f into master May 2, 2022
@asturur
Copy link
Member

asturur commented May 3, 2022

flipX and flipY are totally normal, and are just an abstraction for a negative scale that is totally normal too.
You can't propose someone to have nested groups of different types but not being able to flip an image, is a basic feature imho.
qrDecompose isn't bugged in a strict sense, it just does what it can do.
As we talked before we have more trasform variable than 6 numbers and we don't have as many relationship between numbers.

is like when you get a 6, was it 3 x 2 or 6 x 1? you can't know.

I m not sure a different matrix would help, unless rotation and scale occupy different cells in the matrix.

[scaleX * cosA] [ -sinA ] [translateX]
[sinA] [scaleY * cosA] [translateY]

idependently from the fact that the mulitplication between trasnformation make everything even more complicated, the biggest lie is in the fact that the position 'a' and 'd' of the transform matrix are occupied by scale ( and so flip ) and a part of the rotation. with the cosine that can be negative or positive and the scale too, once you have those multipled together, if you decompose a matrix without knowing how the object ( and the parents ) are flipped or not flipped, you can't get out of it.
Oh and skewX and skewY are also there somewhere together with rotation. I just see more variables than equations between them i can think of.

@ShaMan123
Copy link
Contributor Author

ShaMan123 commented May 3, 2022

flipX and flipY are totally normal, and are just an abstraction for a negative scale that is totally normal too.

Is it negative scale or 180deg rotation around the x/y axis? Or are the 2 cases the same thing?

Oh and skewX and skewY are also there somewhere together with rotation

Confusing indeed. However the characteristic polynomial might serve as an answer in this case (not sure about it though) 'cause if a matrix is multiplied by a rotation matrix it doesn't have a solution for the characteristic polynomial. Meaning that we can check to see if there is a solution and if so we know the angle was 0. And I read about extracting a rotation matrix be it's heavy stuff.
ShaMan123@22e472b

Did you look at ml-matrix?

Apart from qr decomposition we can do something with eigenvalues that might help determine the rotation...

I really don't know enough linear algebra to solve this.

I just see more variables than equations between them i can think of.

Yes, Is true.

@asturur asturur deleted the v6-fix-nested-controls branch September 11, 2022 23:03
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.

3 participants