There were bugs in the previous sorting functions. They didn't check the homogeneity of the input list before calling _sort_scalars and _sort_vectors. The bug might result in wrong order and missing list elements in the output.
Besides correcting the bug a recode of all sorting functions result in better performance and a enlargement of their scope. With the new functions, list of vectors of any dimension may be sorted, even with idx given, with the native comparison operators. The scope of indexed sorting is also extended.
The file test_arrays has been extended to check the new funcionality.
New functions:
is_homogeneous - checks if a list has elements of the same type (although not distinguing booleans from numbers) up to a given depth
_sort_vectors - internal function to sort homgeneous lists of vectors using native comparison operators; extends the scope of the previous _sort_vectors# functions with better performance
_lexical_sort - internal function to sort non-homogeneous lists; uses compare_vals
_indexed_sort - internal function to perform indexed sorting of non-homogeneous lists; uses compar_vals
Changed/reviewed functions:
_valid_idx - doesn't requires the input of imin and imax args
sort - explores the internal functions to get better performance and an enlarged scope
sortidx - explores the internal functions to get better performance and an enlarged scope
_sort_general - just for sortings of non-homogeneous lists using compare_vals
_array_dim_recurse - changed for bit better performance
Functions eliminated:
_sort_vectors1
_sort_vectors2
_sort_vectors3
_sort_vectors4
Optimize _sort_general and change accordingly sort and sortidx.
Introduce _valid_idx() to simplify teh validations of arg idx.
Add input validation to subindex().
Here is an extensive review of common.scad, vectors.scad, arrays.scad and their regression test codes. The changes were mostly in input data check and format. Some few functions got more changes either to adapt them to the new asserts or because a better (faster, simpler) code was found.
Another change was moving add_scalar from vectors.scad to arrays.scad. It is in fact an array operation. Some few documentation examples and test codes were added. Some function argument names were changed to keep them consistent with the names they have in other similar functions. That name changes were not as extensive as I would like but it is advisable to favor users.
Most, but not all, changed function codes are followed by a comment with a short summary of the changes done. Those comments always start with:
//***
I can eliminate those comments before a merge is done or in a second round.
Refactorigng of list_set(), list_insert() and list_remove() without any sorting and speed gain.
Some argument names changed for consistence between functions.
test_array() updated.