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

#1471 - No sorting for two-points convex hull #1472

Merged
merged 4 commits into from
Jun 30, 2019
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
13 changes: 2 additions & 11 deletions src/concrete_convex_hull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,16 @@ end

function _two_points_1d!(points)
p1, p2 = points[1], points[2]
if p1 == p2
# check for redundancy
if _isapprox(p1[1], p2[1]) # check for redundancy
pop!(points)
elseif p1[1] > p2[1]
points[1], points[2] = p2, p1
end
return points
end

function _two_points_2d!(points)
# special case, see #876
p1, p2 = points[1], points[2]
if p1 == p2
# check for redundancy
if _isapprox(p1[1], p2[1]) && _isapprox(p1[2], p2[2]) # check for redundancy
pop!(points)
elseif p1 <= p2
nothing
else
points[1], points[2] = p2, p1
end
return points
end
Expand Down
2 changes: 1 addition & 1 deletion test/unit_Zonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,6 @@ for N in [Float64]
# constraints_list for generator matrix with a zero row
Z = Zonotope(N[0, 0], N[2 3; 0 0])
P = tovrep(HPolygon(constraints_list(Z)))
@test vertices_list(P) [N[5, 0], [-5, 0]]
@test ispermutation(vertices_list(P), [N[5, 0], [-5, 0]])
end
end
5 changes: 2 additions & 3 deletions test/unit_convex_hull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ for N in [Float64, Rational{Int}]
# corner cases in dimension 1
@test convex_hull([Vector{N}(undef, 0)]) == [Vector{N}(undef, 0)]
@test convex_hull([[N(0)]]) == [[N(0)]]
@test convex_hull([[N(2)], [N(1)]]) == [[N(1)], [N(2)]]
@test ispermutation(convex_hull([N[2], N[1]]), [N[2], N[1]])
@test convex_hull([[N(2)], [N(2)]]) == [[N(2)]]

# corner cases in dimension 2
Expand All @@ -18,8 +18,7 @@ for N in [Float64, Rational{Int}]
p1 = [1., 2.]
p2 = [1., 3.]
@test convex_hull([p1]) == [p1]
@test convex_hull([p1, p2]) == [p1, p2]
@test convex_hull([p2, p1]) == [p1, p2]
@test ispermutation(convex_hull([p1, p2]), [p1, p2])

# corner cases in higher dimension
@test convex_hull([[N(0), N(0), N(0)]]) == [[N(0), N(0), N(0)]]
Expand Down