Skip to content

Commit

Permalink
Added shearX() and shearX() to 2D mode [#1640]
Browse files Browse the repository at this point in the history
Conflicts:
	processing.js
  • Loading branch information
jbuck committed May 27, 2012
2 parents 429315c + 1c9c64c commit 46fc3ec
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
30 changes: 30 additions & 0 deletions processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -5802,6 +5802,26 @@
skewY: function(angle) {
this.apply(1, 0, 1, 0, angle, 0);
},
/**
* @member PMatrix2D
* The shearX() function shears the matrix along the x-axis the amount specified by the angle parameter.
* Angles should be specified in radians (values from 0 to PI*2) or converted to radians with the <b>radians()</b> function.
*
* @param {float} angle angle of skew specified in radians
*/
shearX: function(angle) {
this.apply(1, 0, 1, Math.tan(angle) , 0, 0);
},
/**
* @member PMatrix2D
* The shearY() function shears the matrix along the y-axis the amount specified by the angle parameter.
* Angles should be specified in radians (values from 0 to PI*2) or converted to radians with the <b>radians()</b> function.
*
* @param {float} angle angle of skew specified in radians
*/
shearY: function(angle) {
this.apply(1, 0, 1, 0, Math.tan(angle), 0);
},
/**
* @member PMatrix2D
* The determinant() function calvculates the determinant of this matrix.
Expand Down Expand Up @@ -8081,6 +8101,11 @@
* @see pushMatrix
*/

Drawing2D.prototype.shearX = function(angleInRadians) {
modelView.shearX(angleInRadians);
curContext.transform(1,0,angleInRadians,1,0,0);
};

Drawing3D.prototype.shearX = function(angleInRadians) {
modelView.shearX(angleInRadians);
};
Expand Down Expand Up @@ -8109,6 +8134,11 @@
* @see shearX
*/

Drawing2D.prototype.shearY = function(angleInRadians) {
modelView.shearY(angleInRadians);
curContext.transform(1,angleInRadians,0,1,0,0);
};

Drawing3D.prototype.shearY = function(angleInRadians) {
modelView.shearY(angleInRadians);
};
Expand Down
11 changes: 11 additions & 0 deletions test/ref/shearx.pde

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions test/ref/sheary.pde

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions test/ref/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ var tests = [
{ path: "wolfram.pde", tags: ["2D", "Test Suite"] },
{ path: "pshape_ellipseMode.pde", tags: ["2D","SVG"] },
{ path: "pshape_svg.pde", tags: ["2D","SVG"] },
{ path: "shearx.pde", tags: ["2D"] },
{ path: "sheary.pde", tags: ["2D"] },
{ path: "loadShape.pde", tags: ["2D","SVG"], epsilonOverride: 0.06 },
{ path: "loadShape2.pde", tags: ["2D","SVG"], epsilonOverride: 0.08 },
{ path: "loadShape3.pde", tags: ["2D","SVG"], epsilonOverride: 0.07 },
Expand Down
25 changes: 25 additions & 0 deletions test/unit/pmatrix2d.pde
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ _checkEqual(
0.5000, 0.0000, 0.5000
], m1.array() );

//////////////////
// SHEARX/SHEARY
//////////////////

m1.reset();
m1.shearY(0.5);
_checkEqual(
[ 1.0000, 0.0000, 1.0000,
0.0000, 0.5463, 0.0000
], m1.array(), 0.00001 );

m1.reset();

m1.shearX(0.5);
_checkEqual(
[ 1.0000, 0.0000, 1.0000,
0.5463, 0.0000, 0.0000
], m1.array(), 0.00001 );

m1.shearY(0.5);
_checkEqual(
[ 1.0000, 0.0000, 2.0000,
0.5463, 0.0000, 0.5463
], m1.array(), 0.00001 );

//////////////////
// APPLY
//////////////////
Expand Down

0 comments on commit 46fc3ec

Please sign in to comment.