(defn dist
"Shortest distance between x,y and x2,y2 in toroidal space of dimensions w,h.
Input coordinates should be in range (0,0)-(w,h). For instance, will give
1.414... if x,y = (0,0) and x2,y2 = (w-1,h-1), as these are diagonally
adjacent."
([x y x2 y2 w h]
(let [x2s [(- x2 w) x2 (+ x2 w)]
y2s [(- y2 h) y2 (+ y2 h)]
dist-sqrs (for [x2 x2s y2 y2s]
(let [dx (- x2 x)
dy (- y2 y)]
(+ (* dx dx) (* dy dy))))]
(Math/sqrt (double (apply min dist-sqrs))))))
#'user/dist
(defn dist2
"Shortest distance between x,y and x2,y2 in toroidal space of dimensions w,h.
Input coordinates should be in range (0,0)-(w,h). For instance, will give
1.414... if x,y = (0,0) and x2,y2 = (w-1,h-1), as these are diagonally
adjacent."
(^double [x y x2 y2 w h] ; Sole difference is the ^double added here.
(let [x2s [(- x2 w) x2 (+ x2 w)]
y2s [(- y2 h) y2 (+ y2 h)]
dist-sqrs (for [x2 x2s y2 y2s]
(let [dx (- x2 x)
dy (- y2 y)]
(+ (* dx dx) (* dy dy))))]
(Math/sqrt (double (apply min dist-sqrs))))))
#<CompilerException java.lang.IllegalArgumentException: fns taking
primitives support only 4 or fewer args,
But the function isn't *taking* primitives. It's only *returning* a
primitive, after taking Objects. So it obviously shouldn't produce
this error.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en