Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#336 - Revise conversion from HPolytope to HPolygon #341

Merged
merged 3 commits into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}