Skip to content

Commit

Permalink
better isstrictsubset for Interval
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Jun 28, 2024
1 parent ce5801f commit 9e720b4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/src/lib/sets/Interval.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Undocumented implementations:
* [`convex_hull`](@ref convex_hull(::LazySet, ::LazySet))
* [``](@ref ≈(::LazySet, ::LazySet))
* [`isequivalent`](@ref isequivalent(::LazySet, ::LazySet))
* [``](@ref ⊂(::LazySet, ::LazySet))

```@meta
CurrentModule = LazySets
Expand All @@ -93,7 +94,6 @@ Inherited from [`LazySet`](@ref):
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::LazySet))
* [`sample`](@ref sample(::LazySet, ::Int))
* [`==`](@ref ==(::LazySet, ::LazySet))
* [``](@ref ⊂(::LazySet, ::LazySet))

Inherited from [`AbstractPolyhedron`](@ref):
* [`is_polyhedral`](@ref is_polyhedral(::AbstractPolyhedron))
Expand Down
3 changes: 2 additions & 1 deletion src/Sets/Interval/IntervalModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import IntervalArithmetic as IA
convex_hull, diameter, dim, exponential_map, extrema, high, ,
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
Expand Down Expand Up @@ -66,6 +66,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")
Expand Down
11 changes: 11 additions & 0 deletions src/Sets/Interval/isstrictsubset.jl
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions test/Sets/Interval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,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
Expand Down

0 comments on commit 9e720b4

Please sign in to comment.