diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 054444b..1e95dd4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -24,7 +24,6 @@ jobs: matrix: version: - '1.10' - - '1.6' - 'nightly' os: - ubuntu-latest diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..4a1933d --- /dev/null +++ b/NEWS.md @@ -0,0 +1,5 @@ +# IntervalBoxes.jl NEWS.md + +## v0.2.0 +- Change to square intersection and union symbols + - Exported from `IntervalArithmetic.jl` since v0.22.12 diff --git a/Project.toml b/Project.toml index de0cfbf..9725c65 100644 --- a/Project.toml +++ b/Project.toml @@ -1,14 +1,14 @@ name = "IntervalBoxes" uuid = "43d83c95-ebbb-40ec-8188-24586a1458ed" authors = ["David Sanders and contributors"] -version = "0.1.1" +version = "0.2.0" [deps] IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" [compat] -IntervalArithmetic = "0.22" +IntervalArithmetic = "0.22.12" StaticArrays = "1" julia = "1" diff --git a/README.md b/README.md index 5201570..da7746f 100644 --- a/README.md +++ b/README.md @@ -35,19 +35,19 @@ We treat `IntervalBox`es as sets as much as possible, and extend Julia's set ope to act on these objects: ```jl -julia> X ∩ Y +julia> X ⊓ Y [2.0, 3.0]_trv × [4.0, 5.0]_trv -julia> X ∪ Y +julia> X ⊔ Y [1.0, 5.0]_trv × [2.0, 6.0]_trv julia> using StaticArrays -julia> SVector(2, 5) ∈ X ∩ Y +julia> SVector(2, 5) ∈ X ⊓ Y true ``` -Note that the `∪` operator produces the *interval hull* of the union +Note that the `⊔` operator produces the *interval hull* of the union (i.e. the smallest interval box that contains the union). One-dimensional intervals can also be treated as sets in the same way, as follows. @@ -59,7 +59,7 @@ julia> x = IntervalBox(1..3) julia> y = IntervalBox(2..4) [2.0, 4.0]¹ -julia> x ∩ y +julia> x ⊓ y [2.0, 3.0]¹ ``` diff --git a/src/IntervalBoxes.jl b/src/IntervalBoxes.jl index 7495e21..b1971ab 100644 --- a/src/IntervalBoxes.jl +++ b/src/IntervalBoxes.jl @@ -7,13 +7,17 @@ import IntervalArithmetic: emptyinterval, bisect, diam, hull, mid, mince, bareinterval, isinterior, isbounded +import IntervalArithmetic.Symbols: ⊓, ⊔ + import Base: - ∩, ∪, ⊆, +, -, *, /, ==, !=, eltype, length, size, getindex, setindex, iterate, + ⊆, +, -, *, /, ==, !=, eltype, length, size, getindex, setindex, iterate, broadcasted, setdiff, big, isempty, zero export IntervalBox export × + + include("intervalbox.jl") include("arithmetic.jl") include("setdiff.jl") diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 24c5529..c7104e4 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -16,6 +16,9 @@ Base.:∈(v::AbstractVector, X::IntervalBox) = all(in_interval.(v, X)) +⊓(X::IntervalBox, Y::IntervalBox) = IntervalBox( X.v .⊓ Y.v ) +⊔(X::IntervalBox, Y::IntervalBox) = IntervalBox( X.v .⊔ Y.v ) + # broadcasting: # wrap decides whether to wrap the result in an IntervalBox or not, based on the return type @@ -32,7 +35,7 @@ Base.size(X::IntervalBox{2,Float64}) = (2,) @inline broadcasted(f, x, y, Z::IntervalBox) = wrap(f.(x, y, Z.v)) @inline broadcasted(f, x, Y::IntervalBox, z) = wrap(f.(x, Y.v, z)) -for op in (:+, :-, :∩, :∪, :⊆, :isinterior, :dot, :setdiff, :×) +for op in (:+, :-, :⊓, :⊔, :⊆, :isinterior, :dot, :setdiff, :×) @eval $(op)(a::SVector, b::IntervalBox) = $(op)(IntervalBox(a), b) @eval $(op)(a::IntervalBox, b::SVector) = $(op)(a, IntervalBox(b)) end diff --git a/src/intervalbox.jl b/src/intervalbox.jl index 9bec1bf..e6566c8 100644 --- a/src/intervalbox.jl +++ b/src/intervalbox.jl @@ -82,16 +82,16 @@ big(X::IntervalBox) = big.(X) ⊆(X::IntervalBox{N}, Y::IntervalBox{N}) where {N} = all(issubset_interval.(X, Y)) -∩(X::IntervalBox{N}, Y::IntervalBox{N}) where {N} = +⊓(X::IntervalBox{N}, Y::IntervalBox{N}) where {N} = IntervalBox(intersect_interval.(X.v, Y.v)) -∪(X::IntervalBox{N}, Y::IntervalBox{N}) where {N} = +⊔(X::IntervalBox{N}, Y::IntervalBox{N}) where {N} = IntervalBox(hull.(X.v, Y.v)) ∈(X::AbstractVector, Y::IntervalBox{N,T}) where {N,T} = all(in_interval.(X, Y)) ∈(X, Y::IntervalBox{N,T}) where {N,T} = throw(ArgumentError("$X ∈ $Y is not defined")) # mixing intervals with one-dimensional interval boxes -# for op in (:⊆, :⊂, :⊃, :∩, :∪) +# for op in (:⊆, :⊂, :⊃, :⊓, :⊔) # @eval $(op)(a::Interval, X::IntervalBox{1}) = $(op)(a, first(X)) # @eval $(op)(X::IntervalBox{1}, a::Interval) = $(op)(first(X), a) # end @@ -163,7 +163,7 @@ hull(a::Vector{IntervalBox{N,T}}) where {N,T} = hull(a...) Return the zero interval box of dimension `N` in the numeric type `T`. """ -zero(x::IntervalBox) where {N, T} = zero.(x) +zero(x::IntervalBox) = zero.(x) """ symmetric_box(N, T) diff --git a/src/setdiff.jl b/src/setdiff.jl index 979950f..015bb97 100644 --- a/src/setdiff.jl +++ b/src/setdiff.jl @@ -42,7 +42,7 @@ expand each direction in turn. """ function setdiff(A::IntervalBox{N,T}, B::IntervalBox{N,T}) where {N,T} - intersection = A ∩ B + intersection = A ⊓ B isempty(intersection) && return [A] result_list = fill(emptyinterval.(A), 2 * N) diff --git a/test/multidim.jl b/test/multidim.jl index 75f5083..96389b0 100644 --- a/test/multidim.jl +++ b/test/multidim.jl @@ -53,29 +53,29 @@ using Test @test B ⊇ A.v @test !(A ⊇ B) - @test A ∩ B == A - @test A.v ∩ B == A - @test A ∩ B.v == A + @test A ⊓ B == A + @test A.v ⊓ B == A + @test A ⊓ B.v == A - @test A ∪ B == B - @test A.v ∪ B == B - @test A ∪ B.v == B + @test A ⊔ B == B + @test A.v ⊔ B == B + @test A ⊔ B.v == B end x = IntervalBox(0.5..3) a = IntervalBox(1..2) @test !(x ⊆ a) && a ⊆ x - @test x ∩ a == a ∩ x - @test x ∪ a == a ∪ x == x + @test x ⊓ a == a ⊓ x + @test x ⊔ a == a ⊔ x == x X = IntervalBox(1..2, 3..4) Y = IntervalBox(3..4, 3..4) - @test isempty(X ∩ Y) - @test X ∪ Y == IntervalBox(1..4, 3..4) + @test isempty(X ⊓ Y) + @test X ⊔ Y == IntervalBox(1..4, 3..4) - # @test !contains_zero(X ∩ Y) + # @test !contains_zero(X ⊓ Y) # @test contains_zero( (-1..1) × (-1..1) ) @test !isbounded( (-1..1) × (0..Inf) ) @@ -83,7 +83,7 @@ using Test X = IntervalBox(2..4, 3..5) Y = IntervalBox(3..5, 4..17) - @test X ∩ Y == IntervalBox(3..4, 4..5) + @test X ⊓ Y == IntervalBox(3..4, 4..5) v = [interval(i, i+1) for i in 1:10] V = IntervalBox(v...)