]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/lily-library.scm
Doc: update translation-status
[lilypond.git] / scm / lily-library.scm
index d413aceca5a3fb3dc670aec491f991a1b4355486..574b85437eb251b12c02e6e3f24f6bdbecd3173e 100644 (file)
@@ -707,20 +707,30 @@ right (@var{dir}=+1)."
 (define-public (coord-scale coordinate amount)
   (coord-operation * amount coordinate))
 
-(define-public (coord-rotate coordinate degrees-in-radians)
-  (let*
-      ((coordinate
-        (cons
-         (exact->inexact (coord-x coordinate))
-         (exact->inexact (coord-y coordinate))))
-       (radius
-        (sqrt
-         (+ (* (coord-x coordinate) (coord-x coordinate))
-            (* (coord-y coordinate) (coord-y coordinate)))))
-       (angle (angle-0-2pi (atan (coord-y coordinate) (coord-x coordinate)))))
-    (cons
-     (* radius (cos (+ angle degrees-in-radians)))
-     (* radius (sin (+ angle degrees-in-radians))))))
+(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
+       )))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; trig
@@ -735,11 +745,11 @@ right (@var{dir}=+1)."
 
 (define-public (cyclic-base-value value cycle)
   "Take @var{value} and modulo-maps it between 0 and base @var{cycle}."
-  (if (< value 0)
-      (cyclic-base-value (+ value cycle) cycle)
-      (if (>= value cycle)
-          (cyclic-base-value (- value cycle) cycle)
-          value)))
+  (cond ((< value 0)
+         (cyclic-base-value (+ value cycle) cycle))
+        ((>= value cycle)
+         (cyclic-base-value (- value cycle) cycle))
+        (else value)))
 
 (define-public (angle-0-2pi angle)
   "Take @var{angle} (in radians) and maps it between 0 and 2pi."
@@ -786,6 +796,12 @@ as rectangular coordinates @ode{(x-length . y-length)}."
 (define-public (string-startswith s prefix)
   (equal? prefix (substring s 0 (min (string-length s) (string-length prefix)))))
 
+(define-public (remove-whitespace strg)
+"Remove characters satisfying @code{char-whitespace?} from string @var{strg}"
+  (string-delete
+    strg
+    char-whitespace?))
+
 (define-public (string-encode-integer i)
   (cond
    ((= i  0) "o")
@@ -1022,3 +1038,10 @@ print a warning and set an optional @var{default}."
    (ly:format "~a:1" input-file-name)
    (_ "no \\version statement found, please add~afor future compatibility")
    (format #f "\n\n\\version ~s\n\n" (lilypond-version))))
+
+(define-public (output-module? module)
+  "Returns @code{#t} if @var{module} belongs to an output module
+usually carrying context definitions (@code{\\midi} or
+@code{\\layout})."
+  (or (module-ref module 'is-midi #f)
+      (module-ref module 'is-layout #f)))