From 46d8f8c05bd544290eff9198010b2ae4ea0301fd Mon Sep 17 00:00:00 2001 From: schillic Date: Sat, 22 Jun 2019 15:49:52 +0200 Subject: [PATCH] fix witness production in isdisjoint for AbstractHyperrectangles --- src/is_intersection_empty.jl | 6 +++--- test/unit_Hyperrectangle.jl | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/is_intersection_empty.jl b/src/is_intersection_empty.jl index c657afa30d..f26495c756 100644 --- a/src/is_intersection_empty.jl +++ b/src/is_intersection_empty.jl @@ -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 @@ -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) diff --git a/test/unit_Hyperrectangle.jl b/test/unit_Hyperrectangle.jl index 3eff4e9880..8c07d259f2 100644 --- a/test/unit_Hyperrectangle.jl +++ b/test/unit_Hyperrectangle.jl @@ -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) @@ -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)