(define-public (coord-scale coordinate amount)
(coord-operation * amount coordinate))
-(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)))))
+(define-public (coord-rotate coordinate angle-in-radians)
+ (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
(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."
(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