X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fgacela_misc.scm;h=6dd13b11a8acd7844c1943279b0c5f2aebc51ee1;hb=2dd62c9397803ff96e72f9e27f138b58273b5976;hp=c95abf5200e323d45465e89229d51e9fb7a29c9f;hpb=6a3d1ffb69036e6d4f1c239fd7d52f9bfc48d50c;p=gacela.git diff --git a/src/gacela_misc.scm b/src/gacela_misc.scm index c95abf5..6dd13b1 100644 --- a/src/gacela_misc.scm +++ b/src/gacela_misc.scm @@ -15,3 +15,56 @@ ;;; along with this program. If not, see . + +;;; Additional modules + +(use-modules (srfi srfi-1)) + + +;;; Constants + +(define *pi* (* (asin 1) 2)) + + +;;; Geometry + +(define (degrees-to-radians angle) + (/ (* angle *pi*) 180)) + +(define (radians-to-degrees angle) + (/ (* angle 180) *pi*)) + +(define (distance-between-points p1 p2) + (define (add-power-of-two p1 p2) + (cond ((null? p1) + 0) + (else + (+ (expt (- (car p1) (car p2)) 2) + (add-power-of-two (cdr p1) (cdr p2)))))) + + (cond ((not (= (length p1) (length p2))) + #f) + (else + (sqrt (add-power-of-two p1 p2))))) + + +;;; Functions + +(define (nearest-power-of-two n) + (define (power p n) + (cond ((> (* p 2) n) p) + (else (power (* p 2) n)))) + (power 1 n)) + +(define-macro (pushnew elem list) + `(cond ((not (find (lambda (e) (eq? e ,elem)) ,list)) + (set! ,list (cons ,elem ,list))))) + +(define (assoc-multiple-set! alist . pairs) + (define (amset! alist pairs) + (cond ((< (length pairs) 2) + alist) + (else + (assoc-set! alist (car pairs) (cadr pairs)) + (amset! alist (cddr pairs))))) + (amset! alist pairs))