Added methods for performing skew transform on the Matrix objects.

master
Mariusz Jamro 2015-08-03 21:05:12 +02:00
parent 2fee8b0b4c
commit ec89611d5d
2 changed files with 73 additions and 0 deletions

View File

@ -153,6 +153,43 @@ Snap.plugin(function (Snap, Element, Paper, glob, Fragment) {
this.add(cos, sin, -sin, cos, x, y);
return this.add(1, 0, 0, 1, -x, -y);
};
/*\
* Matrix.skewX
[ method ]
**
* Skews the matrix along the x-axis
- x (number) Angle to skew along the x-axis (in degrees).
\*/
matrixproto.skewX = function (x) {
return this.skew(x, 0);
};
/*\
* Matrix.skewY
[ method ]
**
* Skews the matrix along the y-axis
- y (number) Angle to skew along the y-axis (in degrees).
\*/
matrixproto.skewY = function (y) {
return this.skew(0, y);
};
/*\
* Matrix.skew
[ method ]
**
* Skews the matrix
- y (number) Angle to skew along the y-axis (in degrees).
- x (number) Angle to skew along the x-axis (in degrees).
\*/
matrixproto.skew = function (x, y) {
x = x || 0;
y = y || 0;
x = Snap.rad(x);
y = Snap.rad(y);
var c = math.tan(x).toFixed(9);
var b = math.tan(y).toFixed(9);
return this.add(1, b, c, 1, 0, 0);
};
/*\
* Matrix.x
[ method ]

View File

@ -183,6 +183,42 @@ describe("Matrix methods", function () {
f: 18
});
});
it("Matrix.skewX", function() {
var matrix = new Snap.Matrix(1, 0, 0, 1, 20, 30);
matrix.skewX(45);
expect(matrix).to.eql({
a: 1,
b: 0,
c: 1,
d: 1,
e: 20,
f: 30
});
});
it("Matrix.skewY", function() {
var matrix = new Snap.Matrix(1, 0, 0, 1, 20, 30);
matrix.skewY(45);
expect(matrix).to.eql({
a: 1,
b: 1,
c: 0,
d: 1,
e: 20,
f: 30
});
});
it("Matrix.skew", function() {
var matrix = new Snap.Matrix(1, 0, 0, 1, 20, 30);
matrix.skew(45, -45);
expect(matrix).to.eql({
a: 1,
b: -1,
c: 1,
d: 1,
e: 20,
f: 30
});
});
it("Matrix.x", function() {
var matrix = new Snap.Matrix(1, 0, 0, 1, 20, 30);
var result = matrix.x(10, -10);