I have a vector of points in 2D space such as:
[[0 0] [1 1] [2 2]]
And need to compute the distance between some point and each point in the vector to determine which point in the vector is closest to the point I'm querying. I need to know both the distance and the closest point, so I want a vector of hashes like this:
[{:point [0 0] :dist 2.7} {:point [1 1] :dist 3.5} {:point [2 2] :dist 4.3}]
How can I transform the former into the latter? I tried something like this:
(defn closest-point [point all-points]
(map #({:point % :dist (distance point %)}) all-points))
But I get an error:
(user=> ArityException Wrong number of args (0) passed to: PersistentArrayMap clojure.lang.AFn.throwArity (AFn.java:437)