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

Move back vertices_list helper function from ZonotopeModule #3606

Merged
merged 1 commit into from
Jul 21, 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
35 changes: 35 additions & 0 deletions src/Interfaces/AbstractZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,41 @@ function _vertices_list_zonotope_2D_order_one(c::VN, G::MN;
return apply_convex_hull ? _four_points_2d!(vlist) : vlist
end

# TODO this function is currently not used
function _vertices_list_2D(c::AbstractVector{N}, G::AbstractMatrix{N};
apply_convex_hull::Bool) where {N}
if apply_convex_hull
return _vertices_list_zonotope_iterative(c, G; apply_convex_hull=apply_convex_hull)
end

angles = mapslices(_angles, G; dims=1)[1, :]
perm = sortperm(angles)
sorted_angles = angles[perm]
sorted_G = G[:, perm]
polygons = Vector{VPolygon{N}}()
sizehint!(polygons, 4)

@inbounds for i in zip(0:90:360, 90:90:360)
index = i[1] .<= sorted_angles .< i[2]
if sum(index) > 0
push!(polygons, _single_quadrant_vertices_enum(sorted_G[:, index], true))
end
end

return vertices_list(translate(reduce(minkowski_sum, polygons), c))
end

@inline function _angles(point::AbstractVector{N}) where {N}
return (atand(point[2], point[1]) + 360) % 360
end

function _single_quadrant_vertices_enum(G::AbstractMatrix{N}, sorted::Bool=false) where {N}
if !sorted
G = sortslices(G; dims=2, by=_angles)
end
return VPolygon(2 * cumsum(hcat(G, -G); dims=2) .- sum(G; dims=2))
end

"""
constraints_list(P::AbstractZonotope)

Expand Down
6 changes: 2 additions & 4 deletions src/Sets/Zonotope/ZonotopeModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ module ZonotopeModule

using Reexport, Requires

using ..LazySets: AbstractZonotope, generators_fallback,
_vertices_list_zonotope_iterative
using ..LazySets: AbstractZonotope, generators_fallback
using LinearAlgebra: mul!
using Random: AbstractRNG, GLOBAL_RNG
using ReachabilityBase.Arrays: ismultiple, remove_zero_columns, to_matrix,
vector_type
using ReachabilityBase.Distribution: reseed!
using ReachabilityBase.Require: require

@reexport import ..API: center, high, isoperationtype, low, rand, vertices_list,
@reexport import ..API: center, high, isoperationtype, low, rand,
permute, scale!, translate!
@reexport import ..LazySets: generators, genmat, ngens, reduce_order,
remove_redundant_generators, togrep
Expand All @@ -30,7 +29,6 @@ include("high.jl")
include("isoperationtype.jl")
include("low.jl")
include("rand.jl")
include("vertices_list.jl")
include("linear_map.jl")
include("permute.jl")
include("scale.jl")
Expand Down
35 changes: 0 additions & 35 deletions src/Sets/Zonotope/vertices_list.jl

This file was deleted.

4 changes: 2 additions & 2 deletions test/Sets/Zonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ for N in [Float64]
@test length(vlistZ) == 6
@test ispermutation(vlistZ, [N[-2, -2], N[0, -2], N[2, 0], N[2, 2], N[0, 2], N[-2, 0]])
c, G = Z.center, Z.generators
vlist2 = LazySets.ZonotopeModule._vertices_list_2D(c, G; apply_convex_hull=true)
vlist2 = LazySets._vertices_list_2D(c, G; apply_convex_hull=true)
@test ispermutation(vlistZ, vlist2)
vlist3 = LazySets.ZonotopeModule._vertices_list_2D(c, G; apply_convex_hull=false)
vlist3 = LazySets._vertices_list_2D(c, G; apply_convex_hull=false)
@test ispermutation(vlistZ, vlist3)

# test 3d zonotope vertex enumeration
Expand Down
Loading