Skip to content

Commit

Permalink
turn VPolytope constructor from VRep to convert method
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Dec 29, 2024
1 parent 1b8a259 commit 4170eba
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
3 changes: 3 additions & 0 deletions docs/src/lib/sets/VPolytope.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ VPolytope
```@docs
convert(::Type{VPolytope}, ::LazySet)
```
```julia
convert(::Type{VPolytope}, ::Polyhedra.VRep)
```

## Operations

Expand Down
12 changes: 0 additions & 12 deletions src/Sets/VPolytope/VPolytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,3 @@ function VPolytope(vertices_matrix::MT) where {N,MT<:AbstractMatrix{N}}
vertices = [vertices_matrix[:, j] for j in axes(vertices_matrix, 2)]
return VPolytope(vertices)
end

function load_Polyhedra_VPolytope()
return quote
using .Polyhedra: VRep

# VPolytope from a VRep
function VPolytope(P::VRep)
vertices = collect(Polyhedra.points(P))
return VPolytope(vertices)
end
end
end # load_Polyhedra_VPolytope
12 changes: 12 additions & 0 deletions src/Sets/VPolytope/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ remove redundant vertices before constructing the polytope.
function convert(::Type{VPolytope}, X::LazySet; prune::Bool=true)
return VPolytope(vertices_list(X; prune=prune))
end

function load_Polyhedra_convert_VPolytope()
return quote
using .Polyhedra: VRep

# VPolytope from a VRep
function convert(::Type{VPolytope}, P::VRep)
vertices = collect(Polyhedra.points(P))
return VPolytope(vertices)
end
end
end # load_Polyhedra_convert_VPolytope
2 changes: 1 addition & 1 deletion src/Sets/VPolytope/init_Polyhedra.jl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
eval(load_Polyhedra_VPolytope())
eval(load_Polyhedra_convert_VPolytope())
eval(load_Polyhedra_polyhedron())
3 changes: 1 addition & 2 deletions test/Sets/Polytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,8 @@ for N in [Float64, Rational{Int}, Float32]
@test_throws AssertionError extrema(p2, 1)

if test_suite_polyhedra
V = VPolytope(polyhedron(p))

# conversion to and from Polyhedra's VRep data structure
V = convert(VPolytope, polyhedron(p))
vl = vertices_list(V)
@test length(p.vertices) == length(vl) && vl p.vertices

Expand Down

0 comments on commit 4170eba

Please sign in to comment.