Skip to content

Commit

Permalink
binary convex_hull with EmptySet: use unary
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Apr 24, 2024
1 parent 72083a8 commit 5ae7e26
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/ConcreteOperations/convex_hull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,7 @@ function convex_hull(P1::HPoly, P2::HPoly;
end

@commutative function convex_hull(X::LazySet, ::EmptySet)
@assert isconvextype(typeof(X)) "this implementation requires a convex " *
"set as input"
return X
return convex_hull(X)
end

convex_hull(∅::EmptySet, ::EmptySet) =
Expand Down
21 changes: 19 additions & 2 deletions test/ConcreteOperations/convex_hull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ for N in [Float64, Rational{Int}]
@test convex_hull([[N(1), N(0)], [N(1), N(0)]]) == [[N(1), N(0)]]

# test corner cases with one and two vectors (see #876)
p1 = [1.0, 2.0]
p2 = [1.0, 3.0]
p1 = N[1, 2]
p2 = N[1, 3]
@test convex_hull([p1]) == [p1]
@test ispermutation(convex_hull([p1, p2]), [p1, p2])

Expand Down Expand Up @@ -168,4 +168,21 @@ for N in [Float64, Rational{Int}]
@test isequivalent(convex_hull(U), P)
U = UnionSetArray([convert(HPolytope, V1), convert(HPolytope, V2)])
@test isequivalent(convex_hull(U), P)

# ==========================
# Unary concrete convex hull
# ==========================

# convex set
S = Singleton(N[1])
@test convex_hull(S) == S

# non-convex set
P = Polygon([N[0, 0], N[0, 2], N[2, 2], N[2, 0], N[1, 1]])
Pc = VPolygon([N[0, 0], N[2, 0], N[2, 2], N[0, 2]])
@test convex_hull(P) == Pc

# binary convex hull with an empty set is identical to unary
@test convex_hull(S, EmptySet{N}(1)) == convex_hull(EmptySet{N}(1), S) == S
@test convex_hull(P, EmptySet{N}(1)) == convex_hull(EmptySet{N}(1), P) == Pc
end

0 comments on commit 5ae7e26

Please sign in to comment.