ttn pushed a commit to branch ttn-xpm in repository elpa. commit fa7a06990f0d0c3159780b812e392b04d660a553 Author: Thien-Thi Nguyen <t...@gnu.org> Date: Tue May 13 12:40:44 2014 +0200
add xpm-m2z-circle.el --- packages/xpm/xpm-m2z-circle.el | 79 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 79 insertions(+), 0 deletions(-) diff --git a/packages/xpm/xpm-m2z-circle.el b/packages/xpm/xpm-m2z-circle.el new file mode 100644 index 0000000..8a744bc --- /dev/null +++ b/packages/xpm/xpm-m2z-circle.el @@ -0,0 +1,79 @@ +;;; xpm-m2z-circle.el --- (% diameter 2) => 0 -*- lexical-binding: t -*- + +;; Copyright (C) 2014 Free Software Foundation, Inc. + +;; Author: Thien-Thi Nguyen <t...@gnu.org> +;; Version: -1 + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Although artist.el is wonderful, it doesn't (yet) do subpixel-centered +;; circles (or ellipses). This means that circles rendered by artist.el +;; always have an "outer diameter" modulo 2 of 1, because the origin is +;; *on* a pixel (i.e., coordinate, i.e., intersection of row and column). +;; That's a bummer when you're trying to generate circles with outer +;; diameter modulo 2 of 0 (hereby dubbed "m2z"). +;; +;; This file adds provides func `xpm-m2z-circle' to locally rectify the +;; current situation, with the hope that eventually a generalization can +;; be worked back into artist.el, perhaps as a subpixel-center minor mode +;; of some sort. + +;;; Code: + +(require 'artist) +(require 'cl-lib) + +;;;###autoload +(defun xpm-m2z-circle (cx cy radius) ; => ((X . Y) ...) + "Return coords for a circle with center (CX,CY) and RADIUS. +RADIUS must be integer and both CX and CY must be non-integer, +preferably precisely half-way between integers, e.g., 13/2 => 6.5. +The returned coordinates are unique but unordered." + (assert (not (integerp cx))) + (assert (not (integerp cy))) + (assert (integerp radius)) + (when (< 0 radius) + (cl-flet* + ((offset (coord idx) + (- (aref coord idx) 0.5)) + (normal (coord) + ;; flip axes: artist (ROW,COL) to xpm (X,Y) + (cons + (offset coord 1) ; 1: COL -> car: X + (offset coord 0))) ; 0: ROW -> cdr: Y + (placed (origin scale n) + (truncate (+ origin (* scale n)))) + (orient (coords quadrant) + (loop with (sx . sy) = quadrant + for (x . y) in coords + collect (cons (placed cx sx x) + (placed cy sy y))))) + (delete-dups + (loop with coords = (mapcar + #'normal + (artist-ellipse-generate-quadrant + radius radius)) + for quadrant ; these are in order: I-IV + in '(( 1 . 1) ; todo: "manually" remove single + (-1 . 1) ; (border point) overlaps; + (-1 . -1) ; zonk ‘delete-dups’ + ( 1 . -1)) + append (orient coords quadrant)))))) + +(provide 'xpm-m2z-circle) + +;;; xpm-m2z-circle.el ends here