Source file coord.ml

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
type ns = N | S;;
type ew = E | W;;
type lat = float * ns;;
type lng = float * ew;;

type t = lat * lng;;

let dm_to_d v = 
  let dgr = floor @@ v /. 100. in
  let min = (v -. (dgr *. 100.)) *. (1.0 /. 60.) in 
  dgr +. min
;;

let parse_lat v ns = (dm_to_d v, ns);;
let parse_lng v ew = (dm_to_d v, ew);;

let lat = fst;;
let lng = snd;;

let to_string c = 
  let nstos l = match l with 
  | N -> 'N'
  | S -> 'S'
  in let ewtos l = match l with 
  | E -> 'E'
  | W -> 'W'
  in
  Printf.sprintf "%f %c %f %c" (lat c |> fst) (lat c |> snd |> nstos) 
    (lng c |> fst) (lng c |> snd |> ewtos)
;;

let eq c c' = (to_string c) = (to_string c');;