Skip to content

Commit

Permalink
Document left/right endpoint equality
Browse files Browse the repository at this point in the history
  • Loading branch information
omus authored and spurll committed Mar 9, 2018
1 parent 469a366 commit f4d716a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/endpoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ RightEndpoint(ep::T, included::Bool) where T = RightEndpoint{T}(ep, included)
LeftEndpoint(i::AbstractInterval{T}) where T = LeftEndpoint{T}(first(i), first(inclusivity(i)))
RightEndpoint(i::AbstractInterval{T}) where T = RightEndpoint{T}(last(i), last(inclusivity(i)))


"""
==(a::LeftEndpoint{T}, b::RightEndpoint{T}) where T -> Bool
==(a::RightEndpoint{T}, b::LeftEndpoint{T}) where T -> Bool
A left-endpoint and a right-endpoint are only equal when they use the same point and are
both included. Note that left/right endpoints which are both not included are not equal
as the left-endpoint contains values below that point while the right-endpoint only contains
values that are above that point.
Visualizing two touching intervals can assist in understanding this logic:
[x..y][y..z] -> RightEndpoint == LeftEndpoint
[x..y)[y..z] -> RightEndpoint != LeftEndpoint
[x..y](y..z] -> RightEndpoint != LeftEndpoint
[x..y)(y..z] -> RightEndpoint != LeftEndpoint
"""
Base.:(==)(a::Endpoint, b::Endpoint)


function Base.:(==)(a::LeftEndpoint{T}, b::RightEndpoint{T}) where T
a.endpoint == b.endpoint && a.included && b.included
end
Expand Down

0 comments on commit f4d716a

Please sign in to comment.