From 17a58e0c4c67f27d87635bf1b2ca50fb11795ad3 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sat, 7 Mar 2015 15:12:02 +0100 Subject: Organizing source code with subdirectories --- src/Utils/Geometry.elm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/Utils/Geometry.elm (limited to 'src/Utils/Geometry.elm') diff --git a/src/Utils/Geometry.elm b/src/Utils/Geometry.elm new file mode 100644 index 0000000..085026f --- /dev/null +++ b/src/Utils/Geometry.elm @@ -0,0 +1,27 @@ +module Utils.Geometry + ( polarToCartesian + , distance + , inBoard + ) where + +import Model.Vec2 (..) +import Model.Board (boardSize) + +polarToCartesian : Float -> Float -> Vec2 +polarToCartesian angle dist = + { x = dist * (cos angle) + , y = dist * (sin angle) + } + +distance : Vec2 -> Vec2 -> Float +distance v1 v2 = sqrt((v2.x - v1.x)^2 + (v2.y - v1.y)^2) + +inBoard : Float -> Vec2 -> Vec2 +inBoard size pos = + let leftX = -boardSize.x / 2 + size + rightX = boardSize.x / 2 - size + bottomY = -boardSize.y / 2 + size + topY = boardSize.y / 2 - size + in { x = clamp leftX rightX pos.x + , y = clamp bottomY topY pos.y + } -- cgit v1.2.3