Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
name = "IntervalBoxes"
uuid = "43d83c95-ebbb-40ec-8188-24586a1458ed"
version = "0.3.0"
version = "0.3.1"

[deps]
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
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"
42 changes: 42 additions & 0 deletions ext/IntervalBoxesMakieExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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

@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

function Makie.convert_arguments(P::Type{<:Poly}, boxes::AbstractVector{<:IntervalBox{2}})
return Makie.convert_arguments(P, _to_rect.(boxes))
end

end
27 changes: 27 additions & 0 deletions ext/IntervalBoxesPlotsExt.jl
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/IntervalBoxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/intervalbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading