1 (in-package #:clnl-nvm)
3 (defun wrap (pos min max)
5 ((>= pos max) (+ min (mod (- pos max) (- max min))))
8 ((res (- max (mod (- min pos) (- max min)))))
9 (if (< res max) res min))) ; If d is infinitesimal, may return max, which would be bad :(
12 (defgeneric wrap-x (topology x))
13 (defgeneric wrap-y (topology y))
15 ; Torus implementations
16 (defmethod wrap-x ((topology (eql :torus)) x)
17 (wrap x (- (min-pxcor) 0.5d0) (+ (max-pxcor) 0.5d0)))
19 (defmethod wrap-y ((topology (eql :torus)) y)
20 (wrap y (- (min-pycor) 0.5d0) (+ (max-pycor) 0.5d0)))