Function: artist-rect-corners-squarify
artist-rect-corners-squarify is a byte-compiled function defined in
artist.el.gz.
Signature
(artist-rect-corners-squarify X1 Y1 X2 Y2)
Documentation
Compute square corners from rectangle corners at X1, Y1 and X2, Y2.
The square's first corner will be X1, Y1. The position of the second corner depends on which of X2 and Y2 is most far away from X1, Y1.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/artist.el.gz
(defun artist-rect-corners-squarify (x1 y1 x2 y2)
"Compute square corners from rectangle corners at X1, Y1 and X2, Y2.
The square's first corner will be X1, Y1. The position of the second
corner depends on which of X2 and Y2 is most far away from X1, Y1."
(let* ((delta-x (- x2 x1))
(delta-y (- y2 y1))
(delta-x-sign (if (< delta-x 0) -1 1))
(delta-y-sign (if (< delta-y 0) -1 1))
(new-x2) ; set below
(new-y2)) ; set below
;; Check which of x2 and y2 is most distant
;; take care to the aspect ratio
(if (> (abs delta-x) (abs delta-y))
;; *** x2 more distant than y2 (with care taken to aspect ratio)
(progn
(setq new-x2 x2)
(setq new-y2 (+ y1 (round (/ (* (abs delta-x) delta-y-sign)
artist-aspect-ratio)))))
;; *** y2 more distant than x2 (with care taken to aspect ratio)
(progn
(setq new-x2 (round (+ x1 (* (* (abs delta-y) delta-x-sign)
artist-aspect-ratio))))
(setq new-y2 y2)))
;; Return this
(list x1 y1 new-x2 new-y2)))