From 1b991905e57ea8357f1ec742bc511aeb6e33acfc Mon Sep 17 00:00:00 2001 From: Marcelo Forets Date: Sun, 30 Jun 2019 09:49:59 -0300 Subject: [PATCH] #1471 - No sorting for two-points convex hull (#1472) * write non-sorting functions for two points convex hull * remove code that sorts * use ispermutation (needs 1439) * fix test --- src/concrete_convex_hull.jl | 13 ++----------- test/unit_Zonotope.jl | 2 +- test/unit_convex_hull.jl | 5 ++--- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/concrete_convex_hull.jl b/src/concrete_convex_hull.jl index bef36e422b..9ebab74310 100644 --- a/src/concrete_convex_hull.jl +++ b/src/concrete_convex_hull.jl @@ -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 diff --git a/test/unit_Zonotope.jl b/test/unit_Zonotope.jl index 57cdfcb89a..48d6d5fb62 100644 --- a/test/unit_Zonotope.jl +++ b/test/unit_Zonotope.jl @@ -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 diff --git a/test/unit_convex_hull.jl b/test/unit_convex_hull.jl index 98fa97220e..50d23b51cf 100644 --- a/test/unit_convex_hull.jl +++ b/test/unit_convex_hull.jl @@ -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 @@ -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)]]