emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/pacmacs c571f5874c 272/472: Extract wall bits normalizatio


From: ELPA Syncer
Subject: [nongnu] elpa/pacmacs c571f5874c 272/472: Extract wall bits normalization
Date: Thu, 6 Jan 2022 21:59:31 -0500 (EST)

branch: elpa/pacmacs
commit c571f5874caa71c90ed1a7438c8c4cab18add27e
Author: rexim <reximkut@gmail.com>
Commit: rexim <reximkut@gmail.com>

    Extract wall bits normalization
---
 pacmacs-image.el           | 34 ++++++++++++++++------------------
 test/pacmacs-image-test.el |  8 ++++++++
 2 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/pacmacs-image.el b/pacmacs-image.el
index 323946fcd0..c0e904276b 100644
--- a/pacmacs-image.el
+++ b/pacmacs-image.el
@@ -82,32 +82,30 @@
     ",\n")
    "\n};"))
 
-(defun pacmacs--create-wall-tile (width height
+(defun pacmacs--normalize-wall-bits (wall-bits)
+  (-let (((bottom right top left left-upper right-upper left-bottom 
right-bottom)
+          wall-bits))
+    (list bottom right top left
+          (and left-upper   (not left)  (not top))
+          (and right-upper  (not right) (not top))
+          (and left-bottom  (not left)  (not bottom))
+          (and right-bottom (not right) (not bottom)))))
 
+(defun pacmacs--create-wall-tile (width height
                                   bottom right
                                   top left
                                   left-upper right-upper
                                   left-bottom right-bottom)
-  (let ((cache-index
-         (pacmacs--bit-list-to-integer
-          (list bottom right top left
-                (and left-upper
-                     (not left)
-                     (not top))
-                (and right-upper
-                     (not right)
-                     (not top))
-                (and left-bottom
-                     (not left)
-                     (not bottom))
-                (and right-bottom
-                     (not right)
-                     (not bottom))))))
+  (let* ((wall-bits (list bottom right top left
+                          left-upper right-upper
+                          left-bottom right-bottom))
+         (cache-index (-> wall-bits
+                          (pacmacs--normalize-wall-bits)
+                          (pacmacs--bit-list-to-integer))))
     (-if-let (cached-tile (gethash cache-index pacmacs--wall-blocks))
         cached-tile
       (puthash cache-index
-               (let ((wall-block (make-vector
-                                  width nil))
+               (let ((wall-block (make-vector width nil))
                      (weight 3))
 
                  (dotimes (i width)
diff --git a/test/pacmacs-image-test.el b/test/pacmacs-image-test.el
index a7bcd9d3a3..e96b7ed392 100644
--- a/test/pacmacs-image-test.el
+++ b/test/pacmacs-image-test.el
@@ -86,3 +86,11 @@
                    (pacmacs--bits-to-xpm [[t t]
                                           [nil nil]]
                                          2 2))))
+
+(ert-deftest pacmacs--normalize-wall-bits-test ()
+  (should (equal '(nil nil nil nil t nil t nil)
+                 (pacmacs--normalize-wall-bits
+                  '(nil nil nil nil t nil t nil))))
+  (should (equal '(t t t t nil nil nil nil)
+                 (pacmacs--normalize-wall-bits
+                  '(t t t t nil t nil t)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]