Skip to content

Commit

Permalink
Avoid IntervalBox referring to its internal variable (#133)
Browse files Browse the repository at this point in the history
* Change internals of IntervalBox for recent FixedSizeArrays changes

* Fix IntervalBox and tests to avoid reference to the internal variable inside the IntervalBox
  • Loading branch information
dpsanders authored and lbenet committed May 21, 2016
1 parent a0e6a55 commit 378e6c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/multidim/intervalbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ doc"""An `IntervalBox` is a Cartesian product of an arbitrary number of `Interva
representing an $N$-dimensional rectangular IntervalBox."""

immutable IntervalBox{N, T} <: FixedVector{N, Interval{T}} # uses FixedSizeArrays package
intervals :: NTuple{N, Interval{T}}
_ :: NTuple{N, Interval{T}}
end

IntervalBox(x::Interval) = IntervalBox( (x,) ) # single interval treated as tuple with one element


mid(X::IntervalBox) = [mid(x) for x in X.intervals]
mid(X::IntervalBox) = [mid(x) for x in X]

(X::IntervalBox, Y::IntervalBox) = all([x y for (x,y) in zip(X.intervals, Y.intervals)])
(X::IntervalBox, Y::IntervalBox) = all([x y for (x,y) in zip(X, Y)])

(X::IntervalBox, Y::IntervalBox) = IntervalBox([x y for (x,y) in zip(X.intervals, Y.intervals)]...)
isempty(X::IntervalBox) = any(map(isempty, X.intervals))
(X::IntervalBox, Y::IntervalBox) = IntervalBox([x y for (x,y) in zip(X, Y)]...)
isempty(X::IntervalBox) = any([isempty(x) for x in X])


function show(io::IO, X::IntervalBox)
Expand Down
2 changes: 1 addition & 1 deletion test/multidim_tests/multidim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ facts("Operations on boxes") do

Y = IntervalBox(1..2) # single interval
@fact isa(Y, IntervalBox) --> true
@fact length(Y.intervals) --> 1
@fact length(Y) --> 1
@fact Y --> IntervalBox( (Interval(1., 2.),) )

end
Expand Down

0 comments on commit 378e6c9

Please sign in to comment.