Skip to content

Commit

Permalink
add diff for parts
Browse files Browse the repository at this point in the history
  • Loading branch information
joshday committed Mar 19, 2020
1 parent db2cbf3 commit 6ca489d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/part.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function _merge!(a::Part, b::Part)
merge!(a.domain, b.domain)
end

Base.diff(a::Part, b::Part) = diff(a.domain, b.domain)



#-----------------------------------------------------------------------------#
Expand All @@ -28,6 +30,7 @@ end
# - Base.merge!
# - Base.in
# - Base.isless
# - Base.diff

#-----------------------------------------------------------------------------# Centroid
mutable struct Centroid{T}
Expand All @@ -38,6 +41,7 @@ Base.in(x::T, c::Centroid{T}) where {T} = true
Base.in(x, c::Centroid) = false
Base.isless(a::Centroid, b::Centroid) = isless(a.center, b.center)
Base.show(io::IO, c::Centroid) = print(io, "Centroid: $(c.center)")
Base.diff(a::Centroid, b::Centroid) = norm(a.center - b.center)

function Base.merge!(a::Part{Centroid{T}, O}, b::Part{Centroid{T}, O}) where {T <: Number, O}
merge!(a.stat, b.stat)
Expand All @@ -59,7 +63,12 @@ end
Base.show(io::IO, b::ClosedInterval) = print(io, "ClosedInterval: [$(b.first), $(b.last)]")
Base.in(x, bucket::ClosedInterval) = bucket.first x bucket.last
Base.isless(a::ClosedInterval, b::ClosedInterval) = isless(a.first, b.first)
function Base.diff(a::ClosedInterval, b::ClosedInterval)
a < b ? _value(b.last) - _value(a.first) : _value(a.last) - _value(b.first)
end

_value(x) = x
_value(x::Dates.TimeType) = Dates.value(x)

function Base.merge!(a::ClosedInterval, b::ClosedInterval)
a.first = min(a.first, b.first)
Expand Down

2 comments on commit 6ca489d

@joshday
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: "Tag with name 1.2.5 already exists and points to a different commit"

Please sign in to comment.