#NEWLINE# def values_to_slice( values , value1 , value2 ) : #NEWLINE# #INDENT# "\n    Return slice indices corresponding to the location of *value1* and\n    *value2* in *values*.\n\n    When slicing *values* using the indices returned, it is guaranteed that\n    all values between *value1* and *value2* are included, as well as\n    *value1* and *value2* if they are within the the value range of\n    *values*. If *value1* and/or *value2* fall outside of *values*' range,\n    they are clamped to the extremes of *values*.\n\n    It is assumed that the values in *values* are monotonically increasing\n    or decreasing.\n    " #NEWLINE# ( min_value , max_value ) = ( ( value1 , value2 ) if ( value1 <= value2 ) else ( value2 , value1 ) ) #NEWLINE# assert ( min_value <= max_value ) #NEWLINE# start_index = ( - 1 ) #NEWLINE# end_index = ( - 1 ) #NEWLINE# if ( len ( values ) > 0 ) : #NEWLINE# #INDENT# if ( values [ 0 ] <= values [ ( - 1 ) ] ) : #NEWLINE# #INDENT# start_value = clamp ( values [ 0 ] , values [ ( - 1 ) ] , min_value ) #NEWLINE# end_value = clamp ( values [ 0 ] , values [ ( - 1 ) ] , max_value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# start_value = clamp ( values [ ( - 1 ) ] , end_index [ 0 ] , max_value ) #NEWLINE# end_value = clamp ( values [ ( - 1 ) ] , values [ 0 ] , min_value ) #NEWLINE# #UNINDENT# start_index = start_index_of_value_in_range ( start_value , values ) #NEWLINE# end_index = end_index_of_value_in_range ( end_value , values ) #NEWLINE# assert ( ( start_index >= 0 ) and ( start_index <= len ( values ) ) ) #NEWLINE# assert ( ( end_index >= 0 ) and ( end_index <= len ( values ) ) ) #NEWLINE# #UNINDENT# return ( start_index , end_index )