Skip to content

Commit d7e4642

Browse files
authored
Rename isopen/isclosed to isopenset/isclosedset (#60)
* Add documentation for isopen * rename isopen to isopenset and isclosed to isclosedset * add deprecation warnings, bump version
1 parent 1d76371 commit d7e4642

File tree

5 files changed

+51
-32
lines changed

5 files changed

+51
-32
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
name = "IntervalSets"
22
uuid = "8197267c-284f-5f27-9208-e0e47529a953"
3-
version = "0.4.0"
3+
version = "0.5.0"
44

55
[deps]
66
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
77
EllipsisNotation = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
88
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
99

1010
[compat]
11-
julia = "0.7, 1"
1211
EllipsisNotation = "0.4"
12+
julia = "0.7, 1"
1313

1414
[extras]
1515
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ intervals upon which other packages might build. In particular, we
1515
for the reason that only one interval package can
1616
unambiguously define the `..` and `±` operators (see below).
1717

18-
Currently this package defines one concrete type, `ClosedInterval`.
19-
These define the closed set spanning from `a` to `b`, meaning the
18+
Currently this package defines one concrete type, `Interval`.
19+
These define the set spanning from `a` to `b`, meaning the
2020
interval is defined as the set `{x}` satisfying `a ≤ x ≤ b`. This is
2121
sometimes written `[a,b]` (mathematics syntax, not Julia syntax) or
2222
`a..b`.
2323

24+
Optionally, `Interval{L,R}` can represent open and half-open intervals. The type
25+
parameters `L` and `R` correspond to the left and right endpoint respectively.
26+
The notation `ClosedInterval` is short for `Interval{:closed,:closed}`, while `OpenInterval` is short for `Interval{:open,:open}`. For example, the interval `Interval{:open,:closed}` corresponds to the set `{x}` satisfying `a < x ≤ b`.
27+
2428
## Usage
2529

2630
You can construct `ClosedInterval`s in a variety of ways:
@@ -73,6 +77,15 @@ true
7377

7478
julia> (0.25..5) (3..7.4) # \cup<TAB>; can also use union()
7579
0.25..7.4
80+
81+
julia> isclosedset(0.5..2.0)
82+
true
83+
84+
julia> isopenset(OpenInterval(0.5..2.5))
85+
true
86+
87+
julia> isleftopen(2..3)
88+
false
7689
```
7790

7891
When computing the union, the result must also be an interval:

src/IntervalSets.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import EllipsisNotation: Ellipsis
1414

1515
export AbstractInterval, Interval, OpenInterval, ClosedInterval,
1616
, .., ±, ordered, width, duration, leftendpoint, rightendpoint, endpoints,
17-
isclosed, isleftclosed, isrightclosed, isleftopen, isrightopen, closedendpoints,
17+
isopenset, isclosedset, isleftclosed, isrightclosed,
18+
isleftopen, isrightopen, closedendpoints,
1819
infimum, supremum
1920

2021
"""
@@ -59,8 +60,13 @@ isleftopen(d::AbstractInterval) = !isleftclosed(d)
5960
isrightopen(d::AbstractInterval) = !isrightclosed(d)
6061

6162
# Only closed if closed at both endpoints, and similar for open
62-
isclosed(d::AbstractInterval) = isleftclosed(d) && isrightclosed(d)
63-
isopen(d::AbstractInterval) = isleftopen(d) && isrightopen(d)
63+
isclosedset(d::AbstractInterval) = isleftclosed(d) && isrightclosed(d)
64+
65+
"Is the interval open?"
66+
isopenset(d::AbstractInterval) = isleftopen(d) && isrightopen(d)
67+
68+
@deprecate isopen(d) isopenset(d) false
69+
@deprecate isclosed(d) isclosedset(d)
6470

6571
eltype(::Type{AbstractInterval{T}}) where {T} = T
6672
@pure eltype(::Type{I}) where {I<:AbstractInterval} = eltype(supertype(I))

src/interval.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ end
4949
convert(::Type{Interval}, i::Interval) = i
5050

5151
function convert(::Type{II}, i::AbstractInterval) where II<:ClosedInterval
52-
isclosed(i) || throw(InexactError(:convert,II,i))
52+
isclosedset(i) || throw(InexactError(:convert,II,i))
5353
II(i)
5454
end
5555
function convert(::Type{II}, i::AbstractInterval) where II<:OpenInterval
56-
isopen(i) || throw(InexactError(:convert,II,i))
56+
isopenset(i) || throw(InexactError(:convert,II,i))
5757
II(i)
5858
end
5959
function convert(::Type{II}, i::AbstractInterval) where II<:Interval{:open,:closed}

test/runtests.jl

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct IncompleteInterval <: AbstractInterval{Int} end
2222

2323
@testset "IntervalSets" begin
2424
if VERSION >= v"1.1"
25-
# Julia 1.0 defines getindex(a::GenericArray, i...) in Test,
25+
# Julia 1.0 defines getindex(a::GenericArray, i...) in Test,
2626
# which could cause an ambiguity with getindex(A::AbstractArray, ::EllipsisNotation.Ellipsis)
2727
@test isempty(detect_ambiguities(IntervalSets, Base, Core))
2828
end
@@ -146,17 +146,17 @@ struct IncompleteInterval <: AbstractInterval{Int} end
146146
@test @inferred(convert(ClosedInterval{Float64}, I)) ===
147147
@inferred(convert(AbstractInterval{Float64}, I)) ===
148148
@inferred(convert(Domain{Float64}, I)) ===
149-
@inferred(ClosedInterval{Float64}(I)) ===
150-
@inferred(convert(TypedEndpointsInterval{:closed,:closed,Float64},I)) ===
149+
@inferred(ClosedInterval{Float64}(I)) ===
150+
@inferred(convert(TypedEndpointsInterval{:closed,:closed,Float64},I)) ===
151151
0.0..3.0
152152
@test @inferred(convert(ClosedInterval, I)) ===
153153
@inferred(convert(Interval, I)) ===
154154
@inferred(ClosedInterval(I)) ===
155155
@inferred(Interval(I)) ===
156156
@inferred(convert(AbstractInterval, I)) ===
157-
@inferred(convert(Domain, I)) ===
158-
@inferred(convert(TypedEndpointsInterval{:closed,:closed}, I)) ===
159-
@inferred(convert(TypedEndpointsInterval{:closed,:closed,Int}, I)) ===
157+
@inferred(convert(Domain, I)) ===
158+
@inferred(convert(TypedEndpointsInterval{:closed,:closed}, I)) ===
159+
@inferred(convert(TypedEndpointsInterval{:closed,:closed,Int}, I)) ===
160160
@inferred(convert(ClosedInterval{Int}, I)) === I
161161
@test_throws InexactError convert(OpenInterval, I)
162162
@test_throws InexactError convert(Interval{:open,:closed}, I)
@@ -175,8 +175,8 @@ struct IncompleteInterval <: AbstractInterval{Int} end
175175
@inferred(convert(Interval, J)) ===
176176
@inferred(convert(AbstractInterval, J)) ===
177177
@inferred(convert(Domain, J)) ===
178-
@inferred(OpenInterval(J)) ===
179-
@inferred(OpenInterval{Int}(J)) ===
178+
@inferred(OpenInterval(J)) ===
179+
@inferred(OpenInterval{Int}(J)) ===
180180
@inferred(convert(OpenInterval{Int},J)) === OpenInterval(J)
181181
J = Interval{:open,:closed}(I)
182182
@test_throws InexactError convert(Interval{:closed,:open}, J)
@@ -244,27 +244,27 @@ struct IncompleteInterval <: AbstractInterval{Int} end
244244
@test minimum(d) == infimum(d) == leftendpoint(d)
245245
@test maximum(d) == supremum(d) == rightendpoint(d)
246246

247-
@test IntervalSets.isclosed(d)
248-
@test !IntervalSets.isopen(d)
247+
@test IntervalSets.isclosedset(d)
248+
@test !IntervalSets.isopenset(d)
249249
@test IntervalSets.isleftclosed(d)
250250
@test !IntervalSets.isleftopen(d)
251251
@test !IntervalSets.isrightopen(d)
252-
@test IntervalSets.isrightclosed(d)
252+
@test IntervalSets.isrightclosed(d)
253253

254254
@test convert(AbstractInterval, d) d
255255
@test convert(AbstractInterval{T}, d) d
256256
@test convert(IntervalSets.Domain, d) d
257257
@test convert(IntervalSets.Domain{T}, d) d
258258

259259
d = OpenInterval(zero(T) .. one(T))
260-
@test IntervalSets.isopen(d)
261-
@test !IntervalSets.isclosed(d)
262-
@test IntervalSets.isopen(d)
263-
@test !IntervalSets.isclosed(d)
260+
@test IntervalSets.isopenset(d)
261+
@test !IntervalSets.isclosedset(d)
262+
@test IntervalSets.isopenset(d)
263+
@test !IntervalSets.isclosedset(d)
264264
@test !IntervalSets.isleftclosed(d)
265265
@test IntervalSets.isleftopen(d)
266266
@test IntervalSets.isrightopen(d)
267-
@test !IntervalSets.isrightclosed(d)
267+
@test !IntervalSets.isrightclosed(d)
268268
@test leftendpoint(d) d
269269
@test BigFloat(leftendpoint(d)) d
270270
@test nextfloat(leftendpoint(d)) d
@@ -285,12 +285,12 @@ struct IncompleteInterval <: AbstractInterval{Int} end
285285
@test isempty(OpenInterval(1,1))
286286

287287
d = Interval{:open,:closed}(zero(T) .. one(T))
288-
@test !IntervalSets.isopen(d)
289-
@test !IntervalSets.isclosed(d)
288+
@test !IntervalSets.isopenset(d)
289+
@test !IntervalSets.isclosedset(d)
290290
@test !IntervalSets.isleftclosed(d)
291291
@test IntervalSets.isleftopen(d)
292292
@test !IntervalSets.isrightopen(d)
293-
@test IntervalSets.isrightclosed(d)
293+
@test IntervalSets.isrightclosed(d)
294294
@test leftendpoint(d) d
295295
@test BigFloat(leftendpoint(d)) d
296296
@test nextfloat(leftendpoint(d)) d
@@ -308,12 +308,12 @@ struct IncompleteInterval <: AbstractInterval{Int} end
308308
@test_throws ArgumentError minimum(d)
309309

310310
d = Interval{:closed,:open}(zero(T) .. one(T))
311-
@test !IntervalSets.isopen(d)
312-
@test !IntervalSets.isclosed(d)
311+
@test !IntervalSets.isopenset(d)
312+
@test !IntervalSets.isclosedset(d)
313313
@test IntervalSets.isleftclosed(d)
314314
@test !IntervalSets.isleftopen(d)
315315
@test IntervalSets.isrightopen(d)
316-
@test !IntervalSets.isrightclosed(d)
316+
@test !IntervalSets.isrightclosed(d)
317317
@test leftendpoint(d) d
318318
@test BigFloat(leftendpoint(d)) d
319319
@test nextfloat(leftendpoint(d)) d
@@ -651,7 +651,7 @@ struct IncompleteInterval <: AbstractInterval{Int} end
651651
@test ismissing(missing in Interval{:closed, :open}(0, 1))
652652
@test ismissing(missing in Interval{:open, :closed}(0, 1))
653653
end
654-
654+
655655
@testset "complex in" begin
656656
@test 0+im 0..2
657657
@test 0+0im 0..2

0 commit comments

Comments
 (0)