From f4b5fd8352e1bade92b3381ffff1542f5175cd71 Mon Sep 17 00:00:00 2001 From: schillic Date: Mon, 1 Oct 2018 16:36:44 +0200 Subject: [PATCH 1/2] made 'Interval' an 'AbstractHyperrectangle' --- src/AbstractCentrallySymmetricPolytope.jl | 3 +- src/AbstractHyperrectangle.jl | 3 +- src/Interval.jl | 49 ++++++++++++++++++++--- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/AbstractCentrallySymmetricPolytope.jl b/src/AbstractCentrallySymmetricPolytope.jl index 486f62af48..114fde97ad 100644 --- a/src/AbstractCentrallySymmetricPolytope.jl +++ b/src/AbstractCentrallySymmetricPolytope.jl @@ -25,10 +25,9 @@ functions: ```jldoctest julia> subtypes(AbstractCentrallySymmetricPolytope) -5-element Array{Any,1}: +4-element Array{Any,1}: AbstractHyperrectangle Ball1 - Interval LineSegment Zonotope ``` diff --git a/src/AbstractHyperrectangle.jl b/src/AbstractHyperrectangle.jl index b9c6e74704..09abb52537 100644 --- a/src/AbstractHyperrectangle.jl +++ b/src/AbstractHyperrectangle.jl @@ -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 ``` """ diff --git a/src/Interval.jl b/src/Interval.jl index 7a0ff742d7..8dada4ffe6 100644 --- a/src/Interval.jl +++ b/src/Interval.jl @@ -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}. @@ -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 @@ -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 From f2207c035080482ef0468b6a19db7b137a1d27b5 Mon Sep 17 00:00:00 2001 From: schillic Date: Mon, 1 Oct 2018 16:41:35 +0200 Subject: [PATCH 2/2] fix method ambiguity --- src/Interval.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Interval.jl b/src/Interval.jl index 8dada4ffe6..0907f6b26f 100644 --- a/src/Interval.jl +++ b/src/Interval.jl @@ -210,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. @@ -223,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}