Skip to content

Commit e085e92

Browse files
authored
Merge pull request #3906 from JuliaReach/schillic/is_interior_point_hyperrectangle
Fix and improve `is_interior_point` for `AbstractHyperrectangle`
2 parents b04f16f + 0a54d9c commit e085e92

File tree

8 files changed

+34
-25
lines changed

8 files changed

+34
-25
lines changed

docs/src/lib/interfaces/AbstractHyperrectangle.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ CurrentModule = LazySets.API
243243
* [`low`](@ref low(::LazySet))
244244
* [`low`](@ref low(::LazySet, ::Int))
245245
* [`distance`](@ref distance(::AbstractVector, ::LazySet))
246+
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::LazySet))
246247
* [`project`](@ref project(::LazySet, ::AbstractVector{Int}))
247248
* [`ρ`](@ref ρ(::AbstractVector, ::LazySet))
248249
* [`cartesian_product`](@ref cartesian_product(::LazySet, ::LazySet))
@@ -272,7 +273,6 @@ Inherited from [`LazySet`](@ref):
272273
* [`vertices`](@ref vertices(::LazySet))
273274
* [`affine_map`](@ref affine_map(::AbstractMatrix, ::LazySet, ::AbstractVector))
274275
* [`exponential_map`](@ref exponential_map(::AbstractMatrix, ::LazySet))
275-
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::LazySet))
276276
* [`sample`](@ref sample(::LazySet, ::Int=1))
277277
* [`scale`](@ref scale(::Real, ::LazySet))
278278
* [`translate`](@ref translate(::LazySet, ::AbstractVector))

docs/src/lib/interfaces/AbstractSingleton.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ Inherited from [`LazySet`](@ref):
134134
* [`triangulate_faces`](@ref triangulate_faces(::LazySet))
135135
* [`affine_map`](@ref affine_map(::AbstractMatrix, ::LazySet, ::AbstractVector))
136136
* [`exponential_map`](@ref exponential_map(::AbstractMatrix, ::LazySet))
137-
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::LazySet))
138137
* [`sample`](@ref sample(::LazySet, ::Int=1))
139138
* [`scale`](@ref scale(::Real, ::LazySet))
140139
* [`translate`](@ref translate(::LazySet, ::AbstractVector))
@@ -181,6 +180,7 @@ Inherited from [`AbstractHyperrectangle`](@ref):
181180
* [`rectify`](@ref rectify(::AbstractHyperrectangle))
182181
* [`volume`](@ref volume(::AbstractHyperrectangle))
183182
* [`distance`](@ref distance(::AbstractVector, ::AbstractHyperrectangle; ::Real=2.0))
183+
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::AbstractHyperrectangle))
184184
* [`difference`](@ref difference(::AbstractHyperrectangle, ::AbstractHyperrectangle))
185185
* [`minkowski_difference`](@ref minkowski_difference(::AbstractHyperrectangle, ::AbstractHyperrectangle))
186186

docs/src/lib/sets/BallInf.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ Inherited from [`LazySet`](@ref):
131131
* [`vertices`](@ref vertices(::LazySet))
132132
* [`affine_map`](@ref affine_map(::AbstractMatrix, ::LazySet, ::AbstractVector))
133133
* [`exponential_map`](@ref exponential_map(::AbstractMatrix, ::LazySet))
134-
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::LazySet))
135134
* [`sample`](@ref sample(::LazySet, ::Int))
136135
* [`translate`](@ref translate(::LazySet, ::AbstractVector))
137136
* [`convex_hull`](@ref convex_hull(::LazySet, ::LazySet))
@@ -180,6 +179,7 @@ Inherited from [`AbstractHyperrectangle`](@ref):
180179
* [`rectify`](@ref rectify(::AbstractHyperrectangle))
181180
* [`vertices_list`](@ref vertices_list(::AbstractHyperrectangle))
182181
* [``](@ref ∈(::AbstractVector, ::AbstractHyperrectangle))
182+
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::AbstractHyperrectangle))
183183
* [`cartesian_product`](@ref cartesian_product(::AbstractHyperrectangle, ::AbstractHyperrectangle))
184184
* [`difference`](@ref difference(::AbstractHyperrectangle, ::AbstractHyperrectangle))
185185
* [`distance`](@ref distance(::AbstractHyperrectangle, ::AbstractHyperrectangle))

docs/src/lib/sets/Hyperrectangle.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ Inherited from [`LazySet`](@ref):
9393
* [`vertices`](@ref vertices(::LazySet))
9494
* [`affine_map`](@ref affine_map(::AbstractMatrix, ::LazySet, ::AbstractVector))
9595
* [`exponential_map`](@ref exponential_map(::AbstractMatrix, ::LazySet))
96-
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::LazySet))
9796
* [`sample`](@ref sample(::LazySet, ::Int=1))
9897
* [`convex_hull`](@ref convex_hull(::LazySet, ::LazySet))
9998
* [`exact_sum`](@ref exact_sum(::LazySet, ::LazySet))
@@ -152,6 +151,7 @@ Inherited from [`AbstractHyperrectangle`](@ref):
152151
* [`volume`](@ref volume(::AbstractHyperrectangle))
153152
* [`distance`](@ref distance(::AbstractVector, ::AbstractHyperrectangle))
154153
* [``](@ref ∈(::AbstractVector, ::AbstractHyperrectangle))
154+
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::AbstractHyperrectangle))
155155
* [`project`](@ref project(::AbstractHyperrectangle, ::AbstractVector{Int}))
156156
* [`split`](@ref split(::AbstractHyperrectangle, ::AbstractVector{Int}))
157157
* [`ρ`](@ref ρ(::AbstractVector, ::AbstractHyperrectangle))

