I implemented the Haversine formulaHaversine formula to calculate the distance between two (latitude, longitude) coordinates.
I was wondering if it looks natural to Clojure programmers. What could be improved?
(ns br.com.reactive-poc.calc)
(def raio 6372.795477598)
(defn calculate-distance
"Calcula distância entre duas coordenadas geográficas"
([source to]
{:pre [every? (every-pred map? #(contains? % :lgt) #(contains? % :ltd)) [source to]]}
(let [delta-latitude (Math/toRadians (- (:source/ltd source) (:to/ltd to)))
delta-longitude (Math/toRadians (- (:source/lgt source) (:to/lgt to)))
]
(* (* raio (* 2 (Math/atan2 (Math/sqrt (+ (Math/pow (Math/sin (/ delta-latitude 2)) 2)
(* (Math/cos (Math/toRadians (:source/ltd source))) (Math/cos (Math/toRadians (:to/ltd to))) (Math/sin (/ delta-longitude 2)) (Math/sin (/ delta-longitude 2)))))
(Math/sqrt (- 1 (+ (Math/pow (Math/sin (/ delta-latitude 2)) 2)
(* (Math/cos (Math/toRadians (:source/ltd source))) (Math/cos (Math/toRadians (:to/ltd to)) ) (Math/sin (/ delta-longitude 2)) (Math/sin (/ delta-longitude 2))))))))) 1000)
)
)
)