Function: image--rotate-map

image--rotate-map is a byte-compiled function defined in image.el.gz.

Signature

(image--rotate-map MAP ROTATION SIZE)

Documentation

Rotate MAP according to ROTATION and SIZE.

ROTATION must be a non-zero multiple of 90. Destructively modifies and returns MAP.

Source Code

;; Defined in /usr/src/emacs/lisp/image.el.gz
(defun image--rotate-map (map rotation size)
  "Rotate MAP according to ROTATION and SIZE.
ROTATION must be a non-zero multiple of 90.
Destructively modifies and returns MAP."
  (setq rotation (mod rotation 360))
  (pcase-dolist (`(,`(,type . ,coords) ,_id ,_plist) map)
    (pcase-exhaustive type
      ('rect
       (let ( x0 y0  ; New upper left corner
              x1 y1) ; New bottom right corner
         (pcase rotation ; Set new corners to...
           (90 ; ...old bottom left and upper right
            (setq x0 (caar coords) y0 (cddr coords)
                  x1 (cadr coords) y1 (cdar coords)))
           (180 ; ...old bottom right and upper left
            (setq x0 (cadr coords) y0 (cddr coords)
                  x1 (caar coords) y1 (cdar coords)))
           (270 ; ...old upper right and bottom left
            (setq x0 (cadr coords) y0 (cdar coords)
                  x1 (caar coords) y1 (cddr coords))))
         (setcar coords (image--rotate-coord x0 y0 rotation size))
         (setcdr coords (image--rotate-coord x1 y1 rotation size))))
      ('circle
       (setcar coords (image--rotate-coord
                       (caar coords) (cdar coords) rotation size)))
      ('poly
       (dotimes (i (length coords))
         (when (= 0 (% i 2))
           (pcase-let ((`(,x . ,y)
                        (image--rotate-coord
                         (aref coords i) (aref coords (1+ i)) rotation size)))
             (aset coords i x)
             (aset coords (1+ i) y)))))))
  map)