                     wall :- s/Str
                     distance-maps :- [DistanceMap]
                     path-map :- (s/maybe PathMap)]
-  (let [changed-cells (or (when-not optimize-drawing (g/grid-coords grid))
+  (let [changed-cells (or (when-not optimize-drawing (set (g/grid-coords grid)))
                           (when path-map (:changed-cells (:distances path-map)))
                           (first (map (comp :changed-cells :distances) distance-maps))
                           (:changed-cells grid)
-                          (g/grid-coords grid))]
+                          (set (g/grid-coords grid)))]
     (draw-cell-backgrounds g grid cell-size background distance-maps changed-cells)
     (draw-cell-walls g grid cell-size wall changed-cells)
     (when path-map (draw-path g cell-size path-map changed-cells))

                         cell-size :- g/NonNegativeInt
                         wall :- s/Str
                         changed-cells]
  (println (str "Drawing walls for " (count changed-cells) " cells."))
  (doseq [coord changed-cells]
    (let [[y1 x1] (map #(* % cell-size) coord)
          [y2 x2] (map #(+ % cell-size) [y1 x1])

;;
;; Any variable called 'g' is a CanvasRenderingContext2D object.

(def optimize-drawing true)

;; To debug the optimized drawing:
;; * set snergly.image/optimize-drawing to true
;; * set snergly.core/sync-by-frame to false
;; * in snergly.core/sync-chan, change the parameter of async/timeout
;;   from 0 to 1000.
;;
;; When I do this, I can tell that the cell background starts too far up
;; and to the left, so that redrawing the background makes the top and left
;; borders half-width.  And the right and left borders, if they are drawn,
;; become progressively thicker; I think this is just because of the canvas
;; drawing strokes with translucency for some reason, even

(defn fill-rect [g style x y w h]
  (aset g "fillStyle" style)
