Skip to content

Commit

Permalink
Correct display of IntervalBox with full option
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders committed Jun 4, 2016
1 parent 8b87747 commit 6bbf7c2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
59 changes: 51 additions & 8 deletions src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,31 @@ function subscriptify(n::Int)
join( [Char(subscript_0 + i) for i in dig])
end

function representation(a::Interval{BigFloat})
if display_params.format == :standard

function representation(a::Interval{BigFloat}, format=nothing)

if format == nothing
format = display_params.format # default
end


if format == :standard
string( invoke(representation, (Interval,), a),
subscriptify(precision(a.lo)) )

elseif display_params.format == :full
elseif format == :full
invoke(representation, (Interval,), a)
end
end

function representation(a::DecoratedInterval)

if display_params.format==:full
function representation(a::DecoratedInterval, format=nothing)

if format == nothing
format = display_params.format # default
end

if format==:full
return "DecoratedInterval($(interval_part(a)), $(decoration(a)))"
end

Expand All @@ -132,7 +144,38 @@ function representation(a::DecoratedInterval)

end

show(io::IO, a::Interval) = print(io, representation(a))
show(io::IO, a::DecoratedInterval) = print(io, representation(a))

showall(io::IO, a::Interval) = print(io, representation(a, :full))
function representation(X::IntervalBox, format=nothing)

if format == nothing
format = display_params.format # default
end

buffer = IOBuffer()

if display_params.format==:full
print(buffer, "IntervalBox(")

for i in 1:length(X)-1
print(buffer, X[i], ", ")
end
print(buffer, X[end], ")")


else

for i in 1:length(X)-1
print(buffer, X[i], " × ")
end
print(buffer, X[end])

end

return takebuf_string(buffer)
end


for T in (Interval, DecoratedInterval, IntervalBox)
@eval show(io::IO, a::$T) = print(io, representation(a))
@eval showall(io::IO, a::Interval) = print(io, representation(a, :full))
end
6 changes: 6 additions & 0 deletions test/display_tests/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,11 @@ facts("displaymode tests") do
X = IntervalBox(1.1..1.2, 2.1..2.2)
@fact string(X) --> "[1.09999, 1.20001] × [2.09999, 2.20001]"

X = IntervalBox(-Inf..Inf, -Inf..Inf)
@fact string(X) --> "[-∞, ∞] × [-∞, ∞]"

displaymode(format=:full)
@fact string(X) --> "IntervalBox(Interval(-Inf, Inf), Interval(-Inf, Inf))"

end
end

0 comments on commit 6bbf7c2

Please sign in to comment.