blob: c4a4539dd9517bf032cd0ce3e71301f75ac7d5e2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
module Utils.Geometry exposing
( polarToCartesian
, distance
, inBoard
)
import Model.Vec2 exposing (..)
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 : Vec2 -> Float -> Vec2 -> Vec2
inBoard boardSize 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
}
|