Skip to content

Commit

Permalink
polyhedron for empty VPolytope
Browse files Browse the repository at this point in the history
  • Loading branch information
mforets committed May 13, 2019
1 parent a828b93 commit 0c05331
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/VPolytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -496,19 +496,22 @@ Return an `VRep` polyhedron from `Polyhedra.jl` given a polytope in V-representa
- `backend` -- (optional, default: `default_polyhedra_backend(P, N)`) the polyhedral
computations backend, see [Polyhedra's documentation](https://juliapolyhedra.github.io/Polyhedra.jl/latest/installation.html#Getting-Libraries-1)
for further information
- `ambient_dimension` -- (default, optional: `dim(P)`) ambient dimension of the
polytope; required if the polytope is empty
### Output
A `VRep` polyhedron.
"""
function polyhedron(P::VPolytope{N};
backend=default_polyhedra_backend(P, N),
d::Int=dim(P)) where {N<:Real}
if d == -1 # empty polytope
error("cannot infer dimension of `VPolytope` constructed from no " *
"element, but it is required for `Polyhedra.polyhedron`")
ambient_dimension::Int=dim(P)) where {N<:Real}
if ambient_dimension == -1 # empty polytope
error("the conversion to a `Polyhedra.polyhedron` requires the ambient dimension " *
"of the `VPolytope` to be known, but it cannot be inferred from an empty set; " *
"try passing the ambient dimension as the keyword argument `ambient_dimension`")
end
return polyhedron(Polyhedra.vrep(P.vertices, d=d), backend)
return polyhedron(Polyhedra.vrep(P.vertices, d=ambient_dimension), backend)
end

end # quote
Expand Down
5 changes: 5 additions & 0 deletions test/unit_Polytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ for N in [Float64, Rational{Int}, Float32]

# list of constraints of a VPolytope; calculates tohrep
@test ispermutation(constraints_list(V), constraints_list(tohrep(V)))

# convert empty VPolytope to a polyhedron
Ve = VPolytope()
@test_throws ErrorException polyhedron(VPolytope()) # needs the ambient dim
p = polyhedron(VPolytope(), ambient_dimension=2)
end

# membership
Expand Down

0 comments on commit 0c05331

Please sign in to comment.