Skip to content

Commit

Permalink
Merge pull request #3116 from mvanzulli/master
Browse files Browse the repository at this point in the history
Include non-convex polygon struct `VPolygonNC` ✳️
  • Loading branch information
schillic authored Oct 12, 2022
2 parents a25b116 + 5c608d3 commit 5022fec
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ makedocs(
"Star" => "lib/sets/Star.md",
"Universe" => "lib/sets/Universe.md",
"VPolygon" => "lib/sets/VPolygon.md",
"VPolygonNC" => "lib/sets/VPolygonNC.md",
"VPolytope" => "lib/sets/VPolytope.md",
"ZeroSet" => "lib/sets/ZeroSet.md",
"Zonotope" => "lib/sets/Zonotope.md",
Expand Down
3 changes: 3 additions & 0 deletions docs/src/lib/sets/VPolygonNC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```@docs
VPolygonNC
```
6 changes: 4 additions & 2 deletions src/Interfaces/LazySet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The subtypes of `LazySet` (including abstract interfaces):
```jldoctest; setup = :(using LazySets: subtypes)
julia> subtypes(LazySet, false)
8-element Vector{Any}:
9-element Vector{Any}:
AbstractPolynomialZonotope
Complement
ConvexSet
Expand All @@ -30,6 +30,7 @@ julia> subtypes(LazySet, false)
Rectification
UnionSet
UnionSetArray
VPolygonNC
```
If we only consider *concrete* subtypes, then:
Expand All @@ -38,7 +39,7 @@ If we only consider *concrete* subtypes, then:
julia> concrete_subtypes = subtypes(LazySet, true);
julia> length(concrete_subtypes)
53
54
julia> println.(concrete_subtypes);
AffineMap
Expand Down Expand Up @@ -91,6 +92,7 @@ UnionSet
UnionSetArray
Universe
VPolygon
VPolygonNC
VPolytope
ZeroSet
Zonotope
Expand Down
1 change: 1 addition & 0 deletions src/LazySets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ include("Sets/SimpleSparsePolynomialZonotope.jl")
include("Sets/SparsePolynomialZonotope.jl")
include("Sets/Universe.jl")
include("Sets/VPolygon.jl")
include("Sets/VPolygonNC.jl")
include("Sets/VPolytope.jl")
include("Sets/ZeroSet.jl")
include("Sets/Zonotope.jl")
Expand Down
41 changes: 41 additions & 0 deletions src/Sets/VPolygonNC.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export VPolygonNC

"""
VPolygonNC{N, VN<:AbstractVector{N}} <: LazySet{N}
Type that represents a non-convex polygon by its vertices.
### Fields
- `vertices` -- the list of vertices
### Examples
A non-convex polygon in vertex representation can be constructed by passing the list of
vertices. For example, we can build a tooth:
```jldoctest polygon_v_ncrep
julia> NCP = VPolygonNC( [[0., 0], [0, 2], [2, 2], [2, 0], [1, 1]]);
julia> NCP.vertices
5-element Vector{Vector{Float64}}:
[0.0, 0.0]
[0.0, 2.0]
[2.0, 2.0]
[2.0, 0.0]
[1.0, 1.0]
```
"""
struct VPolygonNC{N, VN<:AbstractVector{N}} <: LazySet{N}
vertices::Vector{VN}

function VPolygonNC(vertices::Vector{VN}) where {N, VN<:AbstractVector{N}}
return new{N, VN}(vertices)
end
end

# constructor with empty vertices list
VPolygonNC{N}() where {N} = VPolygonNC(Vector{Vector{N}}())

# constructor with no vertices of type Float64
VPolygonNC() = VPolygonNC{Float64}()
3 changes: 2 additions & 1 deletion src/Utils/helper_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ Every convex set type implements the function `σ`.
julia> dict = implementing_sets(σ; signature=Type[AbstractVector], index=2);
julia> dict["missing"]
5-element Vector{Type}:
6-element Vector{Type}:
Complement
LazySets.AbstractStar
QuadraticMap
SimpleSparsePolynomialZonotope
SparsePolynomialZonotope
VPolygonNC
```
Some operations are not available for sets with rational numbers.
Expand Down
2 changes: 2 additions & 0 deletions test/Sets/PolygonNC.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# default Float64 constructors
@test VPolygonNC() isa VPolygonNC{Float64, Vector{Float64}}
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ if test_suite_basic
@time @testset "LazySets.BallInf" begin include("Sets/BallInf.jl") end
@time @testset "LazySets.Hyperrectangle" begin include("Sets/Hyperrectangle.jl") end
@time @testset "LazySets.Polygon" begin include("Sets/Polygon.jl") end
@time @testset "LazySets.PolygonNC" begin include("Sets/PolygonNC.jl") end
@time @testset "LazySets.Polytope" begin include("Sets/Polytope.jl") end
@time @testset "LazySets.Polyhedron" begin include("Sets/Polyhedron.jl") end
@time @testset "LazySets.Zonotope" begin include("Sets/Zonotope.jl") end
Expand Down

0 comments on commit 5022fec

Please sign in to comment.