Jump To …

transform_test.coffee

{Matrix} = require '../test_helper'

module.exports =
  "Point transformation": (test) ->
    scale = new Matrix( 2, 0, 0, 2 )
    translate = new Matrix( 1, 0, 0, 1, 15, 50 )

    test.deepEqual scale.transform( x: 25, y: 50 ),       x: 50, y: 100
    test.deepEqual translate.transform( x: 20, y: 20 ),   x: 35, y: 70
    test.done()
  
  "Transformation accepting several arguments": (test) ->
    test.deepEqual Matrix.scaled(2,2).transform({x:10,y:5},{x:-20,y:20}),  [{x:20,y:10},{x:-40,y:40}]
    test.done()
  
  "Transformations of array of points": (test) ->
    points = [
      { x: 10, y : 12 }
      { x: -13, y: 23 }
      { x: 50, y: -120 }
    ]
    expected = for p in points
      { x: -1.5 * p.x + 20 * (1 + 1.5), y: 3 * p.y + 30 * (1 - 3) }
    
    actual = Matrix.scaled(-1.5,3,x:20,y:30).transform points
    
    test.equal actual.length, 3
    test.deepEqual actual, expected
    
    test.done()