Skip to content

Commit

Permalink
Merge pull request #341 from JuliaReach/mforets/336
Browse files Browse the repository at this point in the history
#336 - Revise conversion from HPolytope to HPolygon
  • Loading branch information
mforets authored May 17, 2018
2 parents 794c3e7 + 9f469b5 commit 89dffa7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/HPolygonOpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@ HPolygonOpt(constraints::Vector{LinearConstraint{N}},
ind::Int=1) where {N<:Real} =
HPolygonOpt{N}(constraints, ind)

# constructor for an HPolygon with no constraints
HPolygonOpt{N}() where {N<:Real} = HPolygonOpt{N}(Vector{LinearConstraint{N}}(0), 1)

# constructor for an HPolygon with no constraints of type Float64
HPolygonOpt() = HPolygonOpt{Float64}()

# conversion constructor
HPolygonOpt(S::LazySet) = convert(HPolygonOpt, S)



# --- LazySet interface functions ---


Expand Down
9 changes: 7 additions & 2 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ Convert from 2D polytope in H-representation to polygon in H-representation.
The 2D polytope represented as polygon.
"""
function convert(::Type{HPOLYGON},
P::HPolytope) where {HPOLYGON<:AbstractHPolygon}
P::HPolytope{N}) where {N, HPOLYGON<:AbstractHPolygon}
if dim(P) != 2
error("polytope must be 2D for conversion")
end
return HPOLYGON(P.constraints)
H = HPOLYGON{N}()
for ci in constraints_list(P)
# guarantee that the edges are correctly sorted for storage
addconstraint!(H, ci)
end
return H
end

"""
Expand Down
5 changes: 3 additions & 2 deletions test/unit_Polygon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,6 @@ for N in [Float64, Float32, Rational{Int}]
end
end

# default Float64 constructor
HPolygon()
# default Float64 constructors
@test HPolygon() isa LazySets.HPolygon{Float64}
@test HPolygonOpt() isa LazySets.HPolygonOpt{Float64}

0 comments on commit 89dffa7

Please sign in to comment.