# HG changeset patch # User Robert McIntyre # Date 1326540517 25200 # Node ID 65332841b7d94f69906282bf3b8c6d81b4114a7e # Parent 940074adc1d5e7602bbb111dc66ebc98b49fd7e9 topological sensor bundling appears to work diff -r 940074adc1d5 -r 65332841b7d9 org/test-creature.org --- a/org/test-creature.org Sat Jan 14 01:19:18 2012 -0700 +++ b/org/test-creature.org Sat Jan 14 04:28:37 2012 -0700 @@ -98,39 +98,78 @@ "Take a sparse collection of points and visuliaze it as a BufferedImage." [points] - (let [xs (map first points) - ys (map second points) - width (- (apply max xs) (apply min xs)) - height (- (apply max ys) (apply min ys)) - image (BufferedImage. width height - BufferedImage/TYPE_BYTE_BINARY) - + (let [xs (vec (map first points)) + ys (vec (map second points)) + x0 (apply min xs) + y0 (apply min ys) + width (- (apply max xs) x0) + height (- (apply max ys) y0) + image (BufferedImage. (inc width) (inc height) + BufferedImage/TYPE_BYTE_BINARY)] + (dorun + (for [index (range (count points))] + (.setRGB image (- (xs index) x0) (- (ys index) y0) -1))) - - )) + image)) ;;(defn visualize [points] +(defn test-data + [] + (vec + (for [a (range 0 100 2) + b (range 0 100 2)] + (vector a b)) + )) +(defn average [coll] + (/ (reduce + coll) (count coll))) + +(defn collapse-1d + "One dimensional analogue of collapse" + [center line] + (let [length (count line) + num-above (count (filter (partial < center) line)) + num-below (- length num-above)] + (range (- center num-below) + (+ center num-above)) + )) (defn collapse "Take a set of pairs of integers and collapse them into a contigous bitmap." [points] - (let [center [0 0]] - - ) - - - - - - - - + (let + [num-points (count points) + center (vector + (average (map first points)) + (average (map first points))) + flattened + (reduce + concat + (map + (fn [column] + (map vector + (map first column) + (collapse-1d (second center) + (map second column)))) + (partition-by first (sort-by first points)))) + squeezed + (reduce + concat + (map + (fn [row] + (map vector + (collapse-1d (first center) + (map first row)) + (map second row))) + (partition-by second (sort-by second flattened))))] + squeezed + )) + (defn load-bullet []