Skip to content

Commit 77ef1dc

Browse files
authored
center of lazy translation and bloating (#2949)
* add center for lazy bloating * add center for lazy translation
1 parent 7bfd31b commit 77ef1dc

File tree

6 files changed

+46
-3
lines changed

6 files changed

+46
-3
lines changed

docs/src/lib/lazy_operations/Bloating.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ isbounded(::Bloating)
1313
isempty(::Bloating)
1414
an_element(::Bloating)
1515
constraints_list(::Bloating)
16+
center(::Bloating)
1617
```
1718

1819
Inherited from [`LazySet`](@ref):

docs/src/lib/lazy_operations/Translation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ an_element(::Translation)
1414
constraints_list(::Translation)
1515
linear_map(::AbstractMatrix, ::Translation)
1616
∈(::AbstractVector, ::Translation)
17+
center(::Translation)
1718
```
1819
Inherited from [`AbstractAffineMap`](@ref):
1920
* [`dim`](@ref dim(::AbstractAffineMap))

src/LazyOperations/Bloating.jl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export Bloating
22

33
"""
4-
Bloating{N, S<:LazySet{N}} <:LazySet{N}
4+
Bloating{N, S<:LazySet{N}} <: LazySet{N}
55
66
Type that represents a uniform expansion of a set in a given norm (also
77
known as *bloating*).
@@ -21,7 +21,7 @@ of `X` and a ball in the `p`-norm of radius `ε` centered in the origin `O`
2121
The `Bloating` operation preserves convexity: if `X` is convex, then any
2222
bloating of `X` is convex as well.
2323
"""
24-
struct Bloating{N, S<:LazySet{N}} <:LazySet{N}
24+
struct Bloating{N, S<:LazySet{N}} <: LazySet{N}
2525
X::S
2626
ε::N
2727
p::N
@@ -192,3 +192,20 @@ function constraints_list(B::Bloating)
192192

193193
return constraints_list(MinkowskiSum(B.X, _bloating_ball(B)))
194194
end
195+
196+
"""
197+
center(B::Bloating)
198+
199+
Return the center of a bloated set.
200+
201+
### Input
202+
203+
- `B` -- bloated set
204+
205+
### Output
206+
207+
The center of the wrapped set.
208+
"""
209+
function center(B::Bloating)
210+
center(B.X)
211+
end

src/LazyOperations/Translation.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import Base: isempty
33
export Translation,
44
an_element,
55
constraints_list,
6-
linear_map
6+
linear_map,
7+
center
78

89
"""
910
Translation{N, S<:LazySet{N}, VN<:AbstractVector{N}} <: AbstractAffineMap{N, S}
@@ -375,3 +376,20 @@ end
375376
function concretize(tr::Translation)
376377
return translate(concretize(tr.X), tr.v)
377378
end
379+
380+
"""
381+
center(tr::Translation)
382+
383+
Return the center of the translation of a set.
384+
385+
### Input
386+
387+
- `tr` -- translation of a set
388+
389+
### Output
390+
391+
The translation of the center of the wrapped set by the translation vector.
392+
"""
393+
function center(tr::Translation)
394+
center(tr.X) + tr.v
395+
end

test/LazyOperations/Bloating.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ for N in [Float64, Float32]
2929
end
3030
@test_throws ErrorException an_element(Y)
3131

32+
# center
33+
@test center(X) == center(B)
34+
3235
# tests for different norms
3336
for p in N[1, 2, Inf]
3437
B = BallInf(zeros(N, 2), N(1))

test/LazyOperations/Translation.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ for N in [Float64, Rational{Int}, Float32]
6060
# concretize
6161
@test concretize(tr) == translate(B, v)
6262

63+
# center
64+
@test center(tr) == center(B) + v
65+
6366
# ==================================
6467
# Type-specific methods
6568
# ==================================

0 commit comments

Comments
 (0)