Skip to content

Commit

Permalink
Added .skewX() & skewY() shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Sep 11, 2016
1 parent b1f0d2e commit 44f5c8e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2.2.0 / WIP
------------------

- Added `.skewX()` & `.skewY()` shortcuts.
- Dropped `Makefile`, use npm instead.
- Deps bump & cleanup.


2.1.6 / 2016-03-09
------------------

Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,20 @@ Rescale path (the same as SVG `translate` transformation). `y` = 0 by default.

### .rotate(angle [, rx, ry]) -> self

Rotate path to `angle` degree around (rx, ry) point. If rotation center not set,
Rotate path to `angle` degrees around (rx, ry) point. If rotation center not set,
(0, 0) used. The same as SVG `rotate` transformation.


### .skewX(degrees) -> self

Skew path along the X axis by `degrees` angle.


### .skewY(degrees) -> self

Skew path along the Y axis by `degrees` angle.


### .matrix([ m1, m2, m3, m4, m5, m6 ]) -> self

Apply 2x3 affine transform matrix to path. Params - array. The same as SVG
Expand Down
16 changes: 16 additions & 0 deletions lib/svgpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ SvgPath.prototype.rotate = function (angle, rx, ry) {
};


// Skew path along the X axis by `degrees` angle
//
SvgPath.prototype.skewX = function (degrees) {
this.__stack.push(matrix().skewX(degrees));
return this;
};


// Skew path along the Y axis by `degrees` angle
//
SvgPath.prototype.skewY = function (degrees) {
this.__stack.push(matrix().skewY(degrees));
return this;
};


// Apply matrix transform (array of 6 elements)
//
SvgPath.prototype.matrix = function (m) {
Expand Down
22 changes: 22 additions & 0 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,28 @@ describe('API', function () {
});
});

describe('skew', function () {
// SkewX matrix [ 1, 0, 4, 1, 0, 0 ],
// x = x*1 + y*4 + 0 = x + y*4
// y = x*0 + y*1 + 0 = y
it('skewX', function () {
assert.equal(
svgpath('M5 5L15 20').skewX(75.96).round(0).toString(),
'M25 5L95 20'
);
});

// SkewY matrix [ 1, 4, 0, 1, 0, 0 ],
// x = x*1 + y*0 + 0 = x
// y = x*4 + y*1 + 0 = y + x*4
it('skewY', function () {
assert.equal(
svgpath('M5 5L15 20').skewY(75.96).round(0).toString(),
'M5 25L15 80'
);
});
});


describe('matrix', function () {
// x = x*1.5 + y/2 + ( absolute ? 10 : 0)
Expand Down

0 comments on commit 44f5c8e

Please sign in to comment.