-
Notifications
You must be signed in to change notification settings - Fork 0
/
signed.clj
49 lines (38 loc) · 1.26 KB
/
signed.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
(ns geo-yoots.sphere.distance.signed
(:require [geo-yoots.constants :as geo.const]
[geo-yoots.util.core :as geo.util]
[geo-yoots.sphere.distance.core :as geo.sphere.dist]
[geo-yoots.sphere.inclusion :as geo.sphere.incl]))
;;; ===
;;; - Signed distance from point to circle
;;; ---
(defn -to-circle
[pt center radius]
(- (geo.sphere.dist/haversine pt center) radius))
(defn to-circle
[pt center radius]
(-to-circle pt center radius))
(defn within-distance-to-circle?
[limit pt center radius]
(<= (-to-circle pt center radius) limit))
;;; ===
;;; - Signed distance from point to polygon
;;; ---
(defn to-polygon
[pt vertices]
(let [dst (geo.sphere.dist/to-polygon pt vertices)]
(if (geo.sphere.incl/point-in-polygon? pt vertices) (* -1 dst) dst)))
(defn -within-distance-to-polygon?
[limit pt vertices]
(loop [xs vertices]
(if-let [x (first xs)]
(let [[arc-p1 arc-p2] x]
(if (<= (geo.sphere.dist/crossarc-distance pt arc-p1 arc-p2) limit)
true
(recur (rest xs))))
false)))
(defn within-distance-to-polygon?
[limit pt vertices]
(if (geo.sphere.incl/point-in-polygon? pt vertices)
true
(-within-distance-to-polygon? limit pt (geo.util/gen-polygon-edges vertices))))