Add scale and documentation for translation
Express translate in terms of the native matrix method instead.
This commit is contained in:
parent
a654bfa96b
commit
3a02543b26
2 changed files with 19 additions and 5 deletions
|
@ -37,9 +37,6 @@ Elm.Native.Transform2D.make = function(elm) {
|
||||||
var s = Math.sin(t);
|
var s = Math.sin(t);
|
||||||
return new A([c, -s, 0, s, c, 0]);
|
return new A([c, -s, 0, s, c, 0]);
|
||||||
}
|
}
|
||||||
function translation(x,y) {
|
|
||||||
return new A([1,0,x,0,1,y]);
|
|
||||||
}
|
|
||||||
function rotate(t,m) {
|
function rotate(t,m) {
|
||||||
var c = Math.cos(t);
|
var c = Math.cos(t);
|
||||||
var s = Math.sin(t);
|
var s = Math.sin(t);
|
||||||
|
@ -86,7 +83,6 @@ Elm.Native.Transform2D.make = function(elm) {
|
||||||
identity:identity,
|
identity:identity,
|
||||||
matrix:F6(matrix),
|
matrix:F6(matrix),
|
||||||
rotation:rotation,
|
rotation:rotation,
|
||||||
translation:F2(translation),
|
|
||||||
multiply:F2(multiply)
|
multiply:F2(multiply)
|
||||||
/*
|
/*
|
||||||
transform:F7(transform),
|
transform:F7(transform),
|
||||||
|
|
|
@ -46,8 +46,26 @@ Given an angle t, it creates a counterclockwise rotation matrix:
|
||||||
rotation : Float -> Transform2D
|
rotation : Float -> Transform2D
|
||||||
rotation = Native.Transform2D.rotation
|
rotation = Native.Transform2D.rotation
|
||||||
|
|
||||||
|
{-| Creates a transformation matrix for translation:
|
||||||
|
|
||||||
|
translation x y
|
||||||
|
|
||||||
|
/ 1 0 x \
|
||||||
|
| 0 1 y |
|
||||||
|
\ 0 0 1 /
|
||||||
|
-}
|
||||||
translation : Float -> Float -> Transform2D
|
translation : Float -> Float -> Transform2D
|
||||||
translation = Native.Transform2D.translation
|
translation x y = matrix 1 0 0 1 x y
|
||||||
|
|
||||||
|
{-| Creates a transformation matrix for scaling by a all directions:
|
||||||
|
|
||||||
|
scale a
|
||||||
|
|
||||||
|
/ a 0 \
|
||||||
|
\ 0 a /
|
||||||
|
-}
|
||||||
|
scale : Float -> Transform2D
|
||||||
|
scale a = matrix a 0 0 a 0 0
|
||||||
|
|
||||||
{-| Creates a transformation for horizontal scaling -}
|
{-| Creates a transformation for horizontal scaling -}
|
||||||
scaleX : Float -> Transform2D
|
scaleX : Float -> Transform2D
|
||||||
|
|
Loading…
Reference in a new issue