Skip to content

Commit b42bf08

Browse files
committed
Merge branch 'ff/test-coverage' into ff/breaking-changes
2 parents a257769 + 1be5f72 commit b42bf08

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/primitives/rectangles.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ Base.isnan(r::Rect) = isnan(origin(r)) || isnan(widths(r))
311311
Returns a new `Rect{N}` which contains both r1 and r2.
312312
"""
313313
function Base.union(h1::Rect{N}, h2::Rect{N}) where {N}
314+
isnan(h1) && return h2
315+
isnan(h2) && return h1
314316
m = min.(minimum(h1), minimum(h2))
315317
mm = max.(maximum(h1), maximum(h2))
316318
return Rect{N}(m, mm - m)
@@ -331,6 +333,7 @@ end
331333
Perform a intersection between two Rects.
332334
"""
333335
function Base.intersect(h1::Rect{N}, h2::Rect{N}) where {N}
336+
isnan(h1) || isnan(h2) && return Rect{N}()
334337
m = max.(minimum(h1), minimum(h2))
335338
mm = min.(maximum(h1), maximum(h2))
336339
return Rect{N}(m, mm - m)
@@ -341,7 +344,7 @@ function update(b::Rect{N,T}, v::VecTypes{N,T2}) where {N,T,T2}
341344
end
342345

343346
function update(b::Rect{N,T}, v::VecTypes{N,T}) where {N,T}
344-
isnan(b) && return Rect{N, T}(v)
347+
isnan(b) && return Rect{N, T}(v, Vec{N, T}(0))
345348

346349
m = min.(minimum(b), v)
347350
maxi = maximum(b)

test/geometrytypes.jl

+10
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ end
206206
@test widths(r) == Vec2(0)
207207
@test area(r) == 0
208208
@test volume(r) == 0
209+
@test union(r, Rect2f(1,1,2,2)) == Rect2f(1,1,2,2)
210+
@test union(Rect2f(1,1,2,2), r) == Rect2f(1,1,2,2)
211+
@test update(r, Vec2f(1,1)) == Rect2f(1,1,0,0)
209212

210213
a = Rect(Vec(0, 1), Vec(2, 3))
211214
pt_expa = Point{2,Int}[(0, 1), (2, 1), (2, 4), (0, 4)]
@@ -221,6 +224,9 @@ end
221224
@test widths(a) == Vec(2,3)
222225
@test area(a) == 2*3
223226
@test volume(a) == 2*3
227+
@test union(a, Rect2f(1,1,2,2)) == Rect2f(0,1,3,3)
228+
@test union(Rect2f(1,1,2,2), a) == Rect2f(0,1,3,3)
229+
@test update(a, Vec2f(0,0)) == Rect2f(0,0,2,4)
224230

225231
b = Rect(Vec(1, 2, 3), Vec(4, 5, 6))
226232
pt_expb = Point{3, Int64}[[1, 2, 3], [1, 2, 9], [1, 7, 3], [1, 7, 9],
@@ -235,6 +241,10 @@ end
235241
@test widths(b) == Vec(4,5,6)
236242
@test_throws MethodError area(b)
237243
@test volume(b) == 4*5*6
244+
@test union(b, Rect3f(1,1,1,2,2,2)) == Rect3f(1,1,1, 4,6,8)
245+
@test union(Rect3f(1,1,1,2,2,2), b) == Rect3f(1,1,1, 4,6,8)
246+
@test update(b, Vec3f(0)) == Rect3f(0,0,0,5,7,9)
247+
238248

239249
mesh = normal_mesh(b)
240250
@test faces(mesh) == GLTriangleFace[

0 commit comments

Comments
 (0)