Skip to content

Commit b3f9a35

Browse files
committed
fix bounds ns
1 parent 5f026e7 commit b3f9a35

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/renderer/utils/bounds.cljs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,25 @@
3232

3333
(defn intersected?
3434
[a-bounds b-bounds]
35-
(let [[a-left a-top a-right a-bottom] a-bounds
36-
[b-left b-top b-right b-bottom] b-bounds]
37-
(not (or (> b-left a-right)
38-
(< b-right a-left)
39-
(> b-top a-bottom)
40-
(< b-bottom a-top)))))
35+
(when (and a-bounds b-bounds)
36+
(let [[a-left a-top a-right a-bottom] a-bounds
37+
[b-left b-top b-right b-bottom] b-bounds]
38+
(not (or (> b-left a-right)
39+
(< b-right a-left)
40+
(> b-top a-bottom)
41+
(< b-bottom a-top))))))
4142

4243
(defn contained?
4344
[a-bounds b-bounds]
44-
(let [[a-left a-top a-right a-bottom] a-bounds
45-
[b-left b-top b-right b-bottom] b-bounds]
46-
(and (> a-left b-left)
47-
(> a-top b-top)
48-
(< a-right b-right)
49-
(< a-bottom b-bottom))))
45+
(when (and a-bounds b-bounds)
46+
(let [[a-left a-top a-right a-bottom] a-bounds
47+
[b-left b-top b-right b-bottom] b-bounds]
48+
(and (> a-left b-left)
49+
(> a-top b-top)
50+
(< a-right b-right)
51+
(< a-bottom b-bottom)))))
5052

51-
(defn contain-point?
53+
(defn contained-point?
5254
[[left top right bottom] [x y]]
5355
(and (<= left x)
5456
(<= top y)

test/bounds_test.cljs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
(is (= (bounds/contained? [5 5 10 10] [0 0 20 20]) true))
2323
(is (= (bounds/contained? [0 0 10 10] [1 1 10 10]) false))))
2424

25-
(deftest test-contain-point?
25+
(deftest test-contained-point?
2626
(testing "bounds contain point"
27-
(is (= (bounds/contain-point? [0 0 10 10] [0 0]) true))
28-
(is (= (bounds/contain-point? [0 0 10 10] [5 5]) true))
29-
(is (= (bounds/contain-point? [0 0 10 10] [10 10]) true))
30-
(is (= (bounds/contain-point? [0 0 10 10] [-5 5]) false))
31-
(is (= (bounds/contain-point? [0 0 10 10] [5 -5]) false))))
27+
(is (= (bounds/contained-point? [0 0 10 10] [0 0]) true))
28+
(is (= (bounds/contained-point? [0 0 10 10] [5 5]) true))
29+
(is (= (bounds/contained-point? [0 0 10 10] [10 10]) true))
30+
(is (= (bounds/contained-point? [0 0 10 10] [-5 5]) false))
31+
(is (= (bounds/contained-point? [0 0 10 10] [5 -5]) false))))
3232

3333
(deftest test-center
3434
(testing "center of bounds"

0 commit comments

Comments
 (0)