Skip to content

Instantly share code, notes, and snippets.

@quoll
Created January 26, 2018 04:12
Show Gist options
  • Save quoll/f61cbe8bcbe8e4104bb9d32b2f04f2c6 to your computer and use it in GitHub Desktop.
Save quoll/f61cbe8bcbe8e4104bb9d32b2f04f2c6 to your computer and use it in GitHub Desktop.
(defn square [x] (* x x))
(defn offset [x y]
(let [ms (max (Math/abs x) (Math/abs y))
sq (dec (* 2 ms))
base (square sq)
side (inc sq)
hside (/ side 2)]
(cond
(and (= x ms) (< y ms)) (- (+ base hside) y)
(= y (- ms)) (- (+ base side hside) x)
(= x (- ms)) (+ base (* 2 side) hside y)
(= y ms) (+ base (* 3 side) hside x))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment