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

Revise translate and translate! #3525

Merged
merged 1 commit into from
Jun 8, 2024
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
2 changes: 0 additions & 2 deletions docs/src/lib/interfaces/AbstractZonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ generators_fallback(::AbstractZonotope)
σ(::AbstractVector, ::AbstractZonotope)
∈(::AbstractVector, ::AbstractZonotope)
linear_map(::AbstractMatrix, ::AbstractZonotope)
translate(::AbstractZonotope, ::AbstractVector)
translate!(::AbstractZonotope, ::AbstractVector)
split(::AbstractZonotope, ::Int)
split(::AbstractZonotope, ::AbstractVector{Int}, ::AbstractVector{Int})
constraints_list(::AbstractZonotope)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/lib/sets/Ball1.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ center(::Ball1)
vertices_list(::Ball1)
rand(::Type{Ball1})
constraints_list(::Ball1)
translate(::Ball1, ::AbstractVector)
translate!(::Ball1, ::AbstractVector)
reflect(::Ball1)
```
Expand All @@ -28,6 +27,7 @@ Inherited from [`LazySet`](@ref):
* [`low`](@ref low(::LazySet))
* [`high`](@ref high(::LazySet))
* [`linear_map`](@ref linear_map(::AbstractMatrix, ::LazySet)
* [`translate`](@ref translate(::LazySet, ::AbstractVector))

Inherited from [`AbstractPolytope`](@ref):
* [`isbounded`](@ref isbounded(::AbstractPolytope))
Expand Down
2 changes: 1 addition & 1 deletion docs/src/lib/sets/Ball2.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ center(::Ball2)
∈(::AbstractVector, ::Ball2)
rand(::Type{Ball2})
sample(::Ball2{N}, ::Int) where {N}
translate(::Ball2, ::AbstractVector)
translate!(::Ball2, ::AbstractVector)
chebyshev_center_radius(::Ball2)
volume(::Ball2)
Expand All @@ -25,6 +24,7 @@ Inherited from [`LazySet`](@ref):
* [`rectify`](@ref rectify(::LazySet))
* [`low`](@ref low(::LazySet))
* [`high`](@ref high(::LazySet))
* [`translate`](@ref translate(::LazySet, ::AbstractVector))

Inherited from [`AbstractCentrallySymmetric`](@ref):
* [`dim`](@ref dim(::AbstractCentrallySymmetric))
Expand Down
2 changes: 1 addition & 1 deletion docs/src/lib/sets/BallInf.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ isflat(::BallInf)
rand(::Type{BallInf})
σ(::AbstractVector, ::BallInf)
ρ(::AbstractVector, ::BallInf)
translate(::BallInf, ::AbstractVector)
translate!(::BallInf, ::AbstractVector)
ngens(::BallInf)
volume(::BallInf)
Expand All @@ -24,6 +23,7 @@ Inherited from [`LazySet`](@ref):
* [`diameter`](@ref diameter(::LazySet, ::Real))
* [`singleton_list`](@ref singleton_list(::LazySet))
* [`area`](@ref area(::LazySet))
* [`translate`](@ref translate(::LazySet, ::AbstractVector))

Inherited from [`AbstractPolytope`](@ref):
* [`isbounded`](@ref isbounded(::AbstractPolytope))
Expand Down
2 changes: 1 addition & 1 deletion docs/src/lib/sets/Ballp.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ CurrentModule = LazySets
Ballp
center(::Ballp)
rand(::Type{Ballp})
translate(::Ballp, ::AbstractVector)
translate!(::Ballp, ::AbstractVector)
reflect(::Ballp)
```
Expand All @@ -19,6 +18,7 @@ Inherited from [`LazySet`](@ref):
* [`rectify`](@ref rectify(::LazySet))
* [`low`](@ref low(::LazySet))
* [`high`](@ref high(::LazySet))
* [`translate`](@ref translate(::LazySet, ::AbstractVector))

