Skip to content

Commit

Permalink
EmptySet: add 'distance' to point
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Dec 29, 2024
1 parent 8eaf91e commit 7ae3fb2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/src/lib/sets/EmptySet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions src/Sets/EmptySet/EmptySetModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/Sets/EmptySet/distance.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 8 additions & 1 deletion test/Sets/EmptySet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,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)
Expand Down Expand Up @@ -229,7 +236,7 @@ for N in [Float64, Rational{Int}, Float32]
E2 = difference(B, E)
@test E2 isa BallInf{N} && E2 == B

# distance
# distance (between sets)
@test_throws ArgumentError distance(E, E)
E2 = EmptySet{N}(3)
@test_throws AssertionError distance(E, E2)
Expand Down

0 comments on commit 7ae3fb2

Please sign in to comment.