aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Vec2.elm
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-03-07 15:12:02 +0100
committerJoris Guyonvarch2015-03-07 15:12:02 +0100
commit17a58e0c4c67f27d87635bf1b2ca50fb11795ad3 (patch)
tree8de99cdf0b4021ca6db6920537e7d0fa250e90bc /src/Model/Vec2.elm
parent336816d2e8ab4afff1562123dfde61bf3a68e61c (diff)
Organizing source code with subdirectories
Diffstat (limited to 'src/Model/Vec2.elm')
-rw-r--r--src/Model/Vec2.elm55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/Model/Vec2.elm b/src/Model/Vec2.elm
new file mode 100644
index 0000000..85ff008
--- /dev/null
+++ b/src/Model/Vec2.elm
@@ -0,0 +1,55 @@
+module Model.Vec2
+ ( Vec2
+ , add
+ , sub
+ , mul
+ , div
+ , norm
+ , clockwiseRotate90
+ , isNull
+ , originVec
+ ) where
+
+type alias 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
+ }
+
+norm : Vec2 -> Float
+norm v = sqrt(v.x ^ 2 + v.y ^ 2)
+
+clockwiseRotate90 : Vec2 -> Vec2
+clockwiseRotate90 v =
+ { x = -v.y
+ , y = v.x
+ }
+
+isNull : Vec2 -> Bool
+isNull v = (v.x == 0) && (v.y == 0)
+
+originVec : Vec2
+originVec = { x = 0, y = 0 }