diff options
author | David Kastrup <dak@gnu.org> | 2016-08-30 19:40:06 +0200 |
---|---|---|
committer | David Kastrup <dak@gnu.org> | 2016-09-19 23:25:11 +0200 |
commit | 75aa9281227dafb4b2c6e2f39b3fe5ed532e7007 (patch) | |
tree | 65285980fb0775363b8acea5783278bc878bd3ec /scm | |
parent | 807be335ea671790730a483938272e74eb012495 (diff) |
Issue 4968/1: Add coord-rotated function
Uses it for implementing coord-rotate.
Diffstat (limited to 'scm')
-rw-r--r-- | scm/lily-library.scm | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/scm/lily-library.scm b/scm/lily-library.scm index bbbe3cc53a..214c095cf2 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -708,29 +708,15 @@ right (@var{dir}=+1)." (coord-operation * amount coordinate)) (define-public (coord-rotate coordinate angle-in-radians) - ;; getting around (sin PI) not being exactly zero by switching to cos at - ;; appropiate angles and/or taking the negative value (vice versa for cos) - (let* ((quadrant (inexact->exact (round (/ angle-in-radians (/ PI 2))))) - (moved-angle (- angle-in-radians (* quadrant (/ PI 2)))) - (s (sin moved-angle)) - (c (cos moved-angle)) - (x (coord-x coordinate)) - (y (coord-y coordinate))) - (case (modulo quadrant 4) - ((0) ;; -45 .. 45 - (cons (- (* c x) (* s y)) - (+ (* s x) (* c y)))) - ((1) ;; 45 .. 135 - (cons (- (* (- s) x) (* c y)) - (+ (* c x) (* (- s) y)))) - ((2) ;; 135 .. 225 - (cons (- (* (- c) x) (* (- s) y)) - (+ (* (- s) x) (* (- c) y)))) - ((3) ;; 225 .. 315 - (cons (- (* s x) (* (- c) y)) - (+ (* (- c) x) (* s y)))) - ;; for other angles (modulo quadrant 4) returns one of the above cases - ))) + (coord-rotated coordinate (/ angle-in-radians PI-OVER-180))) + +(define-public (coord-rotated coordinate direction) + ;; Same, in degrees or with a given direction + (let ((dir (ly:directed direction))) + (cons (- (* (car dir) (car coordinate)) + (* (cdr dir) (cdr coordinate))) + (+ (* (car dir) (cdr coordinate)) + (* (cdr dir) (car coordinate)))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; trig |