-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
61 lines (50 loc) · 1.26 KB
/
core.clj
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
(ns geo-yoots.util.core
(:require [geo-yoots.constants :as geo.const]))
(defn ** [x n]
(loop [acc 1 n n]
(if (zero? n) acc
(recur (* x acc) (dec n)))))
(defn sq
[x]
(** x 2))
;; ===
;; - Edge Functions
;; ---
;; Generates edges from an input set of vertices
;;
;; ---
(defn label-vertices
"Create {:lat y :lon x} map from input vector [`lat` `lon`]"
[vertices]
(loop [xs vertices
acc []]
(if-let [x (first xs)]
(let [[lat lon] x]
(recur (rest xs) (conj acc {:lat lat :lon lon})))
acc)))
(defn gen-polyline-edges
"Create polyline edges from vertices"
[vertices]
(let [start (first vertices)]
(loop [xs (rest vertices)
a start
acc []]
(if-let [b (first xs)]
(recur (rest xs) b (conj acc [a b]))
acc))))
(defn gen-polygon-edges
"Creates polygon edges from vertices"
[vertices]
(let [start (first vertices)]
(loop [xs (rest vertices)
a start
acc []]
(if-let [b (first xs)]
(recur (rest xs) b (conj acc [a b]))
(conj acc [a start])))))
(defn ensure-unique-vertices
"Ensure vertices only appear once - head & tail are unique "
[vertices]
(if (= (first vertices) (last vertices))
(rest vertices)
vertices))