From 380e6f1aec6f252c2ac166c8fbe45d998ea7e9e6 Mon Sep 17 00:00:00 2001 From: "David P. Sanders" Date: Mon, 13 Apr 2026 18:32:27 -0500 Subject: [PATCH 1/5] Add Makie package extension for plotting IntervalBoxes Add a weak dependency on Makie with a package extension that enables plotting 2D IntervalBoxes as rectangles via poly(). The extension converts IntervalBox{2} to Rect2f and integrates with Makie's convert_arguments system. Co-Authored-By: Claude Opus 4.6 (1M context) --- Project.toml | 7 +++++++ ext/IntervalBoxesMakieExt.jl | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 ext/IntervalBoxesMakieExt.jl diff --git a/Project.toml b/Project.toml index 776239f..1c00dce 100644 --- a/Project.toml +++ b/Project.toml @@ -6,7 +6,14 @@ version = "0.3.0" IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" +[weakdeps] +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" + +[extensions] +IntervalBoxesMakieExt = "Makie" + [compat] IntervalArithmetic = "1" +Makie = "0.21, 0.22" StaticArrays = "1" julia = "1.10" diff --git a/ext/IntervalBoxesMakieExt.jl b/ext/IntervalBoxesMakieExt.jl new file mode 100644 index 0000000..d651134 --- /dev/null +++ b/ext/IntervalBoxesMakieExt.jl @@ -0,0 +1,19 @@ +module IntervalBoxesMakieExt + +using IntervalBoxes: IntervalBox +using Makie +using IntervalArithmetic: inf, diam + +function _to_rect(b::IntervalBox{2}) + Rect2f(inf(b[1]), inf(b[2]), diam(b[1]), diam(b[2])) +end + +function Makie.convert_arguments(P::Type{<:Poly}, box::IntervalBox{2}) + return Makie.convert_arguments(P, [_to_rect(box)]) +end + +function Makie.convert_arguments(P::Type{<:Poly}, boxes::AbstractVector{<:IntervalBox{2}}) + return Makie.convert_arguments(P, _to_rect.(boxes)) +end + +end From e9cdc89dd340ea8dcf52d7e16492fc3d232f1a2e Mon Sep 17 00:00:00 2001 From: "David P. Sanders" Date: Mon, 13 Apr 2026 18:37:20 -0500 Subject: [PATCH 2/5] Add plot recipe so plot(intervalbox) works directly Define a @recipe PlotIntervalBox that decomposes into poly!(), supporting both single IntervalBox{2} and vectors. Users can now call: plot(box) plot(boxes) plotintervalbox(box) plotintervalbox!(ax, boxes) The poly() convert_arguments methods are kept as well. Co-Authored-By: Claude Opus 4.6 (1M context) --- ext/IntervalBoxesMakieExt.jl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ext/IntervalBoxesMakieExt.jl b/ext/IntervalBoxesMakieExt.jl index d651134..8f65da8 100644 --- a/ext/IntervalBoxesMakieExt.jl +++ b/ext/IntervalBoxesMakieExt.jl @@ -8,6 +8,29 @@ function _to_rect(b::IntervalBox{2}) Rect2f(inf(b[1]), inf(b[2]), diam(b[1]), diam(b[2])) end +@recipe(PlotIntervalBox, intervalboxes) do scene + Attributes( + color = (:blue, 0.3), + strokecolor = :black, + strokewidth = 1, + ) +end + +function Makie.plot!(p::PlotIntervalBox{<:Tuple{<:IntervalBox{2}}}) + box = p.intervalboxes + rect = @lift [_to_rect($box)] + poly!(p, rect; color=p.color, strokecolor=p.strokecolor, strokewidth=p.strokewidth) + return p +end + +function Makie.plot!(p::PlotIntervalBox{<:Tuple{AbstractVector{<:IntervalBox{2}}}}) + boxes = p.intervalboxes + rects = @lift _to_rect.($boxes) + poly!(p, rects; color=p.color, strokecolor=p.strokecolor, strokewidth=p.strokewidth) + return p +end + +# Also support poly() directly function Makie.convert_arguments(P::Type{<:Poly}, box::IntervalBox{2}) return Makie.convert_arguments(P, [_to_rect(box)]) end From d9849bca0762de57ff40df1df615d804d751ca47 Mon Sep 17 00:00:00 2001 From: "David P. Sanders" Date: Mon, 13 Apr 2026 18:38:54 -0500 Subject: [PATCH 3/5] Add Plots.jl package extension via RecipesBase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define a @recipe for IntervalBox{2} that draws rectangles using Plots.jl's :shape seriestype. Supports both single boxes and vectors. Usage: using Plots, IntervalBoxes, IntervalArithmetic plot(interval(0,1) × interval(0,1)) plot([interval(0,1) × interval(0,1), interval(2,3) × interval(1,2)]) Co-Authored-By: Claude Opus 4.6 (1M context) --- Project.toml | 3 +++ ext/IntervalBoxesPlotsExt.jl | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 ext/IntervalBoxesPlotsExt.jl diff --git a/Project.toml b/Project.toml index 1c00dce..438a771 100644 --- a/Project.toml +++ b/Project.toml @@ -8,12 +8,15 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" [weakdeps] Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" +RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" [extensions] IntervalBoxesMakieExt = "Makie" +IntervalBoxesPlotsExt = "RecipesBase" [compat] IntervalArithmetic = "1" Makie = "0.21, 0.22" +RecipesBase = "1" StaticArrays = "1" julia = "1.10" diff --git a/ext/IntervalBoxesPlotsExt.jl b/ext/IntervalBoxesPlotsExt.jl new file mode 100644 index 0000000..304c02a --- /dev/null +++ b/ext/IntervalBoxesPlotsExt.jl @@ -0,0 +1,27 @@ +module IntervalBoxesPlotsExt + +using IntervalBoxes: IntervalBox +using RecipesBase +using IntervalArithmetic: inf, sup + +@recipe function f(box::IntervalBox{2}) + seriestype := :shape + legend --> false + fillalpha --> 0.3 + linecolor --> :black + + x_lo, x_hi = inf(box[1]), sup(box[1]) + y_lo, y_hi = inf(box[2]), sup(box[2]) + + [x_lo, x_hi, x_hi, x_lo], [y_lo, y_lo, y_hi, y_hi] +end + +@recipe function f(boxes::AbstractVector{<:IntervalBox{2}}) + for box in boxes + @series begin + box + end + end +end + +end From 07be1e718611b9aa6a827b2ff24f933949181b90 Mon Sep 17 00:00:00 2001 From: "David P. Sanders" Date: Tue, 14 Apr 2026 21:23:37 -0500 Subject: [PATCH 4/5] Fix test for IntervalArithmetic v1 exception type change and bump to v0.3.1 IntervalArithmetic v1 throws InconclusiveBooleanOperation instead of ArgumentError when comparing intervals with ==. Co-Authored-By: Claude Opus 4.6 (1M context) --- Project.toml | 2 +- test/multidim.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 438a771..8ff0ae2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "IntervalBoxes" uuid = "43d83c95-ebbb-40ec-8188-24586a1458ed" -version = "0.3.0" +version = "0.3.1" [deps] IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" diff --git a/test/multidim.jl b/test/multidim.jl index 8b167d8..bbded7e 100644 --- a/test/multidim.jl +++ b/test/multidim.jl @@ -279,7 +279,7 @@ end @test (zero(mid(X)) ∈ X) == false @test zero(mid(X)) ∉ X - @test_throws ArgumentError (3..4) ∈ X + @test_throws IntervalArithmetic.InconclusiveBooleanOperation (3..4) ∈ X end From db95b6b0ac66b730cffe6960326d23fca6128bbe Mon Sep 17 00:00:00 2001 From: "David P. Sanders" Date: Wed, 15 Apr 2026 08:11:37 -0500 Subject: [PATCH 5/5] =?UTF-8?q?Fix=20=E2=88=88=20dispatch=20for=20Interval?= =?UTF-8?q?Box=20by=20importing=20Base.=E2=88=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ∈ methods were not extending Base.in because ∈ was missing from the Base imports. This caused Base.in to use its default iteration path, which called == on intervals and threw InconclusiveBooleanOperation on Julia 1.12+. Fix: add ∈ to `import Base`, add a specific method for IntervalType to throw ArgumentError, and remove the duplicate AbstractVector method from intervalbox.jl (already defined in arithmetic.jl). Co-Authored-By: Claude Opus 4.6 (1M context) --- src/IntervalBoxes.jl | 2 +- src/arithmetic.jl | 2 +- src/intervalbox.jl | 2 +- test/multidim.jl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/IntervalBoxes.jl b/src/IntervalBoxes.jl index b1971ab..a8e61ae 100644 --- a/src/IntervalBoxes.jl +++ b/src/IntervalBoxes.jl @@ -10,7 +10,7 @@ import IntervalArithmetic: import IntervalArithmetic.Symbols: ⊓, ⊔ import Base: - ⊆, +, -, *, /, ==, !=, eltype, length, size, getindex, setindex, iterate, + ⊆, ∈, +, -, *, /, ==, !=, eltype, length, size, getindex, setindex, iterate, broadcasted, setdiff, big, isempty, zero export IntervalBox diff --git a/src/arithmetic.jl b/src/arithmetic.jl index c7104e4..fdd1c02 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -14,7 +14,7 @@ /(a::IntervalBox, b::Real) = IntervalBox( a.v ./ b ) -Base.:∈(v::AbstractVector, X::IntervalBox) = all(in_interval.(v, X)) +∈(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 ) diff --git a/src/intervalbox.jl b/src/intervalbox.jl index 15b2804..28c44a5 100644 --- a/src/intervalbox.jl +++ b/src/intervalbox.jl @@ -87,7 +87,7 @@ big(X::IntervalBox) = big.(X) ⊔(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::IntervalType, Y::IntervalBox{N,T}) where {N,T} = throw(ArgumentError("$X ∈ $Y is not defined")) ∈(X, Y::IntervalBox{N,T}) where {N,T} = throw(ArgumentError("$X ∈ $Y is not defined")) # mixing intervals with one-dimensional interval boxes diff --git a/test/multidim.jl b/test/multidim.jl index bbded7e..8b167d8 100644 --- a/test/multidim.jl +++ b/test/multidim.jl @@ -279,7 +279,7 @@ end @test (zero(mid(X)) ∈ X) == false @test zero(mid(X)) ∉ X - @test_throws IntervalArithmetic.InconclusiveBooleanOperation (3..4) ∈ X + @test_throws ArgumentError (3..4) ∈ X end