drainage/flow-world-nr now works; drainage/flow-world still doesn't
This commit is contained in:
parent
93dab8067b
commit
e19ce2e5f7
17 changed files with 1540 additions and 815 deletions
|
|
@ -107,283 +107,301 @@
|
|||
034
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
035 (defn tag-property
|
||||
035 (defn abs
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
036 "Set the value of this `property` of this cell from the corresponding pixel of this `heightmap`.
|
||||
036 "Prior to Clojure 1.11, there is no native `abs` function. Afterwards, there
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
037 If the heightmap you supply is smaller than the world, this will break.
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
038
|
||||
037 is."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
039 * `world` not actually used, but present to enable this function to be
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
040 passed as an argument to `mw-engine.utils/map-world`, q.v.
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
041 * `cell` a cell, as discussed in world.clj, q.v. Alternatively, a map;
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
042 * `property` the property (normally a keyword) whose value will be set on the cell.
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
043 * `heightmap` an (ideally) greyscale image, whose x and y dimensions should
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
044 exceed those of the world of which the `cell` forms part."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
045 ([_ cell property heightmap]
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
046 (tag-property cell property heightmap))
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
047 ([cell property heightmap]
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
048 (merge cell
|
||||
038 [n]
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
049 {property
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
050 (+ (get-int cell property)
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
051 (- 256
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
052 (abs
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
053 (mod
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
054 (.getRGB heightmap
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
055 (get-int cell :x)
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
056 (get-int cell :y)) 256))))})))
|
||||
039 (Math/abs n))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
057
|
||||
040
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
058 (defn tag-gradient
|
||||
041 (defn tag-property
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
059 "Set the `gradient` property of this `cell` of this `world` to the difference in
|
||||
042 "Set the value of this `property` of this cell from the corresponding pixel of this `heightmap`.
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
060 altitude between its highest and lowest neghbours."
|
||||
043 If the heightmap you supply is smaller than the world, this will break.
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
044
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
061 [world cell]
|
||||
045 * `world` not actually used, but present to enable this function to be
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
046 passed as an argument to `mw-engine.utils/map-world`, q.v.
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
047 * `cell` a cell, as discussed in world.clj, q.v. Alternatively, a map;
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
048 * `property` the property (normally a keyword) whose value will be set on the cell.
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
049 * `heightmap` an (ideally) greyscale image, whose x and y dimensions should
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
050 exceed those of the world of which the `cell` forms part."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
051 ([_ cell property heightmap]
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
052 (tag-property cell property heightmap))
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
053 ([cell property heightmap]
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
054 (merge cell
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
055 {property
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
056 (+ (get-int cell property)
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
057 (- 256
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
058 (abs
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
059 (mod
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
060 (.getRGB heightmap
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
061 (get-int cell :x)
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
062 (get-int cell :y)) 256))))})))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
063
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
064 (defn tag-gradient
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
065 "Set the `gradient` property of this `cell` of this `world` to the difference in
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
066 altitude between its highest and lowest neghbours."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
067 [world cell]
|
||||
</span><br/>
|
||||
<span class="covered" title="11 out of 11 forms covered">
|
||||
062 (let [heights (remove nil? (map :altitude (get-neighbours world cell)))
|
||||
068 (let [heights (remove nil? (map :altitude (get-neighbours world cell)))
|
||||
</span><br/>
|
||||
<span class="partial" title="5 out of 6 forms covered">
|
||||
063 highest (cond (empty? heights) 0 ;; shouldn't happen
|
||||
069 highest (cond (empty? heights) 0 ;; shouldn't happen
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
064 :else (apply max heights))
|
||||
070 :else (apply max heights))
|
||||
</span><br/>
|
||||
<span class="partial" title="5 out of 6 forms covered">
|
||||
065 lowest (cond (empty? heights) 0 ;; shouldn't
|
||||
071 lowest (cond (empty? heights) 0 ;; shouldn't
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
066 :else (apply min heights))
|
||||
072 :else (apply min heights))
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
067 gradient (- highest lowest)]
|
||||
073 gradient (- highest lowest)]
|
||||
</span><br/>
|
||||
<span class="covered" title="6 out of 6 forms covered">
|
||||
068 (merge cell {:gradient gradient})))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
069
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
070 (defn tag-gradients
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
071 "Set the `gradient` property of each cell in this `world` to the difference in
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
072 altitude between its highest and lowest neghbours."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
073 [world]
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 4 forms covered">
|
||||
074 (map-world world tag-gradient))
|
||||
074 (merge cell {:gradient gradient})))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
075
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
076 (defn tag-altitude
|
||||
076 (defn tag-gradients
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
077 "Set the altitude of this cell from the corresponding pixel of this heightmap.
|
||||
077 "Set the `gradient` property of each cell in this `world` to the difference in
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
078 If the heightmap you supply is smaller than the world, this will break.
|
||||
078 altitude between its highest and lowest neghbours."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
079 [world]
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 4 forms covered">
|
||||
080 (map-world world tag-gradient))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
079
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
080 * `world` not actually used, but present to enable this function to be
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
081 passed as an argument to `mw-engine.utils/map-world`, q.v.;
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
082 * `cell` a cell, as discussed in world.clj, q.v. Alternatively, a map;
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
083 * `heightmap` an (ideally) greyscale image, whose x and y dimensions should
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
084 exceed those of the world of which the `cell` forms part."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
085 ([_ cell heightmap]
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
086 (tag-property cell :altitude heightmap))
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
087 ([cell heightmap]
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 5 forms covered">
|
||||
088 (tag-property cell :altitude heightmap)))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
089
|
||||
081
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
090 (defn apply-heightmap
|
||||
082 (defn tag-altitude
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
091 "Apply the image file loaded from this path to this world, and return a world whose
|
||||
083 "Set the altitude of this cell from the corresponding pixel of this heightmap.
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
092 altitudes are modified (added to) by the altitudes in the heightmap. It is assumed that
|
||||
084 If the heightmap you supply is smaller than the world, this will break.
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
085
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
093 the heightmap is at least as large in x and y dimensions as the world. Note that, in
|
||||
086 * `world` not actually used, but present to enable this function to be
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
094 addition to setting the `:altitude` of each cell, this function also sets the `:gradient`.
|
||||
087 passed as an argument to `mw-engine.utils/map-world`, q.v.;
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
088 * `cell` a cell, as discussed in world.clj, q.v. Alternatively, a map;
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
089 * `heightmap` an (ideally) greyscale image, whose x and y dimensions should
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
090 exceed those of the world of which the `cell` forms part."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
091 ([_ cell heightmap]
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
092 (tag-property cell :altitude heightmap))
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
093 ([cell heightmap]
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 5 forms covered">
|
||||
094 (tag-property cell :altitude heightmap)))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
095
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
096 * `world` a world, as defined in `world.clj`, q.v.; if world is not supplied,
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
096 (defn apply-heightmap
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
097 a world the size of the heightmap will be created;
|
||||
097 "Apply the image file loaded from this path to this world, and return a world whose
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
098 * `imagepath` a file path or URL which indicates an (ideally greyscale) image file."
|
||||
098 altitudes are modified (added to) by the altitudes in the heightmap. It is assumed that
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
099 ([world imagepath]
|
||||
099 the heightmap is at least as large in x and y dimensions as the world. Note that, in
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
100 addition to setting the `:altitude` of each cell, this function also sets the `:gradient`.
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
101
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
102 * `world` a world, as defined in `world.clj`, q.v.; if world is not supplied,
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
103 a world the size of the heightmap will be created;
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
104 * `imagepath` a file path or URL which indicates an (ideally greyscale) image file."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
105 ([world imagepath]
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
100 (let [heightmap (filter-image
|
||||
106 (let [heightmap (filter-image
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
101 (load-image imagepath)
|
||||
107 (load-image imagepath)
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
102 (filters/grayscale))]
|
||||
108 (filters/grayscale))]
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
103 (map-world
|
||||
109 (map-world
|
||||
</span><br/>
|
||||
<span class="covered" title="7 out of 7 forms covered">
|
||||
104 (map-world world tag-altitude (list heightmap))
|
||||
110 (map-world world tag-altitude (list heightmap))
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
105 tag-gradient)))
|
||||
111 tag-gradient)))
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
106 ([imagepath]
|
||||
112 ([imagepath]
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
107 (let [heightmap (filter-image
|
||||
113 (let [heightmap (filter-image
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
108 (load-image imagepath)
|
||||
114 (load-image imagepath)
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
109 (filters/grayscale))
|
||||
115 (filters/grayscale))
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
110 world (make-world (.getWidth heightmap) (.getHeight heightmap))]
|
||||
116 world (make-world (.getWidth heightmap) (.getHeight heightmap))]
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
111 (map-world
|
||||
117 (map-world
|
||||
</span><br/>
|
||||
<span class="covered" title="7 out of 7 forms covered">
|
||||
112 (map-world world tag-altitude (list heightmap))
|
||||
118 (map-world world tag-altitude (list heightmap))
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
113 tag-gradient))))
|
||||
119 tag-gradient))))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
114
|
||||
120
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
115 (defn apply-valuemap
|
||||
121 (defn apply-valuemap
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
116 "Generalised from apply-heightmap, set an arbitrary property on each cell
|
||||
122 "Generalised from apply-heightmap, set an arbitrary property on each cell
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
117 of this `world` from the values in this (ideally greyscale) heightmap.
|
||||
123 of this `world` from the values in this (ideally greyscale) heightmap.
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
118
|
||||
124
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
119 * `world` a world, as defined in `world.clj`, q.v.;
|
||||
125 * `world` a world, as defined in `world.clj`, q.v.;
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
120 * `imagepath` a file path or URL which indicates an (ideally greyscale) image file;
|
||||
126 * `imagepath` a file path or URL which indicates an (ideally greyscale) image file;
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
121 * `property` the property of each cell whose value should be added to from the
|
||||
127 * `property` the property of each cell whose value should be added to from the
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
122 intensity of the corresponding cell of the image."
|
||||
128 intensity of the corresponding cell of the image."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
123 [world imagepath property]
|
||||
129 [world imagepath property]
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
124 (let [heightmap (filter-image
|
||||
130 (let [heightmap (filter-image
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
125 (load-image imagepath)
|
||||
131 (load-image imagepath)
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
126 (filters/grayscale))]
|
||||
132 (filters/grayscale))]
|
||||
</span><br/>
|
||||
<span class="covered" title="8 out of 8 forms covered">
|
||||
127 (map-world world tag-property (list property heightmap))))
|
||||
133 (map-world world tag-property (list property heightmap))))
|
||||
</span><br/>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue