|
78 | 78 |
|
79 | 79 | @testset "HyperRectangles" begin |
80 | 80 | @testset "Constructors" begin |
81 | | - # TODO: Do these actually make sense? |
82 | | - # Should they not be Rect(NaN..., 0...)? |
83 | 81 | @testset "Empty Constructors" begin |
| 82 | + function nan_equal(r1::Rect, r2::Rect) |
| 83 | + o1 = origin(r1); o2 = origin(r2) |
| 84 | + return ((isnan(o1) && isnan(o2)) || (o1 == o2)) && (widths(r1) == widths(r2)) |
| 85 | + end |
| 86 | + |
84 | 87 | for constructor in [Rect, Rect{2}, Rect2, RectT, Rect2f] |
85 | | - @test constructor() == Rect{2, Float32}(Inf, Inf, -Inf, -Inf) |
| 88 | + @test nan_equal(constructor(), Rect{2, Float32}(NaN, NaN, 0, 0)) |
86 | 89 | end |
87 | 90 | for constructor in [Rect{3}, Rect3, Rect3f] |
88 | | - @test constructor() == Rect{3, Float32}((Inf, Inf, Inf), (-Inf, -Inf, -Inf)) |
| 91 | + @test nan_equal(constructor(), Rect{3, Float32}((NaN, NaN, NaN), (0, 0, 0))) |
89 | 92 | end |
90 | 93 |
|
91 | | - for T in [UInt32, Int16, Float64] |
| 94 | + for T in [UInt32, Int16] |
92 | 95 | a = typemax(T) |
93 | 96 | b = typemin(T) |
94 | 97 | for constructor in [Rect{2, T}, Rect2{T}, RectT{T, 2}] |
95 | | - @test constructor() == Rect{2, T}(a, a, b, b) |
| 98 | + @test_throws MethodError constructor() |
96 | 99 | end |
97 | 100 | for constructor in [Rect{3, T}, Rect3{T}, RectT{T, 3}] |
98 | | - @test constructor() == Rect{3, T}(Point(a, a, a), Vec(b, b, b)) |
| 101 | + @test_throws MethodError constructor() |
99 | 102 | end |
100 | 103 | end |
| 104 | + |
| 105 | + for constructor in [Rect{2, Float64}, Rect2{Float64}, RectT{Float64, 2}] |
| 106 | + @test nan_equal(constructor(), Rect{2, Float64}(NaN, NaN, 0, 0)) |
| 107 | + end |
| 108 | + for constructor in [Rect{3, Float64}, Rect3{Float64}, RectT{Float64, 3}] |
| 109 | + @test nan_equal(constructor(), Rect{3, Float64}(Point3(NaN), Vec3(0))) |
| 110 | + end |
101 | 111 | end |
102 | 112 |
|
103 | 113 | @testset "Constructor arg conversions" begin |
@@ -182,19 +192,17 @@ end |
182 | 192 | end |
183 | 193 | end |
184 | 194 |
|
185 | | - # TODO: These don't really make sense... |
186 | 195 | r = Rect2f() |
187 | | - @test origin(r) == Vec(Inf, Inf) |
188 | | - @test minimum(r) == Vec(Inf, Inf) |
| 196 | + @test isnan(origin(r)) |
| 197 | + @test isnan(minimum(r)) |
189 | 198 | @test isnan(maximum(r)) |
190 | | - @test width(r) == -Inf |
191 | | - @test height(r) == -Inf |
192 | | - @test widths(r) == Vec(-Inf, -Inf) |
193 | | - @test area(r) == Inf |
194 | | - @test volume(r) == Inf |
195 | | - # TODO: broken? returns NaN widths |
196 | | - # @test union(r, Rect2f(1,1,2,2)) == Rect2f(1,1,2,2) |
197 | | - # @test union(Rect2f(1,1,2,2), r) == Rect2f(1,1,2,2) |
| 199 | + @test width(r) == 0 |
| 200 | + @test height(r) == 0 |
| 201 | + @test widths(r) == Vec2(0) |
| 202 | + @test area(r) == 0 |
| 203 | + @test volume(r) == 0 |
| 204 | + @test union(r, Rect2f(1,1,2,2)) == Rect2f(1,1,2,2) |
| 205 | + @test union(Rect2f(1,1,2,2), r) == Rect2f(1,1,2,2) |
198 | 206 | @test update(r, Vec2f(1,1)) == Rect2f(1,1,0,0) |
199 | 207 |
|
200 | 208 | a = Rect(Vec(0, 1), Vec(2, 3)) |
|
0 commit comments