-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateHelpers.elm
32 lines (26 loc) · 1.17 KB
/
UpdateHelpers.elm
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
27
28
29
30
31
32
module UpdateHelpers exposing (..)
import MapModel exposing (..)
import Mouse exposing (Position)
calculateNodeClickPosition : Model -> {x:Int,y:Int} -> {x:Int,y:Int}
calculateNodeClickPosition model mousePos =
let
fx = toFloat (mousePos.x + (divideByScale model model.panData.svgPos.x) ) / model.svgScale
fy = toFloat (mousePos.y + (divideByScale model model.panData.svgPos.y) ) / model.svgScale
in
{ x = round (fx - getOffSet model), y = round (fy - getOffSet model) }
calculatePanPosition : Model -> {x:Int,y:Int} -> {x:Int,y:Int}
calculatePanPosition model mousePos =
{x = round (toFloat (mousePos.x) / model.svgScale)
,y = round (toFloat (mousePos.y) / model.svgScale) }
divideByScale : Model -> Int -> Int
divideByScale model coord =
round (toFloat coord * model.svgScale)
getOffSet : Model -> Float
getOffSet model =
toFloat model.nodeSize / 2 * model.svgScale
getSvgPos : Model -> {x:Int,y:Int} -> {x:Int,y:Int}
getSvgPos model mousePos =
let
adjustedPos = calculatePanPosition model mousePos in
{ x = model.panData.svgPos.x - (adjustedPos.x - model.panData.panStart.x)
, y = model.panData.svgPos.y - (adjustedPos.y - model.panData.panStart.y) }