Skip to content

Commit 14ef2a2

Browse files
dpsanderslbenet
authored andcommitted
Add constructor for n-dimensional IntervalBox (#79)
* Add IntervalBox(x::Interval, n), but it's type unstable * Use IntervalBox(x::Interval, Val{n}) to make n-dimensional box * Add IntervalBox(x, n) as well as with Val{n}
1 parent ffcfa70 commit 14ef2a2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/multidim/intervalbox.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ import Base.×
5252
×(a::Interval, b::IntervalBox) = IntervalBox(a, b...)
5353
×(a::IntervalBox, b::Interval) = IntervalBox(a..., b)
5454
×(a::IntervalBox, b::IntervalBox) = IntervalBox(a..., b...)
55+
56+
IntervalBox{n}(x::Interval, ::Type{Val{n}}) = IntervalBox(SVector(ntuple(i->x, Val{n})))
57+
58+
IntervalBox(x::Interval, n::Int) = IntervalBox(x, Val{n})

test/multidim_tests/multidim.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,12 @@ end
112112
@test Y == IntervalBox(Interval(0, 2), Interval(3, 5), Interval(4, 8))
113113
@test diam(Y) == 4
114114
end
115+
116+
@testset "Constructing multidimensional IntervalBoxes" begin
117+
@test IntervalBox(1..2, Val{1}) == IntervalBox(1..2)
118+
@test IntervalBox(1..2, Val{2}) == (1..2) × (1..2)
119+
@test IntervalBox(1..2, Val{5}) == (1..2) × (1..2) × (1..2) × (1..2) × (1..2)
120+
121+
@test IntervalBox(1..2, 3) == IntervalBox(1..2, Val{3})
122+
123+
end

0 commit comments

Comments
 (0)