001 (ns walkmap.geometry
002 (:require [clojure.math.combinatorics :as combo]
003 [clojure.math.numeric-tower :as m]))
004
005 (defn =ish
006 "True if numbers `n1`, `n2` are roughly equal; that is to say, equal to
007 within `tolerance` (defaults to one part in a million)."
008 ([n1 n2]
009 (if (and (number? n1) (number? n2))
010 (let [m (m/abs (min n1 n2))
011 t (if (zero? m) 0.000001 (* 0.000001 m))]
012 (=ish n1 n2 t))
013 (= n1 n2)))
014 ([n1 n2 tolerance]
015 (if (and (number? n1) (number? n2))
016 (< (m/abs (- n1 n2)) tolerance)
017 (= n1 n2))))