on master help sign in
Add scale and documentation for translation
3a02543Michael Sondergaard
libraries/Native/Transform2D.js−4
@@ -37,9 +37,6 @@ Elm.Native.Transform2D.make = function(elm) {
37 var s = Math.sin(t);
37 var s = Math.sin(t);
38 return new A([c, -s, 0, s, c, 0]);
38 return new A([c, -s, 0, s, c, 0]);
39 }
39 }
40− function translation(x,y) {
41− return new A([1,0,x,0,1,y]);
42− }
43 function rotate(t,m) {
40 function rotate(t,m) {
44 var c = Math.cos(t);
41 var c = Math.cos(t);
45 var s = Math.sin(t);
42 var s = Math.sin(t);
@@ -86,7 +83,6 @@ Elm.Native.Transform2D.make = function(elm) {
86 identity:identity,
83 identity:identity,
87 matrix:F6(matrix),
84 matrix:F6(matrix),
88 rotation:rotation,
85 rotation:rotation,
89− translation:F2(translation),
90 multiply:F2(multiply)
86 multiply:F2(multiply)
91 /*
87 /*
92 transform:F7(transform),
88 transform:F7(transform),
libraries/Transform2D.elm+19−1
@@ -46,8 +46,26 @@ Given an angle t, it creates a counterclockwise rotation matrix:
46rotation : Float -> Transform2D
46rotation : Float -> Transform2D
47rotation = Native.Transform2D.rotation
47rotation = Native.Transform2D.rotation
48
48
49+{-| Creates a transformation matrix for translation:
50+
51+ translation x y
52+
53+ / 1 0 x \
54+ | 0 1 y |
55+ \ 0 0 1 /
56+-}
49translation : Float -> Float -> Transform2D
57translation : Float -> Float -> Transform2D
50−translation = Native.Transform2D.translation
58+translation x y = matrix 1 0 0 1 x y
59+
60+{-| Creates a transformation matrix for scaling by a all directions:
61+
62+ scale a
63+
64+ / a 0 \
65+ \ 0 a /
66+-}
67+scale : Float -> Transform2D
68+scale a = matrix a 0 0 a 0 0
51
69
52{-| Creates a transformation for horizontal scaling -}
70{-| Creates a transformation for horizontal scaling -}
53scaleX : Float -> Transform2D
71scaleX : Float -> Transform2D