2011-07-01 06:17:45 -04:00
/ *
2013-01-28 21:03:27 -05:00
* Paper . js - The Swiss Army Knife of Vector Graphics Scripting .
2011-07-01 06:17:45 -04:00
* http : //paperjs.org/
*
2014-01-03 19:47:16 -05:00
* Copyright ( c ) 2011 - 2014 , Juerg Lehni & Jonathan Puckey
* http : //scratchdisk.com/ & http://jonathanpuckey.com/
2011-07-01 06:17:45 -04:00
*
* Distributed under the MIT license . See LICENSE file for details .
*
* All rights reserved .
* /
2011-02-07 13:28:09 -05:00
module ( 'Path Drawing Commands' ) ;
test ( 'path.lineTo(point);' , function ( ) {
var path = new Path ( ) ;
path . moveTo ( [ 50 , 50 ] ) ;
path . lineTo ( [ 100 , 100 ] ) ;
2011-05-04 14:40:52 -04:00
equals ( path . segments . toString ( ) , '{ point: { x: 50, y: 50 } },{ point: { x: 100, y: 100 } }' ) ;
2011-02-07 13:28:09 -05:00
} ) ;
test ( 'path.arcTo(from, through, to);' , function ( ) {
var path = new Path ( ) ;
2011-06-14 08:09:06 -04:00
path . moveTo ( [ 0 , 20 ] ) ;
path . arcTo ( [ 75 , 75 ] , [ 100 , 0 ] ) ;
equals ( path . segments . toString ( ) , '{ point: { x: 0, y: 20 }, handleOut: { x: -2.62559, y: 23.01251 } },{ point: { x: 30.89325, y: 74.75812 }, handleIn: { x: -21.05455, y: -9.65273 }, handleOut: { x: 21.05455, y: 9.65273 } },{ point: { x: 92.54397, y: 62.42797 }, handleIn: { x: -15.72238, y: 17.00811 }, handleOut: { x: 15.72238, y: -17.00811 } },{ point: { x: 100, y: 0 }, handleIn: { x: 11.27458, y: 20.23247 } }' ) ;
2011-06-05 11:22:00 -04:00
} ) ;
test ( 'path.arcTo(from, through, to); where from, through and to all share the same y position and through lies in between from and to' , function ( ) {
var path = new Path ( ) ;
path . strokeColor = 'black' ;
path . add ( [ 40 , 75 ] ) ;
path . arcTo ( [ 50 , 75 ] , [ 100 , 75 ] ) ;
equals ( path . lastSegment . point . toString ( ) , '{ x: 100, y: 75 }' , 'We expect the last segment point to be at the position where we wanted to draw the arc to.' ) ;
} ) ;
test ( 'path.arcTo(from, through, to); where from, through and to all share the same y position and through lies to the right of to' , function ( ) {
var path = new Path ( ) ;
path . strokeColor = 'black' ;
path . add ( [ 40 , 75 ] ) ;
2011-06-16 18:58:28 -04:00
var error = null ;
try {
path . arcTo ( [ 150 , 75 ] , [ 100 , 75 ] ) ;
} catch ( e ) {
error = e ;
}
equals ( error != null , true , 'We expect this arcTo() command to throw an error' ) ;
2011-06-05 11:22:00 -04:00
} ) ;
test ( 'path.arcTo(from, through, to); where from, through and to all share the same y position and through lies to the left of to' , function ( ) {
var path = new Path ( ) ;
path . strokeColor = 'black' ;
path . add ( [ 40 , 75 ] ) ;
2011-06-16 18:58:28 -04:00
var error = null ;
try {
path . arcTo ( [ 10 , 75 ] , [ 100 , 75 ] ) ;
} catch ( e ) {
error = e ;
}
equals ( error != null , true , 'We expect this arcTo() command to throw an error' ) ;
2011-02-07 13:28:09 -05:00
} ) ;