diff --git a/docs/src/lib/conversion.md b/docs/src/lib/conversion.md index ba6e742105..01e41ec2e6 100644 --- a/docs/src/lib/conversion.md +++ b/docs/src/lib/conversion.md @@ -18,7 +18,7 @@ end ```@docs convert(::Type{HPOLYGON1}, ::HPOLYGON2) where {HPOLYGON1<:AbstractHPolygon, HPOLYGON2<:AbstractHPolygon} convert(::Type{HPOLYGON}, ::VPolygon) where {HPOLYGON<:AbstractHPolygon} -convert(::Type{Hyperrectangle}, ::Interval) +convert(::Type{Hyperrectangle}, ::AbstractHyperrectangle) convert(::Type{Interval}, ::AbstractHyperrectangle) convert(::Type{Interval}, ::LazySet{N}) where {N<:Real} convert(::Type{Hyperrectangle}, cpa::CartesianProductArray{N, HN}) where {N<:Real, HN<:AbstractHyperrectangle{N}} diff --git a/src/convert.jl b/src/convert.jl index c5abc9b135..8e2d14f806 100644 --- a/src/convert.jl +++ b/src/convert.jl @@ -316,14 +316,14 @@ function convert(::Type{HPOLYGON}, L::LineSegment{N} end """ - convert(::Type{Hyperrectangle}, x::Interval) + convert(::Type{Hyperrectangle}, H::AbstractHyperrectangle) -Converts a unidimensional interval into a hyperrectangle. +Convert a hyperrectangular set to a hyperrectangle. ### Input - `Hyperrectangle` -- hyperrectangle type, used for dispatch -- `x` -- interval +- `H` -- hyperrectangular set ### Output @@ -336,14 +336,14 @@ julia> convert(Hyperrectangle, Interval(0.0, 1.0)) Hyperrectangle{Float64}([0.5], [0.5]) ``` """ -function convert(::Type{Hyperrectangle}, x::Interval) - return Hyperrectangle(low=[min(x)], high=[max(x)]) +function convert(::Type{Hyperrectangle}, H::AbstractHyperrectangle) + return Hyperrectangle(center(H), radius_hyperrectangle(H)) end """ convert(::Type{Interval}, H::AbstractHyperrectangle) -Converts a hyperrectangular set to a unidimensional interval. +Converts a hyperrectangular set to an interval. ### Input @@ -369,7 +369,7 @@ end """ convert(::Type{Interval}, S::LazySet{N}) where {N<:Real} -Converts a convex set to a unidimensional interval. +Converts a convex set to an interval. ### Input diff --git a/test/unit_Hyperrectangle.jl b/test/unit_Hyperrectangle.jl index 7fa42b3fe2..f6c25b1169 100644 --- a/test/unit_Hyperrectangle.jl +++ b/test/unit_Hyperrectangle.jl @@ -162,4 +162,11 @@ for N in [Float64, Rational{Int}, Float32] B = IntervalBox(IntervalArithmetic.Interval(0, 1), IntervalArithmetic.Interval(0, 1)) H = convert(Hyperrectangle, B) @test convert(IntervalBox, H) == B + + # conversion from other hyperrectangular sets + @test convert(Hyperrectangle, BallInf(N[1], N(1))) == + convert(Hyperrectangle, Interval(N(0), N(2))) == + Hyperrectangle(N[1], N[1]) + @test convert(Hyperrectangle, SymmetricIntervalHull(Singleton(N[1, 1]))) == + Hyperrectangle(N[0, 0], N[1, 1]) end