#2: done
This commit is contained in:
parent
75899f8a4d
commit
989a8fe91d
|
@ -25,13 +25,12 @@
|
|||
(defn path
|
||||
"Return a path constructed from these `vertices`."
|
||||
[& vertices]
|
||||
(if
|
||||
(every? vertex? vertices)
|
||||
{:vertices vertices :walkmap.id/id (keyword (gensym "path")) :kind :path}
|
||||
(when-not (every? vertex? vertices)
|
||||
(throw (IllegalArgumentException.
|
||||
(str
|
||||
"Each item on path must be a vertex: "
|
||||
(s/join " " (map kind-type vertices)))))))
|
||||
(s/join " " (map kind-type (remove vertex? vertices)))))))
|
||||
{:vertices vertices :walkmap.id/id (keyword (gensym "path")) :kind :path})
|
||||
|
||||
(defn polygon->path
|
||||
"If `o` is a polygon, return an equivalent path. What's different about
|
||||
|
@ -41,10 +40,12 @@
|
|||
|
||||
If `o` is not a polygon, will throw an exception."
|
||||
[o]
|
||||
(if
|
||||
(polygon? o)
|
||||
(assoc (dissoc o :vertices) :kind :path :vertices (concat (:vertices o) (list (first (:vertices o)))))
|
||||
(throw (IllegalArgumentException. "Not a polygon!"))))
|
||||
(when-not (polygon? o)
|
||||
(throw (IllegalArgumentException. (str "Not a polygon: " (kind-type o)))))
|
||||
(assoc (dissoc o :vertices)
|
||||
:kind :path
|
||||
;; `concat` rather than `conj` because order matters.
|
||||
:vertices (concat (:vertices o) (list (first (:vertices o))))))
|
||||
|
||||
(defn path->edges
|
||||
"if `o` is a path, a polygon, or a sequence of vertices, return a sequence of
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
(ns walkmap.polygon
|
||||
"Essentially the specification for things we shall consider to be polygons."
|
||||
(:require [walkmap.vertex :refer [vertex?]]))
|
||||
(:require [clojure.string :as s]
|
||||
[walkmap.utils :refer [kind-type]]
|
||||
[walkmap.vertex :refer [vertex?]]))
|
||||
|
||||
(defn polygon?
|
||||
"True if `o` satisfies the conditions for a polygon. A polygon shall be a
|
||||
|
@ -16,4 +18,11 @@
|
|||
(:walkmap.id/id o)
|
||||
(or (nil? (:kind o)) (= (:kind o) :polygon)))))
|
||||
|
||||
|
||||
(defn polygon
|
||||
[vertices]
|
||||
(when-not (every? vertex? vertices)
|
||||
(throw (IllegalArgumentException.
|
||||
(str
|
||||
"Each item on path must be a vertex: "
|
||||
(s/join " " (map kind-type (remove vertex? vertices)))))))
|
||||
{:vertices vertices :walkmap.id/id (keyword (gensym "poly")) :kind :polygon})
|
||||
|
|
Loading…
Reference in a new issue