Skip to content

Commit

Permalink
Skew transformations added
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Nov 21, 2013
1 parent 7bc0390 commit 930b9c4
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
51 changes: 51 additions & 0 deletions dist/SVGPathData.js
Original file line number Diff line number Diff line change
Expand Up @@ -7185,6 +7185,24 @@ SVGPathData.prototype.rotate = function() {
return this;
};

SVGPathData.prototype.matrix = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.MATRIX, arguments);
return this;
};

SVGPathData.prototype.skewX = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.SKEW_X, arguments);
return this;
};

SVGPathData.prototype.skewY = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.SKEW_Y, arguments);
return this;
};

SVGPathData.prototype.ySymetry = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.Y_AXIS_SIMETRY, arguments);
Expand Down Expand Up @@ -8055,6 +8073,39 @@ SVGPathDataTransformer.ROTATE = function(a, x, y) {
};
};

// Matrix
SVGPathDataTransformer.MATRIX = function(a, b, c, d, e, f) {
return function(command) {
if('undefined' !== command.x) {
command.x = command.x * a + command.y * c + e;
}
if('undefined' !== command.y) {
command.y = command.x * b + command.y * d + f;
}
if('undefined' !== command.x1) {
command.x1 = command.x1 * a + command.y1 * c + e;
}
if('undefined' !== command.y1) {
command.y1 = command.x1 * b + command.y1 * d + f;
}
if('undefined' !== command.x2) {
command.x2 = command.x2 * a + command.y2 * c + e;
}
if('undefined' !== command.y2) {
command.y2 = command.x2 * b + command.y2 * d + f;
}
return command;
};
};

// Skew
SVGPathDataTransformer.SKEW_X = function(a) {
return SVGPathDataTransformer.MATRIX(1, 0, Math.atan(a), 1, 0, 0);
}
SVGPathDataTransformer.SKEW_Y = function(a) {
return SVGPathDataTransformer.MATRIX(1, Math.atan(a), 0, 1, 0, 0);
}

// Symetry througth the Y axis
SVGPathDataTransformer.Y_AXIS_SIMETRY = function(yDecal) {
var notFirst = false;
Expand Down
18 changes: 18 additions & 0 deletions src/SVGPathData.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ SVGPathData.prototype.rotate = function() {
return this;
};

SVGPathData.prototype.matrix = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.MATRIX, arguments);
return this;
};

SVGPathData.prototype.skewX = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.SKEW_X, arguments);
return this;
};

SVGPathData.prototype.skewY = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.SKEW_Y, arguments);
return this;
};

SVGPathData.prototype.ySymetry = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.Y_AXIS_SIMETRY, arguments);
Expand Down
33 changes: 33 additions & 0 deletions src/SVGPathDataTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,39 @@ SVGPathDataTransformer.ROTATE = function(a, x, y) {
};
};

// Matrix
SVGPathDataTransformer.MATRIX = function(a, b, c, d, e, f) {
return function(command) {
if('undefined' !== command.x) {
command.x = command.x * a + command.y * c + e;
}
if('undefined' !== command.y) {
command.y = command.x * b + command.y * d + f;
}
if('undefined' !== command.x1) {
command.x1 = command.x1 * a + command.y1 * c + e;
}
if('undefined' !== command.y1) {
command.y1 = command.x1 * b + command.y1 * d + f;
}
if('undefined' !== command.x2) {
command.x2 = command.x2 * a + command.y2 * c + e;
}
if('undefined' !== command.y2) {
command.y2 = command.x2 * b + command.y2 * d + f;
}
return command;
};
};

// Skew
SVGPathDataTransformer.SKEW_X = function(a) {
return SVGPathDataTransformer.MATRIX(1, 0, Math.atan(a), 1, 0, 0);
}
SVGPathDataTransformer.SKEW_Y = function(a) {
return SVGPathDataTransformer.MATRIX(1, Math.atan(a), 0, 1, 0, 0);
}

// Symetry througth the Y axis
SVGPathDataTransformer.Y_AXIS_SIMETRY = function(yDecal) {
var notFirst = false;
Expand Down

0 comments on commit 930b9c4

Please sign in to comment.