diff --git a/docs/src/lib/sets/EmptySet.md b/docs/src/lib/sets/EmptySet.md index 8fc5630ff7..f41c73091a 100644 --- a/docs/src/lib/sets/EmptySet.md +++ b/docs/src/lib/sets/EmptySet.md @@ -77,6 +77,7 @@ Undocumented implementations: * [`vertices_list`](@ref vertices_list(::LazySet)) * [`vertices`](@ref vertices(::LazySet)) * [`volume`](@ref volume(::LazySet)) +* [`distance`](@ref distance(::AbstractVector, ::LazySet)) * [`exponential_map`](@ref exponential_map(::AbstractMatrix, ::LazySet)) * [`∈`](@ref ∈(::AbstractVector, ::LazySet)) * [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::LazySet)) diff --git a/src/Sets/EmptySet/EmptySetModule.jl b/src/Sets/EmptySet/EmptySetModule.jl index 491b70bcbf..bbe9e228a0 100644 --- a/src/Sets/EmptySet/EmptySetModule.jl +++ b/src/Sets/EmptySet/EmptySetModule.jl @@ -4,6 +4,7 @@ using Reexport, Requires using ..LazySets: LazySet, ConvexSet, _witness_result_empty using Random: AbstractRNG, GLOBAL_RNG +using ReachabilityBase.Commutative: @commutative using ReachabilityBase.Comparison: _rtol using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Iteration: EmptyIterator diff --git a/src/Sets/EmptySet/distance.jl b/src/Sets/EmptySet/distance.jl index 4c5f38f100..48f8d3033b 100644 --- a/src/Sets/EmptySet/distance.jl +++ b/src/Sets/EmptySet/distance.jl @@ -1,3 +1,14 @@ +# distance point <-> set + +@commutative function distance(x::AbstractVector, ∅::EmptySet; p::Real=2) + @assert length(x) == dim(∅) "incompatible dimensions $(length(x)) and $(dim(∅))" + + N = promote_type(eltype(x), eltype(∅)) + return N(Inf) +end + +# distance set <-> set + function distance(∅₁::EmptySet, ∅₂::EmptySet; p::Real=2.0) return _distance_emptyset(∅₁, ∅₂; p=p) end diff --git a/test/Sets/EmptySet.jl b/test/Sets/EmptySet.jl index 6dc6e6889b..4ab91e5972 100644 --- a/test/Sets/EmptySet.jl +++ b/test/Sets/EmptySet.jl @@ -156,6 +156,13 @@ for N in [Float64, Rational{Int}, Float32] E2 = affine_map(ones(N, 3, 2), E, N[1, 1, 3]) @test E2 isa EmptySet{N} && dim(E2) == 3 + # distance (between point and set) + @test_throws AssertionError distance(E, N[0]) + x = N[0, 0] + for res in (distance(E, x), distance(E, x)) + @test res isa N && res == N(Inf) + end + # exponential_map / linear_map for f in (exponential_map, linear_map) @test_throws AssertionError f(ones(N, 2, 3), E) @@ -231,7 +238,7 @@ for N in [Float64, Rational{Int}, Float32] E2 = difference(B, E) @test E2 isa BallInf{N} && E2 == B - # distance + # distance (between sets) res = distance(E, E) @test res isa N && res == N(Inf) E2 = EmptySet{N}(3)