Skip to content

Commit

Permalink
Change to square intersection and union symbols (#4)
Browse files Browse the repository at this point in the history
* Change to square intersection and union symbols

* Fix merge conflict

* Add NEWS.md

* Remove 1.6 from CI
  • Loading branch information
dpsanders authored Jul 14, 2024
1 parent 8cf8cf3 commit efaa4a4
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 27 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
matrix:
version:
- '1.10'
- '1.6'
- 'nightly'
os:
- ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name = "IntervalBoxes"
uuid = "43d83c95-ebbb-40ec-8188-24586a1458ed"
authors = ["David Sanders <[email protected]> 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"
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]¹
```

Expand Down
6 changes: 5 additions & 1 deletion src/IntervalBoxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/intervalbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/setdiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions test/multidim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,37 @@ 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) )
@test !isbounded( entireinterval() × entireinterval() )

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...)
Expand Down

2 comments on commit efaa4a4

@dpsanders
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/111037

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" efaa4a4b24d4da5c78b08e822102feab29207907
git push origin v0.2.0

Please sign in to comment.