Skip to content

Commit

Permalink
#1471 - No sorting for two-points convex hull (#1472)
Browse files Browse the repository at this point in the history
* write non-sorting functions for two points convex hull

* remove code that sorts

* use ispermutation (needs 1439)

* fix test
  • Loading branch information
mforets authored Jun 30, 2019
1 parent f0b3f70 commit 1b99190
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
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

0 comments on commit 1b99190

Please sign in to comment.