The pre-condition
- is inoperative
- corrected, is inconsistent with the data shape the function requires.
Let's cut down the function so that it destructures its arguments:
(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)))]
[delta-latitude delta-longitude]))
(I've dispensed with the harmless but redundant parentheses wrapping the single arity).
The pre-condition is
{:pre [every? (every-pred map? #(contains? % :lgt) #(contains? % :ltd)) [source to]]}
This evaluates, in turn,
every?
(every-pred map? #(contains? % :lgt) #(contains? % :ltd))
[source to]
... all of which are logically true - two functions and a vector.
You need to wrap the whole expression in ( ... ) to make it evaluate:
{:pre [(every? (every-pred map? #(contains? % :lgt) #(contains? % :ltd)) [source to])]}
Before we do that, let's look at the data shape the function requires. For example,
(calculate-distance {:source/ltd 0, :source/lgt 0}
{:to/ltd 0, :to/lgt 0})
=> [0.0 0.0]
The expressions in the let use qualified keywords: :source/ltd ... .
This is bad. We want both points specified with the same shape - the more so since they are symmetrical in effect: the distance from here to there is the same as the distance from there to here.
Let's go with the shape that the (corrected) pre-condition requires:
(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 (- (:ltd source) (:ltd to)))
delta-longitude (Math/toRadians (- (:lgt source) (:lgt to)))]
[delta-latitude delta-longitude]))
Now
(calculate-distance {:source/ltd 0, :source/lgt 0}
{:to/ltd 0, :to/lgt 0})
AssertionError ...
but
(calculate-distance {:ltd 0, :lgt 0}
{:ltd 0, :lgt 0})
=> [0.0 0.0]
So far, so good.
Let's do a couple of quick examples:
(calculate-distance {:ltd 0, :lgt 0}
{:ltd 0, :lgt 0})
=> 0.0
Good.
(calculate-distance {:ltd 0, :lgt 0}
{:ltd 0, :lgt 90})
=> 1.0010363727626067E7
The distance from the North pole to the equator along the Greenwich meridian is about 10 million metres or 10 thousand kilometres - correct.
As for the calculation, I've nothing to add to the other answers. Though I would prefer in a JVM environment to do as you do and call the Mathfunctions directly.