Skip to content

Commit

Permalink
vertices list for degenerate interval (#2459)
Browse files Browse the repository at this point in the history
  • Loading branch information
mforets authored Dec 22, 2020
1 parent 625a20b commit 7a12227
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Sets/Interval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down
4 changes: 4 additions & 0 deletions test/unit_Interval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7a12227

Please sign in to comment.