From e040b419b8ea5cc628baee5be811cd80749770be Mon Sep 17 00:00:00 2001 From: schillic Date: Sat, 4 Jan 2025 18:56:40 +0100 Subject: [PATCH 1/2] allow to construct H-rep from mixed numeric types --- src/Sets/HalfSpace/HalfSpaceModule.jl | 9 +++++++-- test/Sets/Polygon.jl | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Sets/HalfSpace/HalfSpaceModule.jl b/src/Sets/HalfSpace/HalfSpaceModule.jl index c43cf5c582..98fbd0d70c 100644 --- a/src/Sets/HalfSpace/HalfSpaceModule.jl +++ b/src/Sets/HalfSpace/HalfSpaceModule.jl @@ -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") diff --git a/test/Sets/Polygon.jl b/test/Sets/Polygon.jl index a0286bd22e..1605cb0e10 100644 --- a/test/Sets/Polygon.jl +++ b/test/Sets/Polygon.jl @@ -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) From f15b514c71bbcb490b6fc73c211c26b37c755cdb Mon Sep 17 00:00:00 2001 From: schillic Date: Sat, 4 Jan 2025 18:56:50 +0100 Subject: [PATCH 2/2] fix error message --- src/Convert/convert.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Convert/convert.jl b/src/Convert/convert.jl index 0879ba6ab8..3f60d156c6 100644 --- a/src/Convert/convert.jl +++ b/src/Convert/convert.jl @@ -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