-
Notifications
You must be signed in to change notification settings - Fork 12
Implementing domains as an interface #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
965dbe6
beefcf1
ce52f2e
0340a44
c1b143a
7e7a81b
29262a1
7cb7d94
6f60042
3ee18e1
a7cef5a
272c4ea
1162e66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
iscompact(d::TypedEndpointsInterval{:closed,:closed}) = true | ||
iscompact(d::TypedEndpointsInterval) = false | ||
|
||
isinterval(d::Domain) = false | ||
isinterval(d) = false | ||
isinterval(d::AbstractInterval) = true | ||
|
||
hash(d::AbstractInterval, h::UInt) = | ||
|
@@ -54,9 +54,9 @@ end | |
boundary(d::AbstractInterval) = Point(leftendpoint(d)) ∪ Point(rightendpoint(d)) | ||
corners(d::AbstractInterval) = [leftendpoint(d), rightendpoint(d)] | ||
|
||
normal(d::AbstractInterval, x) = (abs(minimum(d)-x) < abs(maximum(d)-x)) ? -one(eltype(d)) : one(eltype(d)) | ||
normal(d::AbstractInterval, x) = (abs(minimum(d)-x) < abs(maximum(d)-x)) ? -one(deltype(d)) : one(deltype(d)) | ||
|
||
distance_to(d::AbstractInterval, x) = x ∈ d ? zero(eltype(d)) : min(abs(x-supremum(d)), abs(x-infimum(d))) | ||
distance_to(d::AbstractInterval, x) = x ∈ d ? zero(deltype(d)) : min(abs(x-supremum(d)), abs(x-infimum(d))) | ||
|
||
boundingbox(d::AbstractInterval) = d | ||
|
||
|
@@ -79,6 +79,10 @@ and `ChebyshevInterval`. | |
abstract type FixedInterval{L,R,T} <: TypedEndpointsInterval{L,R,T} end | ||
const ClosedFixedInterval{T} = FixedInterval{:closed,:closed,T} | ||
|
||
convert(::Type{AbstractInterval{T}}, d::FixedInterval{L,R,T}) where {L,R,T} = d | ||
convert(::Type{AbstractInterval{T}}, d::FixedInterval{L,R,S}) where {L,R,S,T} = | ||
similardomain(d, T) | ||
|
||
closure(d::AbstractInterval) = ClosedInterval(endpoints(d)...) | ||
closure(d::ClosedInterval) = d | ||
|
||
|
@@ -244,8 +248,8 @@ function similar_interval(d::HalfLine{T,C}, a::S, b::S) where {T,S,C} | |
HalfLine{promote_type(float(T),S),C}() | ||
end | ||
|
||
point_in_domain(d::NonnegativeRealLine) = zero(eltype(d)) | ||
point_in_domain(d::PositiveRealLine) = one(eltype(d)) | ||
point_in_domain(d::NonnegativeRealLine) = zero(deltype(d)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably this name is clearer, but this is called a "choice function" in the Axiom of Choice so we could just call this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, it would be good if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I'm renaming to |
||
point_in_domain(d::PositiveRealLine) = one(deltype(d)) | ||
|
||
|
||
"The negative halfline `(-∞,0]` or `(-∞,0)`, right-closed or right-open." | ||
|
@@ -276,8 +280,8 @@ function similar_interval(d::NegativeHalfLine{T,C}, a::S, b::S) where {S,T,C} | |
NegativeHalfLine{promote_type(S,float(T)),C}() | ||
end | ||
|
||
point_in_domain(d::NegativeRealLine) = -one(eltype(d)) | ||
point_in_domain(d::NonpositiveRealLine) = zero(eltype(d)) | ||
point_in_domain(d::NegativeRealLine) = -one(deltype(d)) | ||
point_in_domain(d::NonpositiveRealLine) = zero(deltype(d)) | ||
|
||
|
||
"The real line `(-∞,∞)`." | ||
|
@@ -318,11 +322,11 @@ intersect(d1::FixedInterval, d2::FixedInterval) = intersectdomain(d1, d2) | |
|
||
# Promotion to joint type T | ||
uniondomain(d1::TypedEndpointsInterval, d2::TypedEndpointsInterval) = | ||
uniondomain(promote(d1,d2)...) | ||
uniondomain(promote_domains(d1,d2)...) | ||
intersectdomain(d1::TypedEndpointsInterval, d2::TypedEndpointsInterval) = | ||
intersectdomain(promote(d1,d2)...) | ||
intersectdomain(promote_domains(d1,d2)...) | ||
setdiffdomain(d1::AbstractInterval, d2::AbstractInterval) = | ||
setdiffdomain(promote(d1,d2)...) | ||
setdiffdomain(promote_domains(d1,d2)...) | ||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's
unionbox1
and belowintersectbox1
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unionbox(d1,d2)
is a function of two arguments, which sometimes simplifies for certaind1
(independently ofd2
or for some possibilities ofd2
). Similarly, it may simplify for certaind2
. The call chain goes:unionbox(d1,d2)
->unionbox1(d1,d2)
->unionbox2(d1,d2)
-> some_default_algorithmThe idea is that
unionbox1
can dispatch safely (without ambiguity) solely on d1, and unionbox2 can dispatch on d2. I've used this pattern in many places and it works rather well. If a combination ofd1
andd2
is specific enough, then one can dispatch on it using just theunionbox
function.