diff --git a/src/Approximations/overapproximate.jl b/src/Approximations/overapproximate.jl index e1a6e19477..fe998fc2f9 100644 --- a/src/Approximations/overapproximate.jl +++ b/src/Approximations/overapproximate.jl @@ -23,6 +23,26 @@ function overapproximate(X::S, ::Type{S}, args...; kwargs...) where {S<:LazySet} return X end +""" + overapproximate(S::LazySet, T::Type{<:LazySet}, [args]...; [kwargs]...) + +Default overapproximation method that falls back to `convert`. + +### Input + +- `X` -- set +- `Type{S}` -- target set type +- `args` -- further arguments +- `kwargs` -- further keyword arguments + +### Output + +The result of `convert`, or a `MethodError` if no such method exists. +""" +function overapproximate(X::T1, T2::Type{<:LazySet}, args...; kwargs...) where {T1<:LazySet} + return convert(T2, X, args...; kwargs...) +end + """ overapproximate(S::LazySet) @@ -130,9 +150,9 @@ for ST in LazySets.subtypes(LazySet, true) end @eval overapproximate(∅::EmptySet, ::Type{<:$ST}) = ∅ end +overapproximate(∅::EmptySet, ::Type{<:LazySet}, args...; kwargs...) = ∅ overapproximate(∅::EmptySet, ::Real) = ∅ overapproximate(∅::EmptySet, ::Type{<:HPolygon}, ::Real=Inf; kwargs...) = ∅ -overapproximate(∅::EmptySet, ::Type{<:EmptySet}, args...; kwargs...) = ∅ function overapproximate(∅::EmptySet, ::Type{<:Zonotope}, ::Union{AbstractDirections,Type{<:AbstractDirections}}; kwargs...) diff --git a/src/Approximations/overapproximate_zonotope.jl b/src/Approximations/overapproximate_zonotope.jl index 49a8a8ba09..c226bb35c6 100644 --- a/src/Approximations/overapproximate_zonotope.jl +++ b/src/Approximations/overapproximate_zonotope.jl @@ -209,26 +209,6 @@ function _overapproximate_convex_hull_zonotope_GGP09(X::ConvexHull{N}) where {N} return Zonotope(c, G) end -""" - overapproximate(lm::LinearMap{N, <:AbstractZonotope}, - ::Type{<:Zonotope}) where {N} - -Overapproximate a lazy linear map of a zonotopic set with a zonotope. - -### Input - -- `lm` -- lazy linear map of a zonotopic set -- `Zonotope` -- target set type - -### Output - -The tight zonotope corresponding to `lm`. -""" -function overapproximate(lm::LinearMap{N,<:AbstractZonotope}, - ::Type{<:Zonotope}) where {N} - return convert(Zonotope, lm) -end - # Given center, (dependent) generator matrix and exponent matrix of a (simple) # sparse polynomial zonotope, compute thew new center and generator matrix of # its zonotope overapproximation. diff --git a/test/Approximations/overapproximate.jl b/test/Approximations/overapproximate.jl index eef1b8648d..7208cb3e32 100644 --- a/test/Approximations/overapproximate.jl +++ b/test/Approximations/overapproximate.jl @@ -16,6 +16,10 @@ for N in [Float64, Rational{Int}, Float32] oa = overapproximate(b, Ball1, Hyperrectangle) @test oa isa Ball1 + # default fallback to `convert` + B = BallInf(c, N(1)) + overapproximate(B, Zonotope) == Zonotope(c, N[1 0; 0 1]) + # HPolygon approximation with box directions p = overapproximate(b, HPolygon) for d in [N[1, 0], N[-1, 0]]