;;; -*- lexical-binding: t -*- ;; ;; -------------------------------------------------------------------------- (require 'cl-lib) (cl-pushnew "." load-path :test #'string=) (require 'luki-lisp) ;; -------------------------------------------------------------------------- (-> 'bad-box) (-> 'bad-elem) ;; -------------------------------------------------------------------------- (cl-defmethod bad-transpose-pos ((e elem)) (~ (x y) e (cl-rotatef x y))) (cl-defmethod bad-transpose ((e elem) &optional inner) (when (or (@ e transposable) inner) (~ (data w h sub) e (let* ((data-lists (cl-loop with chunks = (seq-split data w) for c in chunks collect c))) (setf data (flatten-list (cl-loop for col-i below w collect (cl-loop for row in data-lists collect (elt row col-i)))))) (cl-rotatef w h) (when inner (bad-transpose-pos e)) (mapc (L (sub-e) (bad-transpose sub-e t)) sub)))) ;; -------------------------------------------------------------------------- (cl-defmethod bad-flip-x-pos ((e elem)) (~ (w-max w x min-x) e (setf x (+ (- w-max w x) min-x 1)))) (cl-defmethod bad-flip-y-pos ((e elem)) (~ (h-max h y min-y) e (bad-flip-x-pos e) (setf y (+ (- h-max h y) min-y 1)))) ;; -------------------------------------------------------------------------- (cl-defmethod bad-flip-x :before ((b box) &optional _) (bad-flip-img-x b)) (cl-defmethod bad-flip-x ((e elem) &optional inner) (~ (data w sub) e (setf data (string-to-list (string-join (cl-loop with chunks = (seq-split data w) for c in chunks collect (nreverse c))))) (when inner (bad-flip-x-pos e)) (mapc (L (sub-e) (bad-flip-x sub-e t)) sub))) ;; -------------------------------------------------------------------------- (cl-defmethod bad-flip-y :before ((b box) &optional _) (bad-flip-img-y b)) (cl-defmethod bad-flip-y ((e elem) &optional inner) (~ (data sub) e (setf data (nreverse data)) (bad-flip-x e) (when inner (bad-flip-x e) (bad-flip-y-pos e)) (mapc (L (sub-e) (bad-flip-y sub-e t)) sub))) ;; -------------------------------------------------------------------------- (cl-defmethod bad-rotate-reverse ((e elem) &optional n inner) (or n (setq n 1)) (bad-rotate e (- n) inner)) (cl-defmethod bad-rotate ((e elem) &optional n inner) (or n (setq n 1)) (when (< n 0) (setq n (* (abs n) 3))) (~ (sub movable) e (when movable (cl-loop repeat n do (unless inner (bad-transpose e) (bad-flip-x e)) (mapc (L (sub-e) (bad-rotate sub-e 3 t)) sub))))) ;; -------------------------------------------------------------------------- (<- 'bad-rotate)