]> git.jsancho.org Git - dungeon-master.git/blob - modules/dungeon-master/geom.scm
Modules reorganization
[dungeon-master.git] / modules / dungeon-master / geom.scm
1 ;;; Dungeon Master --- RPG Adventure Generator
2 ;;; Copyright © 2019 Javier Sancho <jsf@jsancho.org>
3 ;;;
4 ;;; Dungeon Master is free software; you can redistribute it and/or modify it
5 ;;; under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation; either version 3 of the License, or
7 ;;; (at your option) any later version.
8 ;;;
9 ;;; Dungeon Master is distributed in the hope that it will be useful, but
10 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 ;;; General Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with Dungeon Master. If not, see <http://www.gnu.org/licenses/>.
16
17
18 (define-module (dungeon-master geom)
19   #:use-module (dungeon-master geom point)
20   #:export (angle-sign))
21
22
23 (define (angle-sign center a b)
24   "Return the sign of (- (atan (- a center))
25                          (atan (- b center)))"
26   (let ((x1 (- (point-x a) (point-x center)))
27         (y1 (- (point-y a) (point-y center)))
28         (x2 (- (point-x b) (point-x center)))
29         (y2 (- (point-y b) (point-y center))))
30     (cond ((and (>= x1 0) (< x2 0))
31              1)
32           ((and (>= x2 0) (< x1 0))
33              -1)
34           ((and (= x1 0) (= x2 0))
35            (if (> y2 y1) 1 -1))
36           (else
37            (if (> (- (* x2 y1) (* x1 y2)) 0) 1 -1)))))