Skip to content

Commit

Permalink
Add constructors to CDDPolyhedron
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jul 26, 2017
1 parent b5af781 commit cc95315
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ changeboth{N, T, S, NewT}(::Type{CDDGeneratorMatrix{N, T, S}}, NewN, ::Type{NewT
decomposedfast(ine::CDDGeneratorMatrix) = false

const CDDMatrix{N, T, S} = Union{CDDInequalityMatrix{N, T, S}, CDDGeneratorMatrix{N, T, S}}
(::Type{CDDMatrix{N, T}}){N, T}(rep) = CDDMatrix{N, T, mytype(T)}(rep)
CDDMatrix{N, T}(rep) where {N, T} = CDDMatrix{N, T, mytype(T)}(rep)

function linset(matrix::CDDMatrix)
mat = unsafe_load(matrix.matrix)
Expand Down Expand Up @@ -164,13 +164,13 @@ CDDInequalityMatrix{N,T}(rep::Rep{N,T}) = CDDInequalityMatrix{N,polytypefor(T),

CDDInequalityMatrix{T}(matrix::Ptr{Cdd_MatrixData{T}}) = CDDInequalityMatrix{unsafe_load(matrix).colsize-1, polytype(T), T}(matrix)

function (::Type{CDDInequalityMatrix{N, T, S}}){N,T,S}(it::HRepIterator{N, T})
function CDDInequalityMatrix{N, T, S}(it::HRepIterator{N, T}) where {N, T, S}
CDDInequalityMatrix(initmatrix(true, it))
end
function (::Type{CDDInequalityMatrix{N, T, S}}){N,T,S}(eqs, ineqs)
function CDDInequalityMatrix{N, T, S}(eqs, ineqs) where {N, T, S}
CDDInequalityMatrix(initmatrix(true, eqs, ineqs))
end
function (::Type{CDDInequalityMatrix{N, T, S}}){N,T,S}(; eqs=nothing, ineqs=nothing)
function CDDInequalityMatrix{N, T, S}(; eqs=nothing, ineqs=nothing) where {N, T, S}
CDDInequalityMatrix{N, T, S}(eqs, ineqs)
end

Expand Down Expand Up @@ -288,13 +288,13 @@ function Base.copy{N, T, S}(matrix::CDDGeneratorMatrix{N, T, S})
CDDGeneratorMatrix{N, T, S}(dd_matrixcopy(matrix.matrix))
end

function (::Type{CDDGeneratorMatrix{N,T,S}}){N,T,S}(it::VRepIterator{N, T})
function CDDGeneratorMatrix{N,T,S}(it::VRepIterator{N, T}) where {N, T, S}
CDDGeneratorMatrix(initmatrix(false, it))
end
function (::Type{CDDGeneratorMatrix{N,T,S}}){N,T,S}(points, rays)
function CDDGeneratorMatrix{N,T,S}(points, rays) where {N, T, S}
CDDGeneratorMatrix(initmatrix(false, rays, points))
end
function (::Type{CDDGeneratorMatrix{N,T,S}}){N,T,S}(; rays=nothing, points=nothing)
function CDDGeneratorMatrix{N,T,S}(; rays=nothing, points=nothing) where {N, T, S}
CDDGeneratorMatrix{N, T, S}(points, rays)
end

Expand Down
10 changes: 6 additions & 4 deletions src/polyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ function polytypeforprecision(precision::Symbol)
precision == :float ? Cdouble : Rational{BigInt}
end

function polyhedron{N}(repit::Union{Representation{N},HRepIterator{N},VRepIterator{N}}, lib::CDDLibrary)
function Polyhedra.polyhedron{N}(repit::Union{Representation{N},HRepIterator{N},VRepIterator{N}}, lib::CDDLibrary)
T = polytypeforprecision(lib.precision)
CDDPolyhedron{N, T}(repit)
end
function polyhedron(lib::CDDLibrary; eqs=nothing, ineqs=nothing, points=nothing, rays=nothing)
function Polyhedra.polyhedron(lib::CDDLibrary; eqs=nothing, ineqs=nothing, points=nothing, rays=nothing)
its = [eqs, ineqs, points, rays]
i = findfirst(x -> !(x === nothing), its)
if i == 0
Expand All @@ -146,8 +146,10 @@ getlibraryfor{T<:AbstractFloat}(::CDDPolyhedron, n::Int, ::Type{T}) = CDDLibrary
Base.convert{N, T}(::Type{CDDPolyhedron{N, T}}, rep::HRepresentation{N}) = CDDPolyhedron{N, T}(cddmatrix(T, rep))
Base.convert{N, T}(::Type{CDDPolyhedron{N, T}}, rep::VRepresentation{N}) = CDDPolyhedron{N, T}(cddmatrix(T, rep))

(::Type{CDDPolyhedron{N, T}}){N, T}(it::HRepIterator{N,T}) = CDDPolyhedron{N, T}(CDDInequalityMatrix{N,T,mytype(T)}(it))
(::Type{CDDPolyhedron{N, T}}){N, T}(it::VRepIterator{N,T}) = CDDPolyhedron{N, T}(CDDGeneratorMatrix{N,T,mytype(T)}(it))
CDDPolyhedron{N, T}(it::HRepIterator{N, T}) where {N, T} = CDDPolyhedron{N, T}(CDDInequalityMatrix{N, T, mytype(T)}(it))
CDDPolyhedron{N, T}(eqs::EqIterator{N, T}, ineqs::IneqIterator{N, T}) where {N, T} = CDDPolyhedron{N, T}(CDDInequalityMatrix{N, T, mytype(T)}(eqs, ineqs))
CDDPolyhedron{N, T}(it::VRepIterator{N, T}) where {N, T} = CDDPolyhedron{N, T}(CDDGeneratorMatrix{N, T, mytype(T)}(it))
CDDPolyhedron{N, T}(ps::PointIterator{N, T}, rs::RayIterator{N, T}) where {N, T} = CDDPolyhedron{N, T}(CDDGeneratorMatrix{N, T, mytype(T)}(ps, rs))

function (::Type{CDDPolyhedron{N, T}}){N, T}(; eqs=nothing, ineqs=nothing, points=nothing, rays=nothing)
noth = eqs === nothing && ineqs === nothing
Expand Down

0 comments on commit cc95315

Please sign in to comment.