Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1222 - Convert hyperrectangular sets to hyperrectangle #1224

Merged
merged 1 commit into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/lib/conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
14 changes: 7 additions & 7 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
7 changes: 7 additions & 0 deletions test/unit_Hyperrectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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