New developed Isle of Man maps; work on intersections.
This commit is contained in:
parent
48d9aacb69
commit
4161f4f04a
1
resources/iom/isle_of_man.edn
Normal file
1
resources/iom/isle_of_man.edn
Normal file
File diff suppressed because one or more lines are too long
1
resources/iom/isle_of_man.html
Normal file
1
resources/iom/isle_of_man.html
Normal file
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
1
resources/iom/isle_of_man_75.edn
Normal file
1
resources/iom/isle_of_man_75.edn
Normal file
File diff suppressed because one or more lines are too long
1
resources/iom/isle_of_man_80.edn
Normal file
1
resources/iom/isle_of_man_80.edn
Normal file
File diff suppressed because one or more lines are too long
1
resources/iom/isle_of_man_80.html
Normal file
1
resources/iom/isle_of_man_80.html
Normal file
File diff suppressed because one or more lines are too long
1
resources/iom/isle_of_man_85.edn
Normal file
1
resources/iom/isle_of_man_85.edn
Normal file
File diff suppressed because one or more lines are too long
1
resources/iom/isle_of_man_85.html
Normal file
1
resources/iom/isle_of_man_85.html
Normal file
File diff suppressed because one or more lines are too long
1
resources/iom/isle_of_man_90.edn
Normal file
1
resources/iom/isle_of_man_90.edn
Normal file
File diff suppressed because one or more lines are too long
1
resources/iom/isle_of_man_90.html
Normal file
1
resources/iom/isle_of_man_90.html
Normal file
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -115,14 +115,21 @@
|
||||||
|
|
||||||
(defn overlaps2d?
|
(defn overlaps2d?
|
||||||
"True if the recangle in the x,y plane bisected by edge `e1` overlaps that
|
"True if the recangle in the x,y plane bisected by edge `e1` overlaps that
|
||||||
bisected by edge `e2`. It is an error if either `e1` or `e2` is not an edge."
|
bisected by edge `e2`. It is an error if either `e1` or `e2` is not an edge.
|
||||||
[e1 e2]
|
|
||||||
|
If `c1` is passed it should be the first coordinate of the plane of
|
||||||
|
projection on which the overlap is sought (default: `:x`); similarly `c2`
|
||||||
|
should be the second such coordinate (default: `:y`)."
|
||||||
|
([e1 e2]
|
||||||
|
(overlaps2d? e1 e2 :x :y))
|
||||||
|
([e1 e2 c1 c2]
|
||||||
(when (and (edge? e1) (edge? e2))
|
(when (and (edge? e1) (edge? e2))
|
||||||
(and
|
(and
|
||||||
(> (minimaxd e1 :x max) (minimaxd e2 :x min))
|
(> (minimaxd e1 c1 max) (minimaxd e2 c1 min))
|
||||||
(< (minimaxd e1 :x min) (minimaxd e2 :x max))
|
(< (minimaxd e1 c1 min) (minimaxd e2 c1 max))
|
||||||
(> (minimaxd e1 :y max) (minimaxd e2 :y min))
|
(> (minimaxd e1 c2 max) (minimaxd e2 c2 min))
|
||||||
(< (minimaxd e1 :y min) (minimaxd e2 :y max)))))
|
(< (minimaxd e1 c2 min) (minimaxd e2 c2 max))))))
|
||||||
|
|
||||||
|
|
||||||
(defn intersection2d
|
(defn intersection2d
|
||||||
"The probability of two lines intersecting in 3d space is low, and actually
|
"The probability of two lines intersecting in 3d space is low, and actually
|
||||||
|
@ -140,38 +147,40 @@
|
||||||
|
|
||||||
It is an error, and an exception will be thrown, if either `e1` or `e2` is
|
It is an error, and an exception will be thrown, if either `e1` or `e2` is
|
||||||
not an edge."
|
not an edge."
|
||||||
[e1 e2]
|
([e1 e2]
|
||||||
(if (and (edge? e1) (edge? e2))
|
(intersection2d e1 e2 :x :y :z))
|
||||||
(when
|
([e1 e2 c1 c2 c3]
|
||||||
(overlaps2d? e1 e2) ;; relatively cheap check
|
(if (and (edge? e1) (edge? e2))
|
||||||
(if
|
(when
|
||||||
(collinear2d? e1 e2)
|
(overlaps2d? e1 e2) ;; relatively cheap check
|
||||||
;; any point within the overlap will do, but we'll pick the end of e1
|
(if
|
||||||
;; which is on e2
|
(collinear2d? e1 e2)
|
||||||
(if (on2d? e2 (:start e1)) (:start e1) (:end e1))
|
;; any point within the overlap will do, but we'll pick the end of e1
|
||||||
;; blatantly stolen from
|
;; which is on e2
|
||||||
;; https://gist.github.com/cassiel/3e725b49670356a9b936
|
(if (on2d? e2 (:start e1)) (:start e1) (:end e1))
|
||||||
(let [x1 (:x (:start e1))
|
;; blatantly stolen from
|
||||||
x2 (:x (:end e1))
|
;; https://gist.github.com/cassiel/3e725b49670356a9b936
|
||||||
x3 (:x (:start e2))
|
(let [x1 (c1 (:start e1))
|
||||||
x4 (:x (:end e2))
|
x2 (c1 (:end e1))
|
||||||
y1 (:y (:start e1))
|
x3 (c1 (:start e2))
|
||||||
y2 (:y (:end e1))
|
x4 (c1 (:end e2))
|
||||||
y3 (:y (:start e2))
|
y1 (c2 (:start e1))
|
||||||
y4 (:y (:end e2))
|
y2 (c2 (:end e1))
|
||||||
denom (- (* (- x1 x2) (- y3 y4))
|
y3 (c2 (:start e2))
|
||||||
(* (- y1 y2) (- x3 x4)))
|
y4 (c2 (:end e2))
|
||||||
x1y2-y1x2 (- (* x1 y2) (* y1 x2))
|
denom (- (* (- x1 x2) (- y3 y4))
|
||||||
x3y4-y3x4 (- (* x3 y4) (* y3 x4))
|
(* (- y1 y2) (- x3 x4)))
|
||||||
px-num (- (* x1y2-y1x2 (- x3 x4))
|
x1y2-y1x2 (- (* x1 y2) (* y1 x2))
|
||||||
(* (- x1 x2) x3y4-y3x4))
|
x3y4-y3x4 (- (* x3 y4) (* y3 x4))
|
||||||
py-num (- (* x1y2-y1x2 (- y3 y4))
|
px-num (- (* x1y2-y1x2 (- x3 x4))
|
||||||
(* (- y1 y2) x3y4-y3x4))
|
(* (- x1 x2) x3y4-y3x4))
|
||||||
result (when-not (zero? denom)
|
py-num (- (* x1y2-y1x2 (- y3 y4))
|
||||||
(vertex (/ px-num denom) (/ py-num denom)))]
|
(* (- y1 y2) x3y4-y3x4))
|
||||||
(when (and result (on2d? e1 result) (on2d? e2 result)) result))))
|
result (when-not (zero? denom)
|
||||||
(throw (IllegalArgumentException.
|
(vertex (/ px-num denom) (/ py-num denom)))]
|
||||||
(str
|
(when (and result (on2d? e1 result) (on2d? e2 result)) result))))
|
||||||
"Both `e1` and `e2` must be edges."
|
(throw (IllegalArgumentException.
|
||||||
(map #(or (:kind %) (type %)) [e1 e2]))))))
|
(str
|
||||||
|
"Both `e1` and `e2` must be edges."
|
||||||
|
(map #(or (:kind %) (type %)) [e1 e2])))))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue