mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-26 00:14:42 +00:00
reduce angle calculation error for cosin of 90 and 270 degrees (#3872)
* reduce angle calculation error * reduce angle calculation error
This commit is contained in:
parent
79c21cf188
commit
17035c7480
2 changed files with 17 additions and 12 deletions
|
|
@ -976,13 +976,6 @@
|
|||
angle = radiansToDegrees(curAngle - lastAngle + t.theta),
|
||||
hasRoated = true;
|
||||
|
||||
// normalize angle to positive value
|
||||
if (angle < 0) {
|
||||
angle = 360 + angle;
|
||||
}
|
||||
|
||||
angle %= 360;
|
||||
|
||||
if (t.target.snapAngle > 0) {
|
||||
var snapAngle = t.target.snapAngle,
|
||||
snapThreshold = t.target.snapThreshold || snapAngle,
|
||||
|
|
@ -995,13 +988,21 @@
|
|||
else if (Math.abs(angle - rightAngleLocked) < snapThreshold) {
|
||||
angle = rightAngleLocked;
|
||||
}
|
||||
|
||||
if (t.target.angle === angle) {
|
||||
hasRoated = false;
|
||||
}
|
||||
}
|
||||
|
||||
t.target.angle = angle;
|
||||
// normalize angle to positive value
|
||||
if (angle < 0) {
|
||||
angle = 360 + angle;
|
||||
}
|
||||
angle %= 360;
|
||||
|
||||
if (t.target.angle === angle) {
|
||||
hasRoated = false;
|
||||
}
|
||||
else {
|
||||
t.target.angle = angle;
|
||||
}
|
||||
|
||||
return hasRoated;
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -450,6 +450,10 @@
|
|||
_calcRotateMatrix: function() {
|
||||
if (this.angle) {
|
||||
var theta = degreesToRadians(this.angle), cos = Math.cos(theta), sin = Math.sin(theta);
|
||||
// trying to keep rounding error small, ugly but it works.
|
||||
if (cos === 6.123233995736766e-17 || cos === -1.8369701987210297e-16) {
|
||||
cos = 0;
|
||||
}
|
||||
return [cos, sin, -sin, cos, 0, 0];
|
||||
}
|
||||
return fabric.iMatrix.concat();
|
||||
|
|
|
|||
Loading…
Reference in a new issue