diff --git a/docs/src/lib/sets/HPolyhedron.md b/docs/src/lib/sets/HPolyhedron.md index c4b9740afa..13b67af203 100644 --- a/docs/src/lib/sets/HPolyhedron.md +++ b/docs/src/lib/sets/HPolyhedron.md @@ -12,7 +12,7 @@ HPolyhedron ```@docs convert(::Type{HPolyhedron}, ::LazySet) -convert(::Type{HPolyhedron}, ::HRep{N}) where {N} +convert(::Type{HPolyhedron}, ::HRep) ``` ## Operations diff --git a/src/Sets/HPolyhedron/convert.jl b/src/Sets/HPolyhedron/convert.jl index 52ee979a1e..a371c86e99 100644 --- a/src/Sets/HPolyhedron/convert.jl +++ b/src/Sets/HPolyhedron/convert.jl @@ -35,9 +35,10 @@ end function load_Polyhedra_convert_HPolyhedron() return quote using .Polyhedra: HRep + using ..HPolytopeModule: _convert_HPoly """ - convert(::Type{HPolyhedron}, P::HRep{N}) where {N} + convert(::Type{HPolyhedron}, P::HRep) Convert an `HRep` polyhedron from `Polyhedra.jl` to a polyhedron in constraint representation . @@ -51,19 +52,8 @@ function load_Polyhedra_convert_HPolyhedron() An `HPolyhedron`. """ - function convert(::Type{HPolyhedron}, P::HRep{N}) where {N} - VN = Polyhedra.hvectortype(P) - constraints = Vector{HalfSpace{N,VN}}() - for hi in Polyhedra.allhalfspaces(P) - a, b = hi.a, hi.β - if isapproxzero(norm(a)) - @assert b >= zero(N) "the half-space is inconsistent since it has a zero " * - "normal direction but the constraint is negative" - continue - end - push!(constraints, HalfSpace(a, b)) - end - return HPolyhedron(constraints) + function convert(::Type{HPolyhedron}, P::HRep) + return _convert_HPoly(HPolyhedron, P) end end end # load_Polyhedra_convert_HPolyhedron diff --git a/src/Sets/HPolytope/convert.jl b/src/Sets/HPolytope/convert.jl index cd57110c3d..8da3ee8dd5 100644 --- a/src/Sets/HPolytope/convert.jl +++ b/src/Sets/HPolytope/convert.jl @@ -36,7 +36,11 @@ function load_Polyhedra_convert_HPolytope() return quote using .Polyhedra: HRep - function convert(::Type{HPolytope}, P::HRep{N}) where {N} + function convert(::Type{HPolytope}, P::HRep) + return _convert_HPoly(HPolytope, P) + end + + function _convert_HPoly(T, P::HRep{N}) where {N} VT = Polyhedra.hvectortype(P) constraints = Vector{HalfSpace{N,VT}}() for hi in Polyhedra.allhalfspaces(P) @@ -48,7 +52,7 @@ function load_Polyhedra_convert_HPolytope() end push!(constraints, HalfSpace(a, b)) end - return HPolytope(constraints) + return T(constraints) end end end # load_Polyhedra_convert_HPolytope