invenia / Intervals.jl

Non-iterable ranges
MIT License
36 stars 18 forks source link

bug in `intersect` #210

Open ericphanson opened 1 year ago

ericphanson commented 1 year ago
julia> using Intervals

julia> intersect([Interval{Int, Closed, Open}(1,3), Interval{Int, Closed, Open}(3,5)])
1-element Vector{Interval{Int64, Closed, Open}}:
 Interval{Int64, Closed, Open}(1, 5)

Those two intervals don't have any common elements, so they don't intersect.

iamed2 commented 1 year ago

That call doesn't actually take the intersection of the two intervals.

To do that:

julia> intersect(Interval{Int, Closed, Open}(1,3), Interval{Int, Closed, Open}(3,5))
Interval{Int64, Open, Open}(0, 0)

Intersect of one argument is an identity operation. For some reason Julia dispatches intersect(s) = union(s), so the misleading union method on arrays of intervals that is currently deprecated takes over. Once that deprecated method is removed, this call will return an array containing the same intervals in the same order.

ericphanson commented 1 year ago

Oh! Ok. That's pretty confusing. Can we do a breaking release & drop the deprecation?

iamed2 commented 1 year ago

Seems reasonable, although it might be good to address any invalidations that still exist at the same time.