From 3910423387cf261613a97630a953e73f03e43291 Mon Sep 17 00:00:00 2001 From: Marcelo Forets Date: Tue, 22 Dec 2020 11:12:56 -0300 Subject: [PATCH] #2453 - Vertices list of IntervalArithmetic types (#2457) * vertices list of IA types * typo * Update unit_Interval.jl --- src/Sets/Interval.jl | 16 ++++++++++++++++ test/unit_Interval.jl | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Sets/Interval.jl b/src/Sets/Interval.jl index b67bd3bcf0..0bb526d946 100644 --- a/src/Sets/Interval.jl +++ b/src/Sets/Interval.jl @@ -699,3 +699,19 @@ end return result end end + +function vertices_list(x::IntervalArithmetic.Interval{N}) where {N} + a = IntervalArithmetic.inf(x) + b = IntervalArithmetic.sup(x) + ST = IntervalArithmetic.SVector{1, N} + if _isapprox(a, b) + vlist = [ST(a)] + else + vlist = [ST(a), ST(b)] + end + return vlist +end + +function vertices_list(H::IntervalArithmetic.IntervalBox) + return vertices_list(convert(Hyperrectangle, H)) +end diff --git a/test/unit_Interval.jl b/test/unit_Interval.jl index 4145d086c1..b212e16e36 100644 --- a/test/unit_Interval.jl +++ b/test/unit_Interval.jl @@ -208,4 +208,12 @@ for N in Ns @test rectify(x) == Interval(N(0), N(2)) x = Interval(N(1), N(2)) @test rectify(x) == x + + # list of vertices of IA types + b = IA.IntervalBox(IA.Interval(0 , 1), IA.Interval(0, 1)) + vlistIB = vertices_list(b) + @test is_cyclic_permutation(vlistIB, [SA[N(1), N(1)], SA[N(0), N(1)], SA[N(1), N(0)], SA[N(0), N(0)]]) + + vlistI = vertices_list(b[1]) + @test is_cyclic_permutation(vlistI, [SA[N(0)], SA[N(1)]]) end