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

#488 - Make Interval an AbstractHyperrectangle #687

Merged
merged 2 commits into from
Oct 1, 2018
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
3 changes: 1 addition & 2 deletions src/AbstractCentrallySymmetricPolytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ functions:

```jldoctest
julia> subtypes(AbstractCentrallySymmetricPolytope)
5-element Array{Any,1}:
4-element Array{Any,1}:
AbstractHyperrectangle
Ball1
Interval
LineSegment
Zonotope
```
Expand Down
3 changes: 2 additions & 1 deletion src/AbstractHyperrectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ Every concrete `AbstractHyperrectangle` must define the following functions:

```jldoctest
julia> subtypes(AbstractHyperrectangle)
4-element Array{Any,1}:
5-element Array{Any,1}:
AbstractSingleton
BallInf
Hyperrectangle
Interval
SymmetricIntervalHull
```
"""
Expand Down
53 changes: 46 additions & 7 deletions src/Interval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ export Interval,
low, high, vertices_list

"""
Interval{N<:Real, IN <: AbstractInterval{N}}
<: AbstractCentrallySymmetricPolytope{N}
Interval{N<:Real, IN <: AbstractInterval{N}} <: AbstractHyperrectangle{N}

Type representing an interval on the real line. Mathematically, it is of the
form
Type representing an interval on the real line.
Mathematically, it is of the form

```math
[a, b] := \\{ a ≤ x ≤ b \\} ⊆ \\mathbb{R}.
Expand Down Expand Up @@ -75,7 +74,7 @@ julia> Interval(0//1, 2//1)
Interval{Rational{Int64},IntervalArithmetic.AbstractInterval{Rational{Int64}}}([0//1, 2//1])
```
"""
struct Interval{N<:Real, IN <: AbstractInterval{N}} <: AbstractCentrallySymmetricPolytope{N}
struct Interval{N<:Real, IN <: AbstractInterval{N}} <: AbstractHyperrectangle{N}
dat::IN
end

Expand Down Expand Up @@ -211,7 +210,7 @@ The product of the intervals as a new `Interval` set.
*(x::Interval, y::Interval) = Interval(x.dat * y.dat)

"""
∈(v::AbstractVector, x::Interval)
∈(v::AbstractVector{N}, x::Interval{N}) where {N<:Real})

Return whether a vector is contained in the interval.

Expand All @@ -224,7 +223,7 @@ Return whether a vector is contained in the interval.

`true` iff `x` contains `v`'s first component.
"""
∈(v::AbstractVector, x::Interval) = v[1] ∈ x.dat
∈(v::AbstractVector{N}, x::Interval{N}) where {N<:Real} = v[1] ∈ x.dat

"""
∈(v::N, x::Interval) where {N}
Expand Down Expand Up @@ -303,3 +302,43 @@ Return the list of vertices of this interval.
The list of vertices of the interval represented as two one-dimensional vectors.
"""
vertices_list(x::Interval) = [[low(x)], [high(x)]]


# --- AbstractHyperrectangle interface functions ---


"""
radius_hyperrectangle(I::Interval{N}, i::Int)::N where {N<:Real}

Return the box radius of an interval in a given dimension.

### Input

- `I` -- interval
- `i` -- dimension index (must be `1`)

### Output

The box radius in the given dimension.
"""
function radius_hyperrectangle(I::Interval{N}, i::Int)::N where {N<:Real}
@assert i == 1 "an interval is one-dimensional"
return high(x) - low(x)
end

"""
radius_hyperrectangle(I::Interval{N})::Vector{N} where {N<:Real}

Return the box radius of an interval in every dimension.

### Input

- `I` -- interval

### Output

The box radius of the interval (a one-dimensional vector).
"""
function radius_hyperrectangle(I::Interval{N})::Vector{N} where {N<:Real}
return [high(x) - low(x)]
end