Skip to content

Commit 3ada21c

Browse files
Kolarudpsanders
authored andcommitted
Add Region and mid(X::IntervalBox, alpha) (#148)
* Add Region and mid(X::IntervalBox, alpha) * Fixes requested changes * Remove unnecessary parametrization
1 parent 54b2720 commit 3ada21c

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/IntervalArithmetic.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ export
6969
interval_part, decoration, DecoratedInterval,
7070
com, dac, def, trv, ill
7171

72+
## Union type
73+
export
74+
Region
7275

7376

7477

@@ -94,5 +97,9 @@ include("plot_recipes/plot_recipes.jl")
9497

9598
include("deprecated.jl")
9699

100+
"""
101+
Region{T} = Union{Interval{T}, IntervalBox{T}}
102+
"""
103+
const Region{T} = Union{Interval{T}, IntervalBox{T}}
97104

98105
end # module IntervalArithmetic

src/multidim/intervalbox.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ eltype(::Type{IntervalBox{N,T}}) where {N,T} = Interval{T} # Note that this is d
3737

3838
## arithmetic operations
3939
# Note that standard arithmetic operations are implemented automatically by FixedSizeArrays.jl
40+
"""
41+
mid(X::IntervalBox, α=0.5)
42+
43+
Return a vector of the `mid` of each interval composing the `IntervalBox`.
4044
45+
See `mid(X::Interval, α=0.5)` for more informations.
46+
"""
47+
mid(X::IntervalBox, α) = mid.(X, α)
4148
mid(X::IntervalBox) = mid.(X)
4249
mid(X::IntervalBox, α) = mid.(X, α)
4350

test/multidim_tests/multidim.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ end
134134
@test length(Y) == 3
135135
@test Y == IntervalBox(Interval(0, 2), Interval(3, 5), Interval(4, 8))
136136
@test diam(Y) == 4
137+
138+
@test mid(IntervalBox(0..1, 3), 0.75) == [0.75, 0.75, 0.75]
137139
end
138140

139141
@testset "Constructing multidimensional IntervalBoxes" begin

0 commit comments

Comments
 (0)