Inherited from [`AbstractCentrallySymmetric`](@ref):
* [`dim`](@ref dim(::AbstractCentrallySymmetric))
Expand Down
2 changes: 1 addition & 1 deletion docs/src/lib/sets/Ellipsoid.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ shape_matrix(::Ellipsoid)
σ(::AbstractVector, ::Ellipsoid)
∈(::AbstractVector, ::Ellipsoid)
rand(::Type{Ellipsoid})
translate(::Ellipsoid, ::AbstractVector)
translate!(::Ellipsoid, ::AbstractVector)
linear_map(::AbstractMatrix, ::Ellipsoid)
```
Expand All @@ -23,6 +22,7 @@ Inherited from [`LazySet`](@ref):
* [`rectify`](@ref rectify(::LazySet))
* [`low`](@ref low(::LazySet))
* [`high`](@ref high(::LazySet))
* [`translate`](@ref translate(::LazySet, ::AbstractVector))

Inherited from [`AbstractCentrallySymmetric`](@ref):
* [`dim`](@ref dim(::AbstractCentrallySymmetric))
Expand Down
2 changes: 1 addition & 1 deletion docs/src/lib/sets/Line.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ isbounded(::Line)
isuniversal(::Line; ::Bool=false)
isempty(::Line)
constraints_list(::Line)
translate(::Line, ::AbstractVector)
translate!(::Line, ::AbstractVector)
normalize(::Line{N}, ::Real=N(2)) where{N}
normalize!(::Line{N}, ::Real=N(2)) where{N}
Expand All @@ -33,3 +32,4 @@ Inherited from [`LazySet`](@ref):
* [`low`](@ref low(::LazySet, ::Int))
* [`high`](@ref high(::LazySet, ::Int))
* [`reflect`](@ref reflect(::LazySet))
* [`translate`](@ref translate(::LazySet, ::AbstractVector))
2 changes: 1 addition & 1 deletion docs/src/lib/sets/Singleton.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ CurrentModule = LazySets
Singleton
rand(::Type{Singleton})
element(::Singleton)
translate(::Singleton, ::AbstractVector)
translate!(::Singleton, ::AbstractVector)
rectify(S::Singleton)
project(::Singleton, ::AbstractVector{Int})
Expand All @@ -18,6 +17,7 @@ linear_map(::AbstractMatrix, ::Singleton)
```
Inherited from [`LazySet`](@ref):
* [`diameter`](@ref diameter(::LazySet, ::Real))
* [`translate`](@ref translate(::LazySet, ::AbstractVector))

