Skip to content

Commit 10d2bb1

Browse files
authored
Merge pull request #39 from visr/test
add a few tests on Rect and Line
2 parents bd63aee + 75c8988 commit 10d2bb1

File tree

4 files changed

+266
-241
lines changed

4 files changed

+266
-241
lines changed

Project.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
1111
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
1212

1313
[compat]
14-
StaticArrays = "0.12,0.1"
14+
IterTools = "1.3.0"
15+
StaticArrays = "0.12"
1516
StructArrays = "0.3,0.4"
1617
Tables = "0.2, 1"
1718
julia = "1.1"
18-
IterTools = "1.3.0"
1919

2020
[extras]
21-
Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1"
2221
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2322
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2423

2524
[targets]
26-
test = ["Test", "Query", "Random"]
25+
test = ["Test", "Random"]

src/rectangles.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,23 +479,23 @@ end
479479
# Containment
480480

481481
"""
482-
contains(b1::Rect, b2::Rect)
482+
in(b1::Rect, b2::Rect)
483483
484-
Check if Rects are contained in each other. This does not use
484+
Check if Rect `b1` is contained in `b2`. This does not use
485485
strict inequality, so Rects may share faces and this will still
486486
return true.
487487
"""
488-
function Base.in(b2::Rect{N}, b1::Rect{N}) where N
488+
function Base.in(b1::Rect{N}, b2::Rect{N}) where N
489489
for i = 1:N
490-
maximum(b2)[i] <= maximum(b1)[i] &&
491-
minimum(b2)[i] >= minimum(b1)[i] ||
490+
maximum(b1)[i] <= maximum(b2)[i] &&
491+
minimum(b1)[i] >= minimum(b2)[i] ||
492492
return false
493493
end
494494
return true
495495
end
496496

497497
"""
498-
contains(b1::Rect{N, T}, pt::VecTypes)
498+
in(pt::VecTypes, b1::Rect{N, T})
499499
500500
Check if a point is contained in a Rect. This will return true if
501501
the point is on a face of the Rect.

test/geometrytypes.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,16 @@ end
226226
rect = FRect3D(base, wxyz)
227227
@test (rect * 4) == FRect3D(base .* 4, wxyz .* 4)
228228
@test (rect * Vec(2, -2, 3)) == FRect3D(base .* Vec(2, -2, 3), wxyz .* Vec(2, -2, 3))
229+
230+
rect1 = Rect(Vec(0.0, 0.0), Vec(1.0, 2.0))
231+
rect2 = Rect(0.0, 0.0, 1.0, 2.0)
232+
@test rect1 isa GeometryBasics.HyperRectangle{2, Float64}
233+
@test rect1 == rect2
234+
235+
split1, split2 = GeometryBasics.split(rect1, 2, 1)
236+
@test widths(split1) == widths(split2)
237+
@test origin(split1) == Vec(0, 0)
238+
@test origin(split2) == Vec(0, 1)
239+
@test in(split1, rect1)
240+
@test !in(rect1, split1)
229241
end

0 commit comments

Comments
 (0)