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

Allow to construct H-rep from mixed numeric types #3776

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/Convert/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ for T in subtypes(AbstractHPolygon, true)
@assert dim(X) == 2 "set must be two-dimensional for conversion, but it " *
"has dimension $(dim(X))"
if check_boundedness && !isbounded(X)
throw(ArgumentError("expected a bounded set for conversion to `$T`"))
throw(ArgumentError("expected a bounded set for conversion to `$($T)`"))
end
return $T(constraints_list(X); prune=prune)
end
Expand Down
9 changes: 7 additions & 2 deletions src/Sets/HalfSpace/HalfSpaceModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,14 @@ function is_tighter_same_dir_2D(c1::HalfSpace,
end

# TODO: after #2032, #2041 remove use of this function
_normal_Vector(c::HalfSpace) = HalfSpace(convert(Vector, c.a), c.b)
_normal_Vector(C::Vector{<:HalfSpace}) = [_normal_Vector(c) for c in C]
_normal_Vector(P::LazySet) = _normal_Vector(constraints_list(P))
_normal_Vector(c::HalfSpace) = HalfSpace(convert(Vector, c.a), c.b)
_normal_Vector(C::Vector{<:HalfSpace{N}}) where {N} = [_normal_Vector(c) for c in C]

function _normal_Vector(C::Vector{<:HalfSpace})
N = promote_type([eltype(c) for c in C]...)
return [HalfSpace(convert(Vector{N}, c.a), N(c.b)) for c in C]
end

include("init.jl")

Expand Down
4 changes: 4 additions & 0 deletions test/Sets/Polygon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,10 @@ rand(HPolygonOpt)
@test HPolygonOpt() isa HPolygonOpt{Float64,Vector{Float64}}
@test VPolygon() isa VPolygon{Float64}

# construction from constraints of mixed numeric types
P = HPolygon([HalfSpace([1.0, 1.0], 1.0), HalfSpace(Float16[1, 1], Float16(1))])
@test P isa HPolygon{Float64}

# isoperationtype
@test !isoperationtype(HPolygon)
@test !isoperationtype(HPolygonOpt)
Expand Down
Loading