Function: image--rotate-coord
image--rotate-coord is a byte-compiled function defined in
image.el.gz.
Signature
(image--rotate-coord X Y ANGLE SIZE)
Documentation
Rotate coordinates X and Y by ANGLE in image of SIZE.
ANGLE must be a multiple of 90 in [90 180 270]. Returns a cons cell of rounded coordinates (X1 Y1).
Source Code
;; Defined in /usr/src/emacs/lisp/image.el.gz
(defun image--rotate-coord (x y angle size)
"Rotate coordinates X and Y by ANGLE in image of SIZE.
ANGLE must be a multiple of 90 in [90 180 270]. Returns a cons cell of
rounded coordinates (X1 Y1)."
(pcase-let* ((radian (* (/ angle 180.0) float-pi))
(`(,width . ,height) size)
;; y is positive, but we are in the bottom-right quadrant
(y (- y))
;; Rotate clockwise
(x1 (+ (* (sin radian) y) (* (cos radian) x)))
(y1 (- (* (cos radian) y) (* (sin radian) x)))
;; Translate image back into bottom-right quadrant
(`(,x1 . ,y1)
(pcase (truncate (mod angle 360))
(90 ; Translate right by height
(cons (+ x1 height) y1))
(180 ; Translate right by width and down by height
(cons (+ x1 width) (- y1 height)))
(270 ; Translate down by width
(cons x1 (- y1 width)))))
;; Invert y1 to make both x1 and y1 positive
(y1 (- y1)))
(cons (round x1) (round y1))))