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(fabric.controlsUtils): stabilize scaleObject function #6540

Merged
merged 1 commit into from
Aug 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/controls.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
bottom: TOP,
left: RIGHT,
right: LEFT,
center: CENTER,
}, radiansToDegrees = fabric.util.radiansToDegrees,
sign = (Math.sign || function(x) { return ((x > 0) - (x < 0)) || +x; });

Expand Down Expand Up @@ -523,8 +524,13 @@
}
else {
newPoint = getLocalPoint(transform, transform.originX, transform.originY, x, y);
signX = sign(newPoint.x);
signY = sign(newPoint.y);
// use of sign: We use sign to detect change of direction of an action. sign usually change when
// we cross the origin point with the mouse. So a scale flip for example. There is an issue when scaling
// by center and scaling using one middle control ( default: mr, mt, ml, mb), the mouse movement can easily
// cross many time the origin point and flip the object. so we need a way to filter out the noise.
// This ternary here should be ok to filter out X scaling when we want Y only and vice versa.
signX = by !== 'y' ? sign(newPoint.x) : 1;
signY = by !== 'x' ? sign(newPoint.y) : 1;
if (!transform.signX) {
transform.signX = signX;
}
Expand Down Expand Up @@ -559,12 +565,12 @@
scaleX *= 2;
scaleY *= 2;
}
if (transform.signX !== signX) {
if (transform.signX !== signX && by !== 'y') {
transform.originX = opposite[transform.originX];
scaleX *= -1;
transform.signX = signX;
}
if (transform.signY !== signY) {
if (transform.signY !== signY && by !== 'x') {
transform.originY = opposite[transform.originY];
scaleY *= -1;
transform.signY = signY;
Expand Down