diff --git a/src/Approximations/box_approximations.jl b/src/Approximations/box_approximations.jl index 9cbe85231e..aaccdaacb2 100644 --- a/src/Approximations/box_approximations.jl +++ b/src/Approximations/box_approximations.jl @@ -41,6 +41,36 @@ box_approximation(S::AbstractHyperrectangle) = # special case: empty set box_approximation(∅::EmptySet) = ∅ +""" + box_approximation(r::Rectification{N} + )::Union{Hyperrectangle{N}, EmptySet{N}} where {N<:Real} + +Overapproximate the rectification of a convex set by a tight hyperrectangle. + +### Input + +- `S` -- rectification of a convex set + +### Output + +A hyperrectangle. + +### Algorithm + +Box approximation and rectification distribute. +Hence we first check whether the wrapped set is empty. +If so, we return the empty set. +Otherwise, we compute the box approximation of the wrapped set, rectify the +resulting box (which is simple), and finally convert the resulting set to a box. +""" +function box_approximation(r::Rectification{N} + )::Union{Hyperrectangle{N}, EmptySet{N}} where {N<:Real} + if isempty(r.X) + return EmptySet{N}() + end + return convert(Hyperrectangle, Rectification(box_approximation(r.X))) +end + """ interval_hull diff --git a/test/unit_box_approximation.jl b/test/unit_box_approximation.jl index 0d0c652b2a..e4a68e2c7f 100644 --- a/test/unit_box_approximation.jl +++ b/test/unit_box_approximation.jl @@ -33,6 +33,11 @@ for N in [Float64, Rational{Int}, Float32] E = EmptySet{N}() @test box_approximation(E) == E + # rectification + @test box_approximation(Rectification(EmptySet{N}())) isa EmptySet{N} + r = Rectification(Ball1(N[0, 0], N(1))) + @test box_approximation(r) == Hyperrectangle(low=N[0, 0], high=N[1, 1]) + # =================================================================== # Testing box_approximation_symmetric (= symmetric interval hull) # ===================================================================