Skip to content

Commit

Permalink
add RotatedHyperrectangle type
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Feb 28, 2021
1 parent 7771adf commit 0f7a0fd
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/LazyOperations/LinearMap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ If ``L = M⋅S``, where ``M`` is a matrix and ``S`` is a convex set, it follows
that ``σ(d, L) = M⋅σ(M^T d, S)`` for any direction ``d``.
"""
function σ(d::AbstractVector, lm::LinearMap)
return _σ_linear_map(d, lm)
end

function _σ_linear_map(d::AbstractVector, lm::LazySet)
return lm.M * σ(_At_mul_B(lm.M, d), lm.X)
end

Expand All @@ -281,6 +285,10 @@ If ``L = M⋅S``, where ``M`` is a matrix and ``S`` is a convex set, it follows
that ``ρ(d, L) = ρ(M^T d, S)`` for any direction ``d``.
"""
function ρ(d::AbstractVector, lm::LinearMap; kwargs...)
return _ρ_linear_map(d, lm; kwargs...)
end

function _ρ_linear_map(d::AbstractVector, lm::LazySet; kwargs...)
return ρ(_At_mul_B(lm.M, d), lm.X; kwargs...)
end

Expand Down
1 change: 1 addition & 0 deletions src/LazySets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ include("Sets/Interval.jl")
include("Sets/Line2D.jl")
include("Sets/Line.jl")
include("Sets/LineSegment.jl")
include("Sets/RotatedHyperrectangle.jl")
include("Sets/Singleton.jl")
include("Sets/Universe.jl")
include("Sets/VPolygon.jl")
Expand Down
61 changes: 61 additions & 0 deletions src/Sets/RotatedHyperrectangle.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export RotatedHyperrectangle

struct RotatedHyperrectangle{N, MN<:AbstractMatrix{N},
HT<:AbstractHyperrectangle{N}} <: AbstractZonotope{N}
M::MN
box::HT

function RotatedHyperrectangle(M::MN, box::HT) where {N,
MN<:AbstractMatrix{N}, HT<:AbstractHyperrectangle{N}}
@assert dim(box) == checksquare(M) "a rotated hyperrectangle " *
"of dimension $(dim(box)) requires a square matrix of the same " *
"dimension"
return new{N, MN, HT}(M, box)
end
end

isoperationtype(::Type{RotatedHyperrectangle}) = false
isconvextype(::Type{RotatedHyperrectangle}) = true

function dim(R::RotatedHyperrectangle)
return size(R.M, 1)
end

function ρ(d::AbstractVector, R::RotatedHyperrectangle)
return _ρ_linear_map(d, R)
end

function σ(d::AbstractVector, R::RotatedHyperrectangle)
return _σ_linear_map(d, R)
end

function center(R::RotatedHyperrectangle)
return R.M * center(R.box)
end

function generators(R::RotatedHyperrectangle)
return generators_fallback(R)
end

function genmat(R::RotatedHyperrectangle)
return R.M * genmat(R.box)
end

function linear_map(M::AbstractMatrix, R::RotatedHyperrectangle)
@assert size(M, 2) == dim(R) "a linear map of size $(size(M)) is " *
"incompatible with a set of dimension $(dim(R))"
if size(M, 1) != size(M, 2) # TODO generalize
throw(ArgumentError("non-square linear maps for rotated " *
"hyperrectangles are not supported yet"))
end

return RotatedHyperrectangle(M * R.M, R.box)
end

function vertices_list(R::RotatedHyperrectangle)
return broadcast(v -> R.M * v, vertices_list(R.box))
end

function constraints_list(R::RotatedHyperrectangle)
return constraints_list(convert(VPolytope, R))
end
5 changes: 1 addition & 4 deletions test/unit_EmptySet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,9 @@ end

# intersection
for X in LazySets.subtypes(LazySet, true)
if X <: HParallelotope || isoperationtype(X) # TODO #2390 and #2391
if X <: RotatedHyperrectangle || isoperationtype(X) # TODO #2391
continue
end
if X <: Line # TODO #2219 (Line has type parameter by default)
X = Line
end
Y = rand(X)
E = EmptySet(dim(Y))
@test intersection(Y, E) == intersection(E, Y) == E
Expand Down

0 comments on commit 0f7a0fd

Please sign in to comment.