docs/src/lib/sets/Interval.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ Inherited from [`LazySet`](@ref):
192192
* [`singleton_list`](@ref singleton_list(::LazySet))
193193
* [`tosimplehrep`](@ref tosimplehrep(::LazySet))
194194
* [`vertices`](@ref vertices(::LazySet))
195-
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::LazySet))
196195
* [`sample`](@ref sample(::LazySet, ::Int))
197196
* [`==`](@ref ==(::LazySet, ::LazySet))
198197

@@ -223,6 +222,7 @@ Inherited from [`AbstractZonotope`](@ref):
223222
Inherited from [`AbstractHyperrectangle`](@ref):
224223
* [`generators`](@ref generators(::AbstractHyperrectangle))
225224
* [`genmat`](@ref genmat(::AbstractHyperrectangle))
225+
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::AbstractHyperrectangle))
226226
* [`cartesian_product`](@ref cartesian_product(::AbstractHyperrectangle, ::AbstractHyperrectangle))
227227

228228
Some additional functionality is available for `IntervalArithmetic.Interval`s:

src/Interfaces/AbstractHyperrectangle.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,3 +637,13 @@ function chebyshev_center_radius(H::AbstractHyperrectangle)
637637
r = minimum(radius_hyperrectangle(H, i) for i in 1:dim(H))
638638
return c, r
639639
end
640+
641+
@validate function is_interior_point(v::AbstractVector{N}, H::AbstractHyperrectangle{N};
642+
p=N(Inf), ε=_rtol(N)) where {N<:Real}
643+
@inbounds for (i, vi) in enumerate(v)
644+
if low(H, i) + ε >= v[i] || v[i] >= high(H, i) - ε
645+
return false
646+
end
647+
end
648+
return true
649+
end

test/ConcreteOperations/interior.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@ if !isdefined(@__MODULE__, Symbol("@tN"))
66
end
77

88
for N in @tN([Float64, Float32, Rational{Int}])
9-
P = BallInf(zeros(N, 2), N(1 // 10))
10-
d = N[1 // 10, 1 // 10]
9+
B = Ball1(zeros(N, 2), N(1 // 10))
10+
x = N[1 // 10, 1 // 10]
1111
if N <: AbstractFloat
12-
@test !is_interior_point(d, P)
12+
@test !is_interior_point(x, B)
1313
else
14-
@test_throws ArgumentError is_interior_point(d, P)
15-
@test !is_interior_point(d, P; ε=1 // 100)
14+
@test_throws ArgumentError is_interior_point(x, B)
15+
@test !is_interior_point(x, B; ε=N(1 // 100))
1616
end
17-
@test !is_interior_point(d, P; ε=N(1))
18-
@test_throws ArgumentError is_interior_point(d, P; ε=N(0))
17+
@test !is_interior_point(x, B; ε=N(1))
18+
@test_throws ArgumentError is_interior_point(x, B; ε=N(0))
1919

20-
d = N[1 // 10, 1 // 10] .- LazySets._rtol(N)
20+
x = N[1 // 10, 1 // 10] .- LazySets._rtol(N)
2121
if N <: AbstractFloat
22-
@test is_interior_point(d, P)
22+
@test !is_interior_point(x, B)
2323
else
24-
@test !is_interior_point(d, P; ε=1 // 100)
24+
@test !is_interior_point(x, B; ε=N(1 // 100))
2525
end
2626
end
2727

2828
for N in @tN([Float64, Float32])
29-
P = BallInf(zeros(N, 2), N(1 // 10))
30-
d = N[1 // 10, 1 // 10]
31-
@test !is_interior_point(d, P; p=N(2))
29+
B = Ball1(zeros(N, 2), N(1 // 10))
30+
x = N[1 // 10, 1 // 10]
31+
@test !is_interior_point(x, B; p=N(2))
3232

33-
d = N[1 // 10, 1 // 10] .- LazySets._rtol(N)
34-
@test is_interior_point(d, P; p=N(2))
33+
x = N[1 // 10, 1 // 10] .- LazySets._rtol(N)
34+
@test !is_interior_point(x, B; p=N(2))
3535
end

test/Sets/Interval.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,11 @@ for N in @tN([Float64, Float32, Rational{Int}])
330330
@test_throws ArgumentError is_interior_point(N[0], X; p=N(1 // 2))
331331
if N <: AbstractFloat
332332
@test is_interior_point(N[1], X)
333-
if N == Float64
334-
@test_broken !is_interior_point(N[2], X) # TODO fix
335-
else
336-
@test !is_interior_point(N[2], X)
337-
end
333+
@test !is_interior_point(N[2], X)
338334
@test !is_interior_point(N[3], X)
335+
@test is_interior_point(N[1], X; p=N(2))
336+
@test is_interior_point(N[1], X; p=N(2), ε=N(1//2))
337+
@test !is_interior_point(N[1], X; ε=N(1))
339338
else
340339
@test_throws ArgumentError is_interior_point(N[1], X)
341340
@test is_interior_point(N[1], X; ε=1 // 100)

0 commit comments

Comments
 (0)