Skip to content

Commit 3ce0217

Browse files
authored
fix intersect with different types (#112)
1 parent b3f0d6e commit 3ce0217

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/interval.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,18 @@ _left_intersect_type(::Type{Val{:closed}}, ::Type{Val{L2}}, a1, a2) where L2 = a
105105
_right_intersect_type(::Type{Val{:open}}, ::Type{Val{R2}}, b1, b2) where R2 = b1 > b2 ? (b2,R2) : (b1,:open)
106106
_right_intersect_type(::Type{Val{:closed}}, ::Type{Val{R2}}, b1, b2) where R2 = b1 b2 ? (b2,R2) : (b1,:closed)
107107

108-
function intersect(d1::TypedEndpointsInterval{L1,R1,T}, d2::TypedEndpointsInterval{L2,R2,T}) where {L1,R1,L2,R2,T}
108+
function intersect(d1::TypedEndpointsInterval{L1,R1}, d2::TypedEndpointsInterval{L2,R2}) where {L1,R1,L2,R2}
109109
a1, b1 = endpoints(d1); a2, b2 = endpoints(d2)
110110
a,L = _left_intersect_type(Val{L1}, Val{L2}, a1, a2)
111111
b,R = _right_intersect_type(Val{R1}, Val{R2}, b1, b2)
112112
Interval{L,R}(a,b)
113113
end
114114

115-
function intersect(d1::TypedEndpointsInterval{L,R,T}, d2::TypedEndpointsInterval{L,R,T}) where {L,R,T}
115+
function intersect(d1::TypedEndpointsInterval{L,R}, d2::TypedEndpointsInterval{L,R}) where {L,R}
116116
a1, b1 = endpoints(d1); a2, b2 = endpoints(d2)
117117
Interval{L,R}(max(a1,a2),min(b1,b2))
118118
end
119119

120-
intersect(d1::TypedEndpointsInterval{L1,R1,T}, d2::TypedEndpointsInterval{L2,R2,V}) where {L1,R1,L2,R2,T,V} =
121-
intersect(promote(d1, d2)...)
122-
123120
intersect(d1::AbstractInterval, d2::AbstractInterval) = intersect(Interval(d1), Interval(d2))
124121

125122

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,10 @@ struct IncompleteInterval <: AbstractInterval{Int} end
582582
@test Interval{:closed,:open}(0..1) OpenInterval(0..1)
583583
OpenInterval(0..1) Interval{:closed,:open}(0..1)
584584
Interval{:closed,:open}(0..1)
585+
586+
# - different interval types
587+
@test (1..2) OpenInterval(0.5, 1.5) Interval{:closed, :open}(1, 1.5)
588+
@test (1..2) OpenInterval(0.5, 1.5) Interval{:open, :closed}(0.5, 2)
585589
end
586590
end
587591

0 commit comments

Comments
 (0)