From 993bc368356b429adcdc7b77c616febb600ff0fa Mon Sep 17 00:00:00 2001 From: mforets Date: Mon, 24 Jun 2019 23:30:46 -0300 Subject: [PATCH] remove code that sorts --- src/concrete_convex_hull.jl | 32 +++++--------------------------- test/unit_convex_hull.jl | 4 ++-- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/src/concrete_convex_hull.jl b/src/concrete_convex_hull.jl index 9a782763bc..9ebab74310 100644 --- a/src/concrete_convex_hull.jl +++ b/src/concrete_convex_hull.jl @@ -103,7 +103,7 @@ function convex_hull!(points::Vector{VN}; if n == 1 # dimensional check if m == 2 # two points case in 1d - return _two_points_1d!(points, false) + return _two_points_1d!(points) else # general case in 1d return _convex_hull_1d!(points) @@ -111,7 +111,7 @@ function convex_hull!(points::Vector{VN}; elseif n == 2 if m == 2 # two points case in 2d - return _two_points_2d!(points, false) + return _two_points_2d!(points) elseif m == 3 # three points case in 2d return _three_points_2d!(points) @@ -128,37 +128,15 @@ function convex_hull!(points::Vector{VN}; end end -function _two_points_1d!(points, sort=Val(true)) - p1, p2 = points[1], points[2] - if _isapprox(p1, p2) # check for redundancy - pop!(points) - elseif p1[1] > p2[1] - points[1], points[2] = p2, p1 - end - return points -end - -function _two_points_1d!(points, sort=Val(false)) - p1, p2 = points[1], points[2] - if _isapprox(p1, p2) # check for redundancy - pop!(points) - end - return points -end - -function _two_points_2d!(points, sort=Val(true)) +function _two_points_1d!(points) p1, p2 = points[1], points[2] - if isapprox(p1[1], p2[1]) && _isapprox(p1[2], p2[2]) # check for redundancy + if _isapprox(p1[1], p2[1]) # check for redundancy pop!(points) - elseif p1 <= p2 - nothing - else - points[1], points[2] = p2, p1 end return points end -function _two_points_2d!(points, sort=Val(false)) +function _two_points_2d!(points) p1, p2 = points[1], points[2] if _isapprox(p1[1], p2[1]) && _isapprox(p1[2], p2[2]) # check for redundancy pop!(points) diff --git a/test/unit_convex_hull.jl b/test/unit_convex_hull.jl index 98fa97220e..d4cee54d5c 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 convex_hull([[N(2)], [N(1)]]) == [[N(2)], [N(1)]] @test convex_hull([[N(2)], [N(2)]]) == [[N(2)]] # corner cases in dimension 2 @@ -19,7 +19,7 @@ for N in [Float64, Rational{Int}] p2 = [1., 3.] @test convex_hull([p1]) == [p1] @test convex_hull([p1, p2]) == [p1, p2] - @test convex_hull([p2, p1]) == [p1, p2] + @test convex_hull([p2, p1]) == [p2, p1] # no sorting # corner cases in higher dimension @test convex_hull([[N(0), N(0), N(0)]]) == [[N(0), N(0), N(0)]]