From 4be194212a7a3d02bacf04b1a892f15c1b3f6291 Mon Sep 17 00:00:00 2001 From: schillic Date: Fri, 13 Dec 2024 19:15:48 +0100 Subject: [PATCH] EmptySet: redefine norm/radius/diameter --- src/Sets/EmptySet/diameter.jl | 5 +++-- src/Sets/EmptySet/norm.jl | 5 +++-- src/Sets/EmptySet/radius.jl | 5 +++-- test/Sets/EmptySet.jl | 6 +++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Sets/EmptySet/diameter.jl b/src/Sets/EmptySet/diameter.jl index 1e57ef52bd..ba191aac11 100644 --- a/src/Sets/EmptySet/diameter.jl +++ b/src/Sets/EmptySet/diameter.jl @@ -1,3 +1,4 @@ -function diameter(::EmptySet, ::Real=Inf) - throw(ArgumentError("the diameter of an empty set is undefined")) +function diameter(∅::EmptySet, ::Real=Inf) + N = eltype(∅) + return zero(N) end diff --git a/src/Sets/EmptySet/norm.jl b/src/Sets/EmptySet/norm.jl index 53765124de..a1d2d9df1b 100644 --- a/src/Sets/EmptySet/norm.jl +++ b/src/Sets/EmptySet/norm.jl @@ -1,3 +1,4 @@ -function norm(::EmptySet, ::Real=Inf) - throw(ArgumentError("the norm of an empty set is undefined")) +function norm(∅::EmptySet, ::Real=Inf) + N = eltype(∅) + return zero(N) end diff --git a/src/Sets/EmptySet/radius.jl b/src/Sets/EmptySet/radius.jl index 6727e5e370..f72e23c1a0 100644 --- a/src/Sets/EmptySet/radius.jl +++ b/src/Sets/EmptySet/radius.jl @@ -1,3 +1,4 @@ -function radius(::EmptySet, ::Real=Inf) - throw(ArgumentError("the radius of an empty set is undefined")) +function radius(∅::EmptySet, ::Real=Inf) + N = eltype(∅) + return zero(N) end diff --git a/test/Sets/EmptySet.jl b/test/Sets/EmptySet.jl index 0892a36a25..ce68c1e0b3 100644 --- a/test/Sets/EmptySet.jl +++ b/test/Sets/EmptySet.jl @@ -37,9 +37,9 @@ for N in [Float64, Rational{Int}, Float32] # an_element/norm/radius/diameter functions @test_throws ArgumentError an_element(E) - @test_throws ArgumentError norm(E) - @test_throws ArgumentError radius(E) - @test_throws ArgumentError diameter(E) + @test norm(E) == N(0) + @test radius(E) == N(0) + @test diameter(E) == N(0) # vertices / vertices_list @test collect(vertices(E)) == vertices_list(E) == Vector{Vector{N}}()