Inherited from [`AbstractPolytope`](@ref):
* [`isbounded`](@ref isbounded(::AbstractPolytope))
Expand Down
4 changes: 2 additions & 2 deletions docs/src/lib/sets/Zonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ remove_zero_generators(::Zonotope)
linear_map!(::Zonotope, ::AbstractMatrix, ::Zonotope)
LazySets._bound_intersect_2D(::Zonotope, ::Line2D)
remove_redundant_generators(Z::Zonotope{N}) where {N}
translate!(::Zonotope, ::AbstractVector)
```
Inherited from [`LazySet`](@ref):
* [`high`](@ref high(::LazySet))
Expand All @@ -27,6 +28,7 @@ Inherited from [`LazySet`](@ref):
* [`radius`](@ref radius(::LazySet, ::Real))
* [`diameter`](@ref diameter(::LazySet, ::Real))
* [`singleton_list`](@ref singleton_list(::LazySet))
* [`translate`](@ref translate(::LazySet, ::AbstractVector))

Inherited from [`AbstractPolytope`](@ref):
* [`isbounded`](@ref isbounded(::AbstractPolytope))
Expand All @@ -43,8 +45,6 @@ Inherited from [`AbstractZonotope`](@ref):
* [`σ`](@ref σ(::AbstractVector, ::AbstractZonotope))
* [`∈`](@ref ∈(::AbstractVector, ::AbstractZonotope))
* [`linear_map`](@ref linear_map(::AbstractMatrix, ::AbstractZonotope))
* [`translate`](@ref translate(::AbstractZonotope, ::AbstractVector))
* [`translate!`](@ref translate!(::AbstractZonotope, ::AbstractVector))
* [`split`](@ref split(::AbstractZonotope, ::Int))
* [`split`](@ref split(::AbstractZonotope, ::AbstractVector{Int}, ::AbstractVector{Int}))
* [`constraints_list`](@ref constraints_list(::AbstractZonotope))
Expand Down
54 changes: 0 additions & 54 deletions src/Interfaces/AbstractZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -333,60 +333,6 @@ function _linear_map_zonotope_nD(M::AbstractMatrix, Z::LazySet)
return Zonotope(c, gi)
end

"""
translate(Z::AbstractZonotope, v::AbstractVector)

Translate (i.e., shift) a zonotopic set by a given vector.

### Input

- `Z` -- zonotopic set
- `v` -- translation vector

### Output

A translated zonotopic set.

### Notes

See also [`translate!(Z::AbstractZonotope, v::AbstractVector)`](@ref) for the
in-place version.
"""
function translate(Z::AbstractZonotope, v::AbstractVector)
return translate!(copy(Z), v)
end

"""
translate!(Z::AbstractZonotope, v::AbstractVector)

Translate (i.e., shift) a zonotopic set by a given vector in-place.

### Input

- `Z` -- zonotopic set
- `v` -- translation vector

### Output

A translated zonotopic set.

### Notes

See also [`translate(Z::AbstractZonotope, v::AbstractVector)`](@ref) for the
out-of-place version.

### Algorithm

We add the translation vector to the center of the zonotopic set.
"""
function translate!(Z::AbstractZonotope, v::AbstractVector)
@assert length(v) == dim(Z) "cannot translate a $(dim(Z))-dimensional " *
"set by a $(length(v))-dimensional vector"
c = center(Z)
c .+= v
return Z
end

"""
vertices_list(Z::AbstractZonotope; [apply_convex_hull]::Bool=true)

Expand Down
22 changes: 0 additions & 22 deletions src/Sets/Ball1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -308,28 +308,6 @@ function constraints_list(B::Ball1)
return clist
end

"""
translate(B::Ball1, v::AbstractVector)

Translate (i.e., shift) a ball in the 1-norm by the given vector.

### Input

- `B` -- ball in the 1-norm
- `v` -- translation vector

### Output

The translated ball in the 1-norm.

### Notes

See also [`translate!(::Ball1, ::AbstractVector)`](@ref) for the in-place version.
"""
function translate(B::Ball1, v::AbstractVector)
return translate!(copy(B), v)
end

"""
translate!(B::Ball1, v::AbstractVector)

Expand Down
23 changes: 0 additions & 23 deletions src/Sets/Ball2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,29 +241,6 @@ function rand(::Type{Ball2};
return Ball2(center, radius)
end

"""
translate(B::Ball2, v::AbstractVector)

Translate (i.e., shift) a ball in the 2-norm by the given vector.

### Input

- `B` -- ball in the 2-norm
- `v` -- translation vector

### Output

A translated ball in the 2-norm.

### Notes

See also [`translate!(::Ball2, ::AbstractVector)`](@ref) for the in-place
version.
"""
function translate(B::Ball2, v::AbstractVector)
return translate!(copy(B), v)
end

"""
translate!(B::Ball2, v::AbstractVector)

Expand Down
23 changes: 0 additions & 23 deletions src/Sets/BallInf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,29 +324,6 @@ function rand(::Type{BallInf};
return BallInf(center, radius)
end

"""
translate(B::BallInf, v::AbstractVector)

Translate (i.e., shift) a ball in the infinity norm by a given vector.

### Input

- `B` -- ball in the infinity norm
- `v` -- translation vector

### Output

A translated ball in the infinity norm.

### Notes

See also [`translate!(::BallInf, ::AbstractVector)`](@ref) for the in-place
version.
"""
function translate(B::BallInf, v::AbstractVector)
return translate!(copy(B), v)
end

"""
translate!(B::BallInf, v::AbstractVector)

Expand Down
23 changes: 0 additions & 23 deletions src/Sets/Ballp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,29 +137,6 @@ function rand(::Type{Ballp};
return Ballp(p, center, radius)
end

"""
translate(B::Ballp, v::AbstractVector)

Translate (i.e., shift) a ball in the p-norm by a given vector.

### Input

- `B` -- ball in the p-norm
- `v` -- translation vector

### Output

A translated ball in the p- norm.

### Notes

See also [`translate!(::Ballp, ::AbstractVector)`](@ref) for the in-place
version.
"""
function translate(B::Ballp, v::AbstractVector)
return translate!(copy(B), v)
end

"""
translate!(B::Ballp, v::AbstractVector)

Expand Down
23 changes: 0 additions & 23 deletions src/Sets/Ellipsoid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,29 +307,6 @@ function rand(::Type{Ellipsoid};
return Ellipsoid(center, shape_matrix)
end

"""
translate(E::Ellipsoid, v::AbstractVector)

Translate (i.e., shift) an ellipsoid by a given vector.

### Input

- `E` -- ellipsoid
- `v` -- translation vector

### Output

A translated ellipsoid.

### Notes

See also [`translate!(::Ellipsoid, ::AbstractVector)`](@ref) for the in-place
version.
"""
function translate(E::Ellipsoid, v::AbstractVector)
return translate!(copy(E), v)
end

"""
translate!(E::Ellipsoid, v::AbstractVector)

Expand Down
2 changes: 1 addition & 1 deletion src/Sets/EmptySet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ Translate (i.e., shift) an empty set by a given vector.
The empty set.
"""
function translate(∅::EmptySet, v::AbstractVector)
return translate!(∅, v)
return translate!(∅, v) # no need to copy
end

function translate!(∅::EmptySet, v::AbstractVector)
Expand Down
7 changes: 7 additions & 0 deletions src/Sets/Hyperrectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,10 @@ function scale!(α::Real, H::Hyperrectangle)
H.radius .*= abs(α)
return H
end

function translate!(H::Hyperrectangle, v::AbstractVector)
@assert length(v) == dim(H) "cannot translate a $(dim(H))-dimensional " *
"set by a $(length(v))-dimensional vector"
H.center .+= v
return H
end
Loading
Loading