Skip to content

Commit

Permalink
Merge pull request #20 from JuliaMath/teh/docstrings
Browse files Browse the repository at this point in the history
Add a few docstrings
  • Loading branch information
timholy authored Jul 7, 2017
2 parents 1af92d6 + 03a7325 commit 77d4bf0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/closed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@ end
ClosedInterval(i::AbstractInterval) = convert(ClosedInterval{eltype(i)}, i)
(::Type{ClosedInterval{T}}){T}(i::AbstractInterval) = convert(ClosedInterval{T}, i)

"""
iv = l..r
Construct a ClosedInterval `iv` spanning the region from `l` to `r`.
"""
..(x, y) = ClosedInterval(x, y)

"""
iv = center±halfwidth
Construct a ClosedInterval `iv` spanning the region from
`center - halfwidth` to `center + halfwidth`.
"""
±(x, y) = ClosedInterval(x - y, x + y)
±(x::CartesianIndex, y) = map(ClosedInterval, (x - y).I, (x + y).I)

Expand Down Expand Up @@ -72,6 +83,12 @@ issubset(A::ClosedInterval, B::ClosedInterval) = ((A.left in B) && (A.right in B

(A::ClosedInterval, B::ClosedInterval) = issubset(B, A)

"""
w = width(iv)
Calculate the width (max-min) of interval `iv`. Note that for integers
`l` and `r`, `width(l..r) = length(l:r) - 1`.
"""
function width{T}(A::ClosedInterval{T})
_width = A.right - A.left
max(zero(_width), _width) # this works when T is a Date
Expand Down

0 comments on commit 77d4bf0

Please sign in to comment.