PageRenderTime 43ms CodeModel.GetById 20ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 1ms

/extra/svg/svg-tests.factor

http://github.com/abeaumont/factor
Unknown | 116 lines | 91 code | 25 blank | 0 comment | 0 complexity | fec31eef58bcaf5f42ec6b9136b5713f MD5 | raw file
  1! (c)2009 Joe Groff, see BSD license
  2USING: accessors arrays literals math math.affine-transforms
  3math.functions sequences svg tools.test xml xml.traversal multiline ;
  4IN: svg.tests
  5
  6{ 1.0 2.25 } { -3.0 4.0 } { 5.5 0.5 } <affine-transform> 1array [
  7    "matrix ( 1 +2.25 -3  , 0.4e+1  ,5.5, 5e-1 )" svg-transform>affine-transform
  8] unit-test
  9
 10{ 1.0 0.0 } { 0.0 1.0 } { 5.0 10.0 } <affine-transform> 1array [
 11    "translate(5.0, 1e1 )" svg-transform>affine-transform
 12] unit-test
 13
 14{ 1.0 0.0 } { 0.0 1.0 } { 5.0 10.0 } <affine-transform> 1array [
 15    "translate( 5.0  1e+1)" svg-transform>affine-transform
 16] unit-test
 17
 18{ 2.0 0.0 } { 0.0 2.0 } { 0.0 0.0 } <affine-transform> 1array [
 19    "scale(2.0)" svg-transform>affine-transform
 20] unit-test
 21
 22{ 2.0 0.0 } { 0.0 4.0 } { 0.0 0.0 } <affine-transform> 1array [
 23    "scale(2.0 4.0)" svg-transform>affine-transform
 24] unit-test
 25
 26{ 2.0 0.0 } { 0.0 4.0 } { 0.0 0.0 } <affine-transform> 1array [
 27    "scale(2.0 4.0)" svg-transform>affine-transform
 28] unit-test
 29
 30[ t ] [
 31    "skewX(45)" svg-transform>affine-transform
 32    { 1.0 0.0 } { 1.0 1.0 } { 0.0 0.0 } <affine-transform> 0.001 a~
 33] unit-test
 34
 35[ t ] [
 36    "skewY(-4.5e1)" svg-transform>affine-transform
 37    { 1.0 -1.0 } { 0.0 1.0 } { 0.0 0.0 } <affine-transform> 0.001 a~
 38] unit-test
 39
 40[ t ] [
 41    "rotate(30)" svg-transform>affine-transform
 42    { $[ 0.75 sqrt ] 0.5            }
 43    { -0.5           $[ 0.75 sqrt ] }
 44    {  0.0           0.0            } <affine-transform> 
 45    0.001 a~
 46] unit-test
 47
 48[ t ] [
 49    "rotate(30 1.0,2.0)" svg-transform>affine-transform
 50    { $[  30 degrees cos ] $[ 30 degrees sin ] }
 51    { $[ -30 degrees sin ] $[ 30 degrees cos ] } {
 52        $[ 1.0 30 degrees cos 1.0 * - 30 degrees sin 2.0 * + ]
 53        $[ 2.0 30 degrees cos 2.0 * - 30 degrees sin 1.0 * - ]
 54    } <affine-transform> 0.001 a~
 55] unit-test
 56
 57{ $[  30 degrees cos ] $[ 30 degrees sin ] }
 58{ $[ -30 degrees sin ] $[ 30 degrees cos ] }
 59{ 1.0 2.0 } <affine-transform> 1array [
 60    "translate(1 2) rotate(30)" svg-transform>affine-transform
 61] unit-test
 62
 63[ {
 64    T{ moveto f { 1.0  1.0 } f }
 65    T{ lineto f { 3.0 -1.0 } f }
 66
 67    T{ lineto f { 2.0  2.0 } t }
 68    T{ lineto f { 2.0 -2.0 } t }
 69    T{ lineto f { 2.0  2.0 } t }
 70
 71    T{ vertical-lineto f -9.0 t }
 72    T{ vertical-lineto f  1.0 t }
 73    T{ horizontal-lineto f 9.0 f }
 74    T{ horizontal-lineto f 8.0 f }
 75
 76    T{ closepath }
 77
 78    T{ moveto f { 0.0 0.0 } f }
 79
 80    T{ curveto f { -4.0 0.0 } { -8.0 4.0 } { -8.0 8.0 } f }
 81    T{ curveto f { -8.0 4.0 } { -12.0 8.0 } { -16.0 8.0 } f }
 82
 83    T{ smooth-curveto f { 0.0 2.0 } { 2.0 0.0 } t }
 84
 85    T{ quadratic-bezier-curveto f { -2.0 0.0 } { 0.0 -2.0 } f }
 86    T{ quadratic-bezier-curveto f { -3.0 0.0 } { 0.0  3.0 } f }
 87
 88    T{ smooth-quadratic-bezier-curveto f { 1.0 2.0 } t }
 89    T{ smooth-quadratic-bezier-curveto f { 3.0 4.0 } t }
 90
 91    T{ elliptical-arc f { 5.0 6.0 } 7.0 t f { 8.0 9.0 } f }
 92} ] [
 93    """
 94    M 1.0,+1 3,-10e-1  l 2 2, 2 -2, 2 2   v -9 1 H 9 8  z 
 95    M 0 0  C -4.0 0.0 -8.0 4.0 -8.0 8.0  -8.0 4.0 -12.0 8.0 -16.0 8.0
 96    s 0.0,2.0 2.0,0.0
 97    Q -2 0 0 -2 -3. 0 0 3
 98    t 1 2 3 4
 99    A 5 6 7 1 0 8 9
100    """ svg-path>array
101] unit-test
102
103STRING: test-svg-string
104<svg xmlns="http://www.w3.org/2000/svg">
105        <path transform="translate(1 2)" d="M -1 -1 l 2 2" />
106</svg>
107;
108
109: test-svg-path ( -- obj )
110    test-svg-string string>xml body>> children-tags first ;
111
112[ { T{ moveto f { -1.0 -1.0 } f } T{ lineto f { 2.0 2.0 } t } } ]
113[ test-svg-path tag-d ] unit-test
114
115[ T{ affine-transform f { 1.0 0.0 } { 0.0 1.0 } { 1.0 2.0 } } ]
116[ test-svg-path tag-transform ] unit-test