]> git.jsancho.org Git - dungeon-master.git/blobdiff - dungeon-master/geom.scm
Make regions from the Delaunay triangulation
[dungeon-master.git] / dungeon-master / geom.scm
diff --git a/dungeon-master/geom.scm b/dungeon-master/geom.scm
new file mode 100644 (file)
index 0000000..96cc378
--- /dev/null
@@ -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)))))