Skip to content

Commit

Permalink
#2466 - Fallback conversion to VPolytope (#2467)
Browse files Browse the repository at this point in the history
* add generic conversion to VPolytope

* Update src/convert.jl

Co-authored-by: Christian Schilling <[email protected]>

* Update src/convert.jl

Co-authored-by: Christian Schilling <[email protected]>

Co-authored-by: Christian Schilling <[email protected]>
  • Loading branch information
mforets and schillic authored Dec 30, 2020
1 parent a4bb2f5 commit a9974e4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/lib/conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ convert(::Type{HPolytope}, ::AbstractPolytope)
convert(::Type{HPolytope}, ::VPolytope)
convert(::Type{VPolygon}, ::AbstractHPolygon)
convert(::Type{VPolygon}, ::AbstractPolytope)
convert(::Type{VPolytope}, ::LazySet)
convert(::Type{VPolytope}, ::AbstractPolytope)
convert(::Type{VPolytope}, ::HPolytope)
convert(::Type{Zonotope}, ::AbstractZonotope)
Expand Down
25 changes: 25 additions & 0 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,31 @@ function convert(::Type{HPolytope}, P::VPolytope)
return tohrep(P)
end

"""
convert(::Type{VPolytope}, X::LazySet; [prune]::Bool=true)
Generic conversion to polytope in vertex representation.
### Input
- `type` -- target type
- `X` -- set
- `prune` -- (optional, default: `true`) option to remove redundant vertices
### Output
The given set represented as a polytope in vertex representation.
### Algorithm
We compute the list of vertices of `X` and wrap the result in a polytope in
vertex representation, `VPolytope`. Use the option `prune` to select whether or not
to remove redundant vertices before constructing the polytope.
"""
function convert(::Type{VPolytope}, X::LazySet; prune::Bool=true)
return VPolytope(vertices_list(X, prune=prune))
end

"""
convert(::Type{VPolytope}, P::HPolytope)
Expand Down
6 changes: 6 additions & 0 deletions test/unit_Polytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,12 @@ for N in [Float64]
Q = minkowski_sum(P1, P2)
@test ispermutation(vertices_list(Q), [N[0, 0, 0], N[0, 1, 0], N[1, 0, 0], N[1, 1, 0]])

# fallback conversion to vertex representation
B3 = BallInf(zeros(N, 3), N(1))
U = Matrix(N(1)*I, 3, 3) * B3
Uv = convert(VPolytope, U, prune=false)
@test ispermutation(vertices_list(Uv), vertices_list(B3))

# -----------------
# mixed H-rep/V-rep
# -----------------
Expand Down

0 comments on commit a9974e4

Please sign in to comment.