Skip to content
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

#1457 - Unsound witness in isdisjoint for hyperrectangles #1465

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/is_intersection_empty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function is_intersection_empty(H1::AbstractHyperrectangle{N},
)::Union{Bool, Tuple{Bool, Vector{N}}} where {N<:Real}
empty_intersection = false
center_diff = center(H2) - center(H1)
for i in eachindex(center_diff)
@inbounds for i in eachindex(center_diff)
if abs(center_diff[i]) >
radius_hyperrectangle(H1, i) + radius_hyperrectangle(H2, i)
empty_intersection = true
Expand All @@ -115,13 +115,13 @@ function is_intersection_empty(H1::AbstractHyperrectangle{N},
# compute a witness 'v' in the intersection
v = copy(center(H1))
c2 = center(H2)
for i in eachindex(center_diff)
@inbounds for i in eachindex(center_diff)
if v[i] <= c2[i]
# second center is right of first center
v[i] += min(radius_hyperrectangle(H1, i), center_diff[i])
else
# second center is left of first center
v[i] -= max(radius_hyperrectangle(H1, i), -center_diff[i])
v[i] -= min(radius_hyperrectangle(H1, i), -center_diff[i])
end
end
return (false, v)
Expand Down
6 changes: 6 additions & 0 deletions test/unit_Hyperrectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ for N in [Float64, Rational{Int}, Float32]
H1 = Hyperrectangle(N[1, 1], N[2, 2])
H2 = Hyperrectangle(N[3, 3], N[2, 2])
B1 = BallInf(N[2, 4], N(0.5))
B2 = BallInf(N[3, 3], N(0.5))
for (X1, X2) in [(H1, H2), (H2, H1)]
intersection_empty, point = is_intersection_empty(X1, X2, true)
cap = intersection(X1, X2)
Expand All @@ -159,6 +160,11 @@ for N in [Float64, Rational{Int}, Float32]
cap = intersection(H1, B1)
@test cap isa EmptySet{N}
@test is_intersection_empty(H1, B1) && is_intersection_empty(H1, B1, true)[1]
cap = intersection(H1, B2)
@test cap == Hyperrectangle(N[2.75, 2.75], N[0.25, 0.25])
intersection_empty, point = is_intersection_empty(H1, B2, true)
@test !is_intersection_empty(H1, B2) && !intersection_empty && point ∈ H1 &&
point ∈ B2

# linear map (concrete)
P = linear_map(N[1 0; 0 2], H1)
Expand Down