X-Git-Url: https://git.jsancho.org/?p=dungeon-master.git;a=blobdiff_plain;f=dungeon-master%2Fgeom.scm;fp=dungeon-master%2Fgeom.scm;h=96cc3789717e3f638cbb91c81031a7a8d1ebeb5f;hp=0000000000000000000000000000000000000000;hb=09c4aef3b2dde4e8fdf0a4b673b36c1ddbc84b6e;hpb=35202c3698d8858b4d81347253e23fe6d4a01bef diff --git a/dungeon-master/geom.scm b/dungeon-master/geom.scm new file mode 100644 index 0000000..96cc378 --- /dev/null +++ b/dungeon-master/geom.scm @@ -0,0 +1,20 @@ +(define-module (dungeon-master geom) + #:use-module (dungeon-master geom point) + #:export (angle-sign)) + + +(define (angle-sign center a b) + "Return the sign of (- (atan (- a center)) + (atan (- b center)))" + (let ((x1 (- (point-x a) (point-x center))) + (y1 (- (point-y a) (point-y center))) + (x2 (- (point-x b) (point-x center))) + (y2 (- (point-y b) (point-y center)))) + (cond ((and (>= x1 0) (< x2 0)) + 1) + ((and (>= x2 0) (< x1 0)) + -1) + ((and (= x1 0) (= x2 0)) + (if (> y2 y1) 1 -1)) + (else + (if (> (- (* x2 y1) (* x1 y2)) 0) 1 -1)))))