Move from github, collapse gltk and strictmath, add candle
[clnl] / src / main / clnl / nvm / topology.lisp
1 (in-package #:clnl-nvm)
2
3 (defun wrap (pos min max)
4  (cond
5   ((>= pos max) (+ min (mod (- pos max) (- max min))))
6   ((< pos min)
7    (let
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 :(
10   (t pos)))
11
12 (defgeneric wrap-x (topology x))
13 (defgeneric wrap-y (topology y))
14
15 ; Torus implementations
16 (defmethod wrap-x ((topology (eql :torus)) x)
17  (wrap x (- (min-pxcor) 0.5d0) (+ (max-pxcor) 0.5d0)))
18
19 (defmethod wrap-y ((topology (eql :torus)) y)
20  (wrap y (- (min-pycor) 0.5d0) (+ (max-pycor) 0.5d0)))