49f0ca1bece8

Poke
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Thu, 18 Aug 2016 18:14:12 +0000
parents d03941f38bca
children 9823fe1aea30
branches/tags (none)
files src/dijkstra-maps.lisp

Changes

--- a/src/dijkstra-maps.lisp	Thu Aug 18 17:47:14 2016 +0000
+++ b/src/dijkstra-maps.lisp	Thu Aug 18 18:14:12 2016 +0000
@@ -24,19 +24,6 @@
      :type function)))
 
 
-(defun make-dijkstra-map (array goal-p impassable-p)
-  (let ((dm (make-instance 'dijkstra-map
-                           :source array
-                           :map (make-array (array-dimensions array)
-                                  :element-type 'single-float
-                                  :initial-element 0.0
-                                  :adjustable nil)
-                           :maximum-value 0.0
-                           :impassable-p impassable-p
-                           :goal-p goal-p)))
-    (dm-recalculate dm)
-    dm))
-
 (defmethod print-object ((object dijkstra-map) stream)
   (destructuring-bind (rows cols)
       (array-dimensions (dm-map object))
@@ -56,6 +43,53 @@
         (format stream "   ...very large array...")))))
 
 
+(defun dm-ref (dm x y)
+  (aref (dm-map dm) x y))
+
+
+;;;; Reference
+(defun make-dijkstra-map (array goal-p impassable-p)
+  (let ((dm (make-instance 'dijkstra-map
+                           :source array
+                           :map (make-array (array-dimensions array))
+                           :maximum-value 0.0
+                           :impassable-p impassable-p
+                           :goal-p goal-p)))
+    (dm-recalculate dm)
+    dm))
+
+
+(defun array-index-in-bounds-p (array &rest subscripts)
+  (iterate
+    (for dimension :in (array-dimensions array))
+    (for subscript :in subscripts)
+    (always (< -1 subscript dimension))))
+
+(defun array-neighboring-indices (array row col radius)
+  (iterate
+    (for (dr dc) :within-radius radius :skip-origin t)
+    (for r = (+ row dr))
+    (for c = (+ col dc))
+    (when (array-index-in-bounds-p array r c)
+      (collect (list r c)))))
+
+
+
+;;;; Chili Dogs
+(defun make-dijkstra-map (array goal-p impassable-p)
+  (let ((dm (make-instance 'dijkstra-map
+                           :source array
+                           :map (make-array (array-dimensions array)
+                                  :element-type 'single-float
+                                  :initial-element 0.0
+                                  :adjustable nil)
+                           :maximum-value 0.0
+                           :impassable-p impassable-p
+                           :goal-p goal-p)))
+    (dm-recalculate dm)
+    dm))
+
+
 (defun dm-recalculate (dm)
   (let* ((source (dm-source dm))
          (rows (first (array-dimensions source)))
@@ -99,9 +133,6 @@
 
 
 
-(defun dm-ref (dm x y)
-  (aref (dm-map dm) x y))
-
 ; (defparameter *m*
 ;   (make-array '(5 6)
 ;     :initial-contents (list (list 0 8 0 0 1 0)