From c4ae3b0ee4bd338995cfecf34e0aeb49f05fa70e Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Tue, 2 Sep 2014 21:35:58 +0200 Subject: Initial commit --- src/Vec2.elm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/Vec2.elm (limited to 'src/Vec2.elm') diff --git a/src/Vec2.elm b/src/Vec2.elm new file mode 100644 index 0000000..a77b372 --- /dev/null +++ b/src/Vec2.elm @@ -0,0 +1,36 @@ +module Vec2 where + +type Vec2 = + { x : Float + , y : Float + } + +add : Vec2 -> Vec2 -> Vec2 +add v1 v2 = + { x = v1.x + v2.x + , y = v1.y + v2.y + } + +sub : Vec2 -> Vec2 -> Vec2 +sub v1 v2 = + { x = v1.x - v2.x + , y = v1.y - v2.y + } + +mul : Float -> Vec2 -> Vec2 +mul m v = + { x = m * v.x + , y = m * v.y + } + +div : Vec2 -> Float -> Vec2 +div v d = + { x = v.x / d + , y = v.y / d + } + +isNull : Vec2 -> Bool +isNull v = (v.x == 0) && (v.y == 0) + +originVec : Vec2 +originVec = { x = 0, y = 0 } -- cgit v1.2.3