From: David Kastrup Date: Fri, 9 Oct 2015 14:17:49 +0000 (+0200) Subject: Issue 4634: Simplify coord-rotate X-Git-Tag: release/2.19.29-1~5 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e860e146ccecf07d42aa53de885916931950245e;p=lilypond.git Issue 4634: Simplify coord-rotate This does not fix the problem that (sin PI) is not really zero because of the MPU working with higher precision than PI is specified, but at least it makes the code nicer to read and modify. --- diff --git a/scm/lily-library.scm b/scm/lily-library.scm index c5bf8cc59d..0bfce9eb0c 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -707,20 +707,13 @@ 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) + (let ((c (cos angle)) + (s (sin angle)) + (x (coord-x coordinate)) + (y (coord-y coordinate))) + (cons (- (* c x) (* s y)) + (+ (* s x) (* c y))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; trig