From 98f3f3cc5cc3efbc203c86e40e2ca49068caf452 Mon Sep 17 00:00:00 2001 From: schillic Date: Fri, 26 Jul 2024 15:44:59 +0200 Subject: [PATCH] rename and move helper function --- docs/src/lib/utils.md | 1 - src/ConcreteOperations/convex_hull.jl | 21 +++++++++++++-- src/Utils/numbers.jl | 38 --------------------------- 3 files changed, 19 insertions(+), 41 deletions(-) diff --git a/docs/src/lib/utils.md b/docs/src/lib/utils.md index 7c7cc280fd..d6c6a4db5a 100644 --- a/docs/src/lib/utils.md +++ b/docs/src/lib/utils.md @@ -72,7 +72,6 @@ LazySets.convert(::Type{Hyperplane{N}}, ::Expr; vars::Vector{Basic}=Basic[]) whe ```@docs sign_cadlag minmax -arg_minmax ``` ## Other functions diff --git a/src/ConcreteOperations/convex_hull.jl b/src/ConcreteOperations/convex_hull.jl index 9227b4f1a8..3918c0b62b 100644 --- a/src/ConcreteOperations/convex_hull.jl +++ b/src/ConcreteOperations/convex_hull.jl @@ -255,7 +255,7 @@ function _collinear_case!(points, A, B, C, D) # assign the points with max and min value in their second component # to the firsts points and the extra point to the third place, then # pop the point that was in the middle - min_y, max_y = arg_minmax(A[2], B[2], C[2]) + min_y, max_y = _arg_minmax(A[2], B[2], C[2]) points[1] = _get_i(min_y, A, B, C) points[2] = _get_i(max_y, A, B, C) points[3] = D @@ -265,7 +265,7 @@ function _collinear_case!(points, A, B, C, D) # assign the points with max and min value in their first component to # the firsts points and the extra point to the third place, then pop the # point that was in the middle - min_x, max_x = arg_minmax(A[1], B[1], C[1]) + min_x, max_x = _arg_minmax(A[1], B[1], C[1]) points[1] = _get_i(min_x, A, B, C) points[2] = _get_i(max_x, A, B, C) points[3] = D @@ -274,6 +274,23 @@ function _collinear_case!(points, A, B, C, D) return _three_points_2d!(points) end +# return the indices of the minimum and maximum of three numbers a, b, c +function _arg_minmax(a, b, c) + if a > b + min, max = b, a + imin, imax = 2, 1 + else + min, max = a, b + imin, imax = 1, 2 + end + if c > max + imax = 3 + elseif c < min + imin = 3 + end + return imin, imax +end + function _four_points_2d!(points::AbstractVector{<:AbstractVector{N}}) where {N} A, B, C, D = points[1], points[2], points[3], points[4] tri_ABC = right_turn(A, B, C) diff --git a/src/Utils/numbers.jl b/src/Utils/numbers.jl index c74bad771f..51e261378c 100644 --- a/src/Utils/numbers.jl +++ b/src/Utils/numbers.jl @@ -66,41 +66,3 @@ function minmax(a, b, c) end return min, max end - -""" - arg_minmax(a, b, c) - -Compute the indices of the minimum and maximum of three numbers a, b, c. - -### Input - -- `a` -- first number -- `b` -- second number -- `c` -- third number - -### Output - -The indices of the minimum and maximum of the three given numbers. - -### Examples - -```jldoctest -julia> LazySets.arg_minmax(1.4, 52.4, -5.2) -(3, 2) -``` -""" -function arg_minmax(a, b, c) - if a > b - min, max = b, a - imin, imax = 2, 1 - else - min, max = a, b - imin, imax = 1, 2 - end - if c > max - imax = 3 - elseif c < min - imin = 3 - end - return imin, imax -end