From a7fcbc1fe3394cf91f2c5d5b68dce966f51e8ae4 Mon Sep 17 00:00:00 2001 From: schillic Date: Mon, 10 Jun 2024 22:47:16 +0200 Subject: [PATCH] better isstrictsubset for Interval --- docs/src/lib/sets/Interval.md | 2 +- src/Sets/Interval/IntervalModule.jl | 3 ++- src/Sets/Interval/isstrictsubset.jl | 11 +++++++++++ test/Sets/Interval.jl | 11 +++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/Sets/Interval/isstrictsubset.jl diff --git a/docs/src/lib/sets/Interval.md b/docs/src/lib/sets/Interval.md index 32a569e6704..e03d486b83f 100644 --- a/docs/src/lib/sets/Interval.md +++ b/docs/src/lib/sets/Interval.md @@ -84,6 +84,7 @@ Undocumented implementations: * [`convex_hull`](@ref convex_hull(::LazySet, ::LazySet)) * [`≈`](@ref ≈(::LazySet, ::LazySet)) * [`isequivalent`](@ref isequivalent(::LazySet, ::LazySet)) +* [`⊂`](@ref ⊂(::LazySet, ::LazySet)) ```@meta CurrentModule = LazySets @@ -99,7 +100,6 @@ Inherited from [`LazySet`](@ref): * [`vertices`](@ref vertices(::LazySet)) * [`sample`](@ref sample(::LazySet, ::Int)) * [`==`](@ref ==(::LazySet, ::LazySet)) -* [`⊂`](@ref ⊂(::LazySet, ::LazySet)) Inherited from [`AbstractPolyhedron`](@ref): * [`is_polyhedral`](@ref is_polyhedral(::AbstractPolyhedron)) diff --git a/src/Sets/Interval/IntervalModule.jl b/src/Sets/Interval/IntervalModule.jl index 2fa17338cd4..0711f7ce7f6 100644 --- a/src/Sets/Interval/IntervalModule.jl +++ b/src/Sets/Interval/IntervalModule.jl @@ -16,7 +16,7 @@ import IntervalArithmetic as IA is_interior_point, isoperationtype, linear_map, low, norm, permute, project, rand, rectify, reflect, scale, ρ, σ, translate, vertices_list, volume, - difference, intersection, ≈, isdisjoint, isequivalent, ⊆, + difference, intersection, ≈, isdisjoint, isequivalent, ⊂, ⊆, minkowski_difference, minkowski_sum @reexport import ..LazySets: chebyshev_center_radius, isflat, ngens, plot_recipe, radius_hyperrectangle, split @@ -67,6 +67,7 @@ include("intersection.jl") include("isapprox.jl") include("isdisjoint.jl") include("isequivalent.jl") +include("isstrictsubset.jl") include("issubset.jl") include("minkowski_difference.jl") include("minkowski_sum.jl") diff --git a/src/Sets/Interval/isstrictsubset.jl b/src/Sets/Interval/isstrictsubset.jl new file mode 100644 index 00000000000..ea4bcbe02ae --- /dev/null +++ b/src/Sets/Interval/isstrictsubset.jl @@ -0,0 +1,11 @@ +function ⊂(X::Interval, Y::Interval, witness::Bool=false) + if min(X) < min(Y) || max(X) > max(Y) + return _witness_result_empty(witness, false, X, Y) + end + if min(X) > min(Y) + return witness ? (true, low(Y)) : true + elseif max(Y) > max(X) + return witness ? (true, high(Y)) : true + end + return _witness_result_empty(witness, false, X, Y) +end diff --git a/test/Sets/Interval.jl b/test/Sets/Interval.jl index 6e2d905788f..eb99e938810 100644 --- a/test/Sets/Interval.jl +++ b/test/Sets/Interval.jl @@ -261,12 +261,23 @@ for N in [Float64, Float32, Rational{Int}] I13 = Interval(N(1), N(3)) I02 = Interval(N(0), N(2)) I24 = Interval(N(2), N(4)) + I03 = Interval(N(0), N(3)) + I14 = Interval(N(1), N(4)) for I in (I02, I24) res, w = ⊆(I13, I, true) @test !(⊆(I13, I)) && !res && w ∈ I13 && w ∉ I end res, w = ⊆(I13, I13, true) @test ⊆(I13, I13) && res && w == N[] + # isstrictsubset + for I in (I02, I24, I13) + res, w = ⊂(I13, I, true) + @test !(⊂(I13, I)) && !res && w == N[] + end + for I in (I03, I14) + res, w = ⊂(I13, I, true) + @test ⊂(I13, I) && res && w ∈ I && w ∉ I13 + end # permute @test permute(x, [1]) == x