Skip to content

Commit 7051fa3

Browse files
authored
allow Vectors in Rect (#243)
* allow Vectors * add tests
1 parent 7ed350d commit 7051fa3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/primitives/rectangles.jl

+7
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ end
9595
RectT{ T}(o::VecTypes{N}, w::VecTypes{N}) where {N, T} = Rect{N, T}(o, w)
9696
Rect{N }(o::VecTypes{N, T1}, w::VecTypes{N, T2}) where {N, T1, T2} = Rect{N, promote_type(T1, T2)}(o, w)
9797

98+
# Arrays
99+
100+
Rect(o::AbstractVector{T1}, w::AbstractVector{T2}) where {T1, T2} = RectT{promote_type(T1, T2)}(Vec(o...), Vec(w...))
101+
RectT{ T}(o::AbstractVector, w::AbstractVector) where {T} = RectT{T}(Vec(o...), Vec(w...))
102+
Rect{N }(o::AbstractVector{T1}, w::AbstractVector{T2}) where {N, T1, T2} = Rect{N, promote_type(T1, T2)}(Vec(o...), Vec(w...))
103+
Rect{N, T}(o::AbstractVector, w::AbstractVector) where {N, T} = Rect{N, T}(Vec(o...), Vec(w...))
104+
98105
# mixed number - vectype
99106

100107
Rect(o::VecTypes{N, <:Number}, args::Vararg{Number, N}) where {N} = Rect{N }(o, promote(args...))

test/geometrytypes.jl

+6
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ end
188188
@test Rect2{UInt32}(0.8, 0.1, 1.3, 1.9) == Rect2i(1,0,1,2)
189189
@test Rect3i(0.3, 0.6, 0.9, 1.2, 1.5, 1.8) == Rect3i(0,1,1,1,2,2)
190190
end
191+
@testset "Vector inputs" begin
192+
@test Rect([1,2], [2,3]) == Rect2i(1,2,2,3)
193+
@test Rect2f([0,1], [2,3]) == Rect2f(0,1,2,3)
194+
@test RectT{Float64}([0,1,0], [2,2,2]) == Rect3d(0,1,0, 2,2,2)
195+
@test Rect3([0,1,0], [2,2,2]) == Rect3i(0,1,0, 2,2,2)
196+
end
191197

192198
# TODO: These don't really make sense...
193199
r = Rect2f()

0 commit comments

Comments
 (0)