Skip to content

Commit

Permalink
feat: fromCTM
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryGogonis committed Jul 14, 2017
1 parent 58d3c2c commit 27377b8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ These matrices can be used for matrix calcuations on SVG CTMs (current transform
* _static_
* [.Matrix](#module_immutable-transform-matrix..Matrix.Matrix)
* [new Matrix(a, b, c, d, e, f)](#new_module_immutable-transform-matrix..Matrix.Matrix_new)
* [.fromCTM(ctm)](#module_immutable-transform-matrix..Matrix.fromCTM) ⇒ <code>Matrix</code>

<a name="module_immutable-transform-matrix..Matrix"></a>

Expand All @@ -49,6 +50,7 @@ These matrices can be used for matrix calcuations on SVG CTMs (current transform
* _static_
* [.Matrix](#module_immutable-transform-matrix..Matrix.Matrix)
* [new Matrix(a, b, c, d, e, f)](#new_module_immutable-transform-matrix..Matrix.Matrix_new)
* [.fromCTM(ctm)](#module_immutable-transform-matrix..Matrix.fromCTM) ⇒ <code>Matrix</code>

<a name="module_immutable-transform-matrix..Matrix+transform"></a>

Expand Down Expand Up @@ -197,3 +199,14 @@ Construct a Matrix. Creates an Identiy matrix if no params are supplied.
| e | <code>number</code> |
| f | <code>number</code> |

<a name="module_immutable-transform-matrix..Matrix.fromCTM"></a>

#### Matrix.fromCTM(ctm) ⇒ <code>Matrix</code>
Construct a new Matrix constructed from an SVGMatrix

**Kind**: static method of [<code>Matrix</code>](#module_immutable-transform-matrix..Matrix)

| Param | Type |
| --- | --- |
| ctm | <code>SVGMatrix</code> |

10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ class Matrix extends Map {
}
}

/**
* Construct a new Matrix constructed from an SVGMatrix
* @param {SVGMatrix} ctm
* @return {Matrix}
*/
static fromCTM (ctm) {
const {a, b, c, d, e, f} = ctm
return new Matrix(a, b, c, d, e, f)
}

/**
* Multiplies current matrix with new matrix values.
* @param {number} a2 - scale x
Expand Down
15 changes: 15 additions & 0 deletions src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,18 @@ describe('#applyToPoint', () => {
expect(new Matrix().applyToPoint(x, y)).toEqual({x, y})
})
})

describe('fromCTM', () => {
it('should return a new Matrix', () => {
const actual = Matrix.fromCTM({
a: 1,
b: 2,
c: 3,
d: 4,
e: 5,
f: 6
})
const expected = new Matrix(1, 2, 3, 4, 5, 6)
expect(actual).toEqual(expected)
})
})

0 comments on commit 27377b8

Please sign in to comment.