]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4634: Simplify coord-rotate
authorDavid Kastrup <dak@gnu.org>
Fri, 9 Oct 2015 14:17:49 +0000 (16:17 +0200)
committerDavid Kastrup <dak@gnu.org>
Sat, 17 Oct 2015 17:29:07 +0000 (19:29 +0200)
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.

scm/lily-library.scm

index c5bf8cc59de12066e1f4bbf7e6aa88e321ef883e..0bfce9eb0c8a748099b3af053cf29d822de8a4b6 100644 (file)
@@ -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