Skip to content

Commit

Permalink
refactor: change the translateY calculation to avoid side effects
Browse files Browse the repository at this point in the history
ref #1152
  • Loading branch information
fengyuanchen committed Apr 14, 2024
1 parent 4e4ce43 commit 4d2665e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions packages/element-image/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export default class CropperImage extends CropperElement {
const moveX = x - originX;
const moveY = y - originY;
const translateX = ((moveX * d) - (c * moveY)) / ((a * d) - (c * b));
const translateY = (moveY - (b * translateX)) / d;
const translateY = ((moveY * a) - (b * moveX)) / ((a * d) - (c * b));

/**
* Equals to
Expand Down Expand Up @@ -405,7 +405,7 @@ export default class CropperImage extends CropperElement {
if (this.translatable && isNumber(x) && isNumber(y)) {
const [a, b, c, d] = this.$matrix;
const e = ((x * d) - (c * y)) / ((a * d) - (c * b));
const f = (y - (b * e)) / d;
const f = ((y * a) - (b * x)) / ((a * d) - (c * b));

this.$translate(e, f);
}
Expand All @@ -423,7 +423,7 @@ export default class CropperImage extends CropperElement {
if (this.translatable && isNumber(x) && isNumber(y)) {
const [a, b, c, d] = this.$matrix;
const e = ((x * d) - (c * y)) / ((a * d) - (c * b));
const f = (y - (b * e)) / d;
const f = ((y * a) - (b * x)) / ((a * d) - (c * b));

this.$setTransform(a, b, c, d, e, f);
}
Expand Down Expand Up @@ -455,7 +455,7 @@ export default class CropperImage extends CropperElement {
const moveX = x - originX;
const moveY = y - originY;
const translateX = ((moveX * d) - (c * moveY)) / ((a * d) - (c * b));
const translateY = (moveY - (b * translateX)) / d;
const translateY = ((moveY * a) - (b * moveX)) / ((a * d) - (c * b));

/**
* Equals to
Expand Down Expand Up @@ -505,7 +505,7 @@ export default class CropperImage extends CropperElement {
const moveX = x - originX;
const moveY = y - originY;
const translateX = ((moveX * d) - (c * moveY)) / ((a * d) - (c * b));
const translateY = (moveY - (b * translateX)) / d;
const translateY = ((moveY * a) - (b * moveX)) / ((a * d) - (c * b));

/**
* Equals to
Expand Down
2 changes: 1 addition & 1 deletion packages/element-selection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ export default class CropperSelection extends CropperElement {
const offsetX = -this.x;
const offsetY = -this.y;
const translateX = ((offsetX * d) - (c * offsetY)) / ((a * d) - (c * b));
const translateY = (offsetY - (b * translateX)) / d;
const translateY = ((offsetY * a) - (b * offsetX)) / ((a * d) - (c * b));
let newE = a * translateX + c * translateY + e;
let newF = b * translateX + d * translateY + f;
let destWidth = image.naturalWidth;
Expand Down

0 comments on commit 4d2665e

Please sign in to comment.