[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 03/07: add xpm-m2z-circle.el
[elpa] 03/07: add xpm-m2z-circle.el
Tue, 13 May 2014 10:40:05 +0000
ttn pushed a commit to branch ttn-xpm
in repository elpa.
Author: Thien-Thi Nguyen <address@hidden>
Date: Tue May 13 12:40:44 2014 +0200
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
@@ -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 <address@hidden>
+;; 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/>.
+;; 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.
+(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)
+ ((offset (coord idx)
+ (- (aref coord idx) 0.5))
+ (normal (coord)
+ ;; flip axes: artist (ROW,COL) to xpm (X,Y)
+ (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)))))
+ (loop with coords = (mapcar
+ 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))))))
+;;; xpm-m2z-circle.el ends here
- [elpa] branch ttn-xpm created (now 3c057a7), Thien-Thi Nguyen, 2014/05/13
- [elpa] 03/07: add xpm-m2z-circle.el,
Thien-Thi Nguyen <=
- [elpa] 05/07: add xpm-ui.el, Thien-Thi Nguyen, 2014/05/13
- [elpa] 04/07: add xpm-palette.el, Thien-Thi Nguyen, 2014/05/13
- [elpa] 06/07: add xpm-compose.el, Thien-Thi Nguyen, 2014/05/13
- [elpa] 01/07: [maint] add NEWS; nfc, Thien-Thi Nguyen, 2014/05/13
- [elpa] 02/07: add xpm.el, Thien-Thi Nguyen, 2014/05/13
- [elpa] 07/07: [maint] add HACKING; nfc, Thien-Thi Nguyen, 2014/05/13