From 7a122275172b1ea9aea70619ef9acb7d165b7ccb Mon Sep 17 00:00:00 2001 From: Marcelo Forets Date: Tue, 22 Dec 2020 11:12:38 -0300 Subject: [PATCH] vertices list for degenerate interval (#2459) --- src/Sets/Interval.jl | 7 +++++-- test/unit_Interval.jl | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Sets/Interval.jl b/src/Sets/Interval.jl index 096c9491e1..b67bd3bcf0 100644 --- a/src/Sets/Interval.jl +++ b/src/Sets/Interval.jl @@ -384,10 +384,13 @@ Return the list of vertices of this interval. ### Output -The list of vertices of the interval represented as two one-dimensional vectors. +The list of vertices of the interval represented as two one-dimensional vectors, +or just one if the interval is degenerate (the endpoints match within the tolerance). """ function vertices_list(x::Interval) - return [[min(x)], [max(x)]] + a = min(x) + b = max(x) + return _isapprox(a, b) ? [[a]] : [[a], [b]] end """ diff --git a/test/unit_Interval.jl b/test/unit_Interval.jl index 0b319ea7be..4145d086c1 100644 --- a/test/unit_Interval.jl +++ b/test/unit_Interval.jl @@ -29,6 +29,10 @@ for N in Ns @test min(x) == N(0) && max(x) == N(1) v = vertices_list(x) @test N[0] in v && N[1] in v + + # vertices list for degenerate interval + @test vertices_list(Interval(N(0), N(0))) == [[N(0)]] + # test interface method an_element and membership @test an_element(x) ∈ x # test containment