summaryrefslogtreecommitdiff
path: root/assets/viz/2/viz/grid.cljs
blob: 6e31443e15f15b516efde5737dd59d6cd7b3f4f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(ns viz.grid)

;; grid     set of points relative to a common origin

(def euclidean [       [0 -1]
                [-1 0]   ,    [1 0]
                       [0 1]       ])

(def isometric [[-1 -1] [0 -2] [1 -1]
                          ,
                [-1 1]  [0 2]  [1 1]])

(def hexagonal [        [0 -1]
                          ,
                [-1 1]         [1 1]])

(defn new-grid [grid-def]
  { :grid-def grid-def
    :points   #{} })

(defn add-point [grid point]
  (update-in grid [:points] conj point))

(def my-grid (-> (new-grid euclidean)
                 (add-point [0 1])))

;; TODO this could be useful, but it's not needed now, as long as all points we
;; use are generated from adjacent-points
;;(defn valid-point? [grid point]
;;  (letfn [(ordered-dim-points [dim order]
;;            (->> (:grid-def grid)
;;                 (map #(%1 dim))
;;                 (sort (if (= order :asc) < > ))
;;                 (filter (if (= order :asc) #(> %1 0) #(< %1 0)))
;;                 ))
;;          (closest-in-dim [dim-i dim-jj]
;;            (reduce (fn [curr dim-j]
;;                      (let [next (+ curr dim-j)]
;;                        (reduce #(if (= ;; TODO wat
;;                                   (if (> 0 dim-i) 
;;                                     (min dim-i next)
;;                                     (max dim-i next))))
;;                    0 dim-jj))
;;
;;          ]
;;    (closest-in-dim 4 [1])))
;;    ;;(ordered-dim 1 :asc)))
;;
;;(valid-point? my-grid [0 1])

(defn rm-point [grid point]
  (update-in grid [:points] disj point))

(defn adjacent-points [grid point]
  (map #(map + %1 point) (:grid-def grid)))

(defn empty-adjacent-points [grid point]
  (remove (:points grid) (adjacent-points grid point)))

(-> (new-grid isometric)
    (add-point [0 0])
    (add-point [0 1])
    (empty-adjacent-points [0 1]))