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/Geometry.elm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/Geometry.elm (limited to 'src/Geometry.elm') diff --git a/src/Geometry.elm b/src/Geometry.elm new file mode 100644 index 0000000..73e8d1f --- /dev/null +++ b/src/Geometry.elm @@ -0,0 +1,23 @@ +module Geometry where + +import Vec2 (..) +import 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