on master help sign in
Add scale and documentation for translation

Express translate in terms of the native matrix method instead.

commit3a02543b2667f9781d01ad82070719bdaf25b903 authorMichael Sondergaard <msond@cs.au.dk> dateMon 21 Oct 2013, 14:53 (13 years ago) parenta654bfa
2 files changed+19−5
libraries/Native/Transform2D.js−4 libraries/Transform2D.elm+19−1
libraries/Native/Transform2D.js−4
@@ -37,9 +37,6 @@ Elm.Native.Transform2D.make = function(elm) {
3737 var s = Math.sin(t);
3838 return new A([c, -s, 0, s, c, 0]);
3939 }
40− function translation(x,y) {
41− return new A([1,0,x,0,1,y]);
42− }
4340 function rotate(t,m) {
4441 var c = Math.cos(t);
4542 var s = Math.sin(t);
@@ -86,7 +83,6 @@ Elm.Native.Transform2D.make = function(elm) {
8683 identity:identity,
8784 matrix:F6(matrix),
8885 rotation:rotation,
89− translation:F2(translation),
9086 multiply:F2(multiply)
9187 /*
9288 transform:F7(transform),
libraries/Transform2D.elm+19−1
@@ -46,8 +46,26 @@ Given an angle t, it creates a counterclockwise rotation matrix:
4646rotation : Float -> Transform2D
4747rotation = Native.Transform2D.rotation
4848
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+-}
4957translation : 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
5169
5270{-| Creates a transformation for horizontal scaling -}
5371scaleX : Float -> Transform2D