X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Flily-library.scm;h=05875b2da2ec5915d7d4c99ae5c89489e9a13986;hb=2bbacb364aa29041af9cbbbd32cfad2e8e387cb3;hp=574b85437eb251b12c02e6e3f24f6bdbecd3173e;hpb=cf11a6cd3300b5ed7e6cbe8c461adebc3bab1618;p=lilypond.git diff --git a/scm/lily-library.scm b/scm/lily-library.scm index 574b85437e..05875b2da2 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 @@ -776,14 +762,8 @@ right (@var{dir}=+1)." (define-public (polar->rectangular radius angle-in-degrees) "Return polar coordinates (@var{radius}, @var{angle-in-degrees}) -as rectangular coordinates @ode{(x-length . y-length)}." - - (let ((complex (make-polar - radius - (degrees->radians angle-in-degrees)))) - (cons - (real-part complex) - (imag-part complex)))) +as rectangular coordinates @code{(x-length . y-length)}." + (ly:directed angle-in-degrees radius)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; string @@ -798,9 +778,9 @@ as rectangular coordinates @ode{(x-length . y-length)}." (define-public (remove-whitespace strg) "Remove characters satisfying @code{char-whitespace?} from string @var{strg}" - (string-delete - strg - char-whitespace?)) + (if (guile-v2) + (string-delete char-whitespace? strg) + (string-delete strg char-whitespace?))) (define-public (string-encode-integer i) (cond @@ -908,6 +888,29 @@ and will be applied to NUM." (fancy-format #f (car custom-format) num)) (else (fancy-format #f "~(~@r~)" num)))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; lilypond version + +(define (lexicographic-list-compare? op a b) + "Lexicographically compare two lists @var{a} and @var{b} using + the operator @var{op}. The types of the list elements have to + be comparable with @var{op}. If the lists are of different length + the trailing elements of the longer list are ignored." + (let* ((ca (car a)) + (iseql (op ca ca))) + (let loop ((ca ca) (cb (car b)) (a (cdr a)) (b (cdr b))) + (let ((axb (op ca cb))) + (if (and (pair? a) (pair? b) + (eq? axb iseql (op cb ca))) + (loop (car a) (car b) (cdr a) (cdr b)) + axb))))) + +(define (ly:version? op ver) + "Using the operator @var{op} compare the currently executed LilyPond + version with a given version @var{ver} which is passed as a list of + numbers." + (lexicographic-list-compare? op (ly:version) ver)) + ;;;;;;;;;;;;;;;; ;; other