In the afternoon, he implemented tagging.
And he looked on his work, and saw that it was good.
This commit is contained in:
parent
f4ca49f11b
commit
9ee365b987
3 changed files with 113 additions and 0 deletions
18
src/walkmap/routing.clj
Normal file
18
src/walkmap/routing.clj
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(ns walkmap.core
|
||||
"Finding optimal routes to traverse a map."
|
||||
(:require [walkmap.path :as p]
|
||||
[walkmap.polygon :as q]
|
||||
[walkmap.stl :as s]
|
||||
[walkmap.utils :as u]
|
||||
[walkmap.vertex :as v]))
|
||||
|
||||
;; Breadth first search is a good algorithm for terrain in which all steps have
|
||||
;; equal, but in our world (like the real world), they don't.
|
||||
|
||||
;; Reading list:
|
||||
;;
|
||||
;; https://en.wikipedia.org/wiki/A*_search_algorithm
|
||||
;; https://www.redblobgames.com/pathfinding/a-star/introduction.html
|
||||
;; https://faculty.nps.edu/ncrowe/opmpaper2.htm
|
||||
;;
|
||||
;; See https://simon-brooke.github.io/the-great-game/codox/Pathmaking.html
|
||||
50
src/walkmap/tag.clj
Normal file
50
src/walkmap/tag.clj
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
(ns walkmap.tag
|
||||
"Code for tagging, untagging, and finding tags on objects. Note the use of
|
||||
the namespaced keyword, `:walkmap.tag/tags`, denoted in this file `::tags`.
|
||||
This is in an attempt to avoid name clashes with other uses of this key."
|
||||
(:require [clojure.set :refer [difference union]]))
|
||||
|
||||
(defn tagged?
|
||||
"True if this `object` is tagged with each of these `tags`."
|
||||
[object & tags]
|
||||
(if
|
||||
(map? object)
|
||||
(if
|
||||
(every? keyword? tags)
|
||||
(let [ot (::tags object)]
|
||||
(and
|
||||
(set? ot)
|
||||
(every? ot tags)
|
||||
true))
|
||||
(throw (IllegalArgumentException.
|
||||
(str "Must be keyword(s): " (map type tags)))))
|
||||
(throw (IllegalArgumentException.
|
||||
(str "Must be a map: " (type object))))))
|
||||
|
||||
(defn tag
|
||||
"Return an object like this `object` but with these `tags` added to its tags,
|
||||
if they are not already present."
|
||||
[object & tags]
|
||||
(if
|
||||
(map? object)
|
||||
(if
|
||||
(every? keyword? tags)
|
||||
(assoc object ::tags (union (set tags) (::tags object)))
|
||||
(throw (IllegalArgumentException.
|
||||
(str "Must be keyword(s): " (map type tags)))))
|
||||
(throw (IllegalArgumentException.
|
||||
(str "Must be a map: " (type object))))))
|
||||
|
||||
(defn untag
|
||||
"Return an object like this `object` but with these `tags` removed from its
|
||||
tags, if present."
|
||||
[object & tags]
|
||||
(if
|
||||
(map? object)
|
||||
(if
|
||||
(every? keyword? tags)
|
||||
(assoc object ::tags (difference (::tags object) (set tags)))
|
||||
(throw (IllegalArgumentException.
|
||||
(str "Must be keywords: " (map type tags)))))
|
||||
(throw (IllegalArgumentException.
|
||||
(str "Must be a map: " (type object))))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue