Commit 622bf9ae by mal Committed by Dmitry Baranovskiy

Fixed flipping in negative scaling animations

Added var for math.abs
parent f17d24d5
...@@ -44,6 +44,7 @@ window.Raphael = (function () { ...@@ -44,6 +44,7 @@ window.Raphael = (function () {
math = Math, math = Math,
mmax = math.max, mmax = math.max,
mmin = math.min, mmin = math.min,
abs = math.abs,
nu = "number", nu = "number",
toString = "toString", toString = "toString",
objectToString = Object[proto][toString], objectToString = Object[proto][toString],
...@@ -571,12 +572,12 @@ window.Raphael = (function () { ...@@ -571,12 +572,12 @@ window.Raphael = (function () {
sin = math.sin(PI / 180 * angle), sin = math.sin(PI / 180 * angle),
x = (x1 - x2) / 2, x = (x1 - x2) / 2,
y = (y1 - y2) / 2; y = (y1 - y2) / 2;
rx = mmax(rx, math.abs(x)); rx = mmax(rx, abs(x));
ry = mmax(ry, math.abs(y)); ry = mmax(ry, abs(y));
var rx2 = rx * rx, var rx2 = rx * rx,
ry2 = ry * ry, ry2 = ry * ry,
k = (large_arc_flag == sweep_flag ? -1 : 1) * k = (large_arc_flag == sweep_flag ? -1 : 1) *
math.sqrt(math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))), math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
cx = k * rx * y / ry + (x1 + x2) / 2, cx = k * rx * y / ry + (x1 + x2) / 2,
cy = k * -ry * x / rx + (y1 + y2) / 2, cy = k * -ry * x / rx + (y1 + y2) / 2,
f1 = math.asin(((y1 - cy) / ry).toFixed(7)), f1 = math.asin(((y1 - cy) / ry).toFixed(7)),
...@@ -599,7 +600,7 @@ window.Raphael = (function () { ...@@ -599,7 +600,7 @@ window.Raphael = (function () {
cy = recursive[3]; cy = recursive[3];
} }
var df = f2 - f1; var df = f2 - f1;
if (math.abs(df) > _120) { if (abs(df) > _120) {
var f2old = f2, var f2old = f2,
x2old = x2, x2old = x2,
y2old = y2; y2old = y2;
...@@ -649,8 +650,8 @@ window.Raphael = (function () { ...@@ -649,8 +650,8 @@ window.Raphael = (function () {
y = [p1y, p2y], y = [p1y, p2y],
x = [p1x, p2x], x = [p1x, p2x],
dot; dot;
math.abs(t1) > 1e12 && (t1 = .5); abs(t1) > 1e12 && (t1 = .5);
math.abs(t2) > 1e12 && (t2 = .5); abs(t2) > 1e12 && (t2 = .5);
if (t1 > 0 && t1 < 1) { if (t1 > 0 && t1 < 1) {
dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1); dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
x[push](dot.x); x[push](dot.x);
...@@ -666,8 +667,8 @@ window.Raphael = (function () { ...@@ -666,8 +667,8 @@ window.Raphael = (function () {
c = p1y - c1y; c = p1y - c1y;
t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a; t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a; t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
math.abs(t1) > 1e12 && (t1 = .5); abs(t1) > 1e12 && (t1 = .5);
math.abs(t2) > 1e12 && (t2 = .5); abs(t2) > 1e12 && (t2 = .5);
if (t1 > 0 && t1 < 1) { if (t1 > 0 && t1 < 1) {
dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1); dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
x[push](dot.x); x[push](dot.x);
...@@ -972,7 +973,7 @@ window.Raphael = (function () { ...@@ -972,7 +973,7 @@ window.Raphael = (function () {
return null; return null;
} }
var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)], var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)],
max = 1 / (mmax(math.abs(vector[2]), math.abs(vector[3])) || 1); max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
vector[2] *= max; vector[2] *= max;
vector[3] *= max; vector[3] *= max;
if (vector[2] < 0) { if (vector[2] < 0) {
...@@ -2551,23 +2552,25 @@ window.Raphael = (function () { ...@@ -2551,23 +2552,25 @@ window.Raphael = (function () {
var bb = this.getBBox(), var bb = this.getBBox(),
rcx = bb.x + bb.width / 2, rcx = bb.x + bb.width / 2,
rcy = bb.y + bb.height / 2, rcy = bb.y + bb.height / 2,
kx = x / this._.sx, kx = abs(x / this._.sx),
ky = y / this._.sy; ky = abs(y / this._.sy);
cx = (+cx || cx == 0) ? cx : rcx; cx = (+cx || cx == 0) ? cx : rcx;
cy = (+cy || cy == 0) ? cy : rcy; cy = (+cy || cy == 0) ? cy : rcy;
var dirx = ~~(x / math.abs(x)), var dirx = ~~(x / abs(x)),
diry = ~~(y / math.abs(y)), diry = ~~(y / abs(y)),
dkx = kx * dirx,
dky = ky * diry,
s = this.node.style, s = this.node.style,
ncx = cx + (rcx - cx) * kx, ncx = cx - abs(rcx - cx) * dkx,
ncy = cy + (rcy - cy) * ky; ncy = cy - abs(rcy - cy) * dky;
switch (this.type) { switch (this.type) {
case "rect": case "rect":
case "image": case "image":
var neww = a.width * dirx * kx, var neww = a.width * kx,
hewh = a.height * diry * ky; newh = a.height * ky;
this.attr({ this.attr({
height: newh, height: newh,
r: a.r * mmin(dirx * kx, diry * ky), r: a.r * mmin(kx, ky),
width: neww, width: neww,
x: ncx - neww / 2, x: ncx - neww / 2,
y: ncy - newh / 2 y: ncy - newh / 2
...@@ -2576,9 +2579,9 @@ window.Raphael = (function () { ...@@ -2576,9 +2579,9 @@ window.Raphael = (function () {
case "circle": case "circle":
case "ellipse": case "ellipse":
this.attr({ this.attr({
rx: a.rx * dirx * kx, rx: a.rx * kx,
ry: a.ry * diry * ky, ry: a.ry * ky,
r: a.r * mmin(dirx * kx, diry * ky), r: a.r * mmin(kx, ky),
cx: ncx, cx: ncx,
cy: ncy cy: ncy
}); });
...@@ -2596,22 +2599,22 @@ window.Raphael = (function () { ...@@ -2596,22 +2599,22 @@ window.Raphael = (function () {
skip = false; skip = false;
} }
if (P0 == "A") { if (P0 == "A") {
p[path[i][length] - 2] *= kx; p[path[i][length] - 2] = abs(p[path[i][length] - 2]) * dkx;
p[path[i][length] - 1] *= ky; p[path[i][length] - 1] = abs(p[path[i][length] - 1]) * dky;
p[1] *= dirx * kx; p[1] *= kx;
p[2] *= diry * ky; p[2] *= ky;
p[5] = +(dirx + diry ? !!+p[5] : !+p[5]); p[5] = +(dirx + diry ? !+p[4] : !!+p[4]);
} else if (P0 == "H") { } else if (P0 == "H") {
for (j = 1, jj = p[length]; j < jj; j++) { for (j = 1, jj = p[length]; j < jj; j++) {
p[j] *= kx; p[j] = abs(p[j]) * dkx;
} }
} else if (P0 == "V") { } else if (P0 == "V") {
for (j = 1, jj = p[length]; j < jj; j++) { for (j = 1, jj = p[length]; j < jj; j++) {
p[j] *= ky; p[j] = abs(p[j]) * dky;
} }
} else { } else {
for (j = 1, jj = p[length]; j < jj; j++) { for (j = 1, jj = p[length]; j < jj; j++) {
p[j] *= (j % 2) ? kx : ky; p[j] = abs(p[j]) * ( (j % 2) ? dkx : dky );
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment