JuliaMath / JuliaMath/IntervalSets.jl

Union of `isdisjoint` intervals

Open
#191 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
109
Forks
29
PR merge metrics
No merged PRs in 30d

Description

Right now, this is the error message we get when trying to compute the union of incompatible intervals:
```julia
julia> OpenInterval(1, 2) ∪ OpenInterval(2, 3)
ERROR: ArgumentError: Cannot construct union of disjoint sets.
```
It is a little bit confusing since it is possible to construct the union of disjoint intervals as long as they share an endpoint:
```julia
julia> isdisjoint(OpenInterval(1, 2), OpenInterval(2, 3))
true
julia> OpenInterval(1, 2) ∪ ClosedInterval(2, 3)
1 .. 3 (open-closed)
```
The confusion arises from such a pair of intervals being disjoint but connected sets. Maybe the error message should be changed to reflect that. Also, right now, in order to check if two intervals are disconnected, you have to do something like
```julia
isdisjoint(A, B) && !=(endpoints(A ∩ B)...)
```
which is a little bit inefficient since it computes `A ∩ B` twice or go full-on with
```julia
AB = A ∩ B
isempty(AB) && !=(endpoints(AB)...)
```
which is kind of lengthy. Maybe it would make sense to have a `isconnected` method?

All in all fairly minor issue, but it got me a little bit confused as a first-time user.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.