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
Eliminate double definitions.
Eliminate unneeded comments.
In common.scad redefine num_defined(), all_defined() and get_radius().
In geometry.scad:
- change name _dist to _dist2line
- simplify _point_above_below_segment() and triangle_area()
- change some arg names for uniformity (path>>poly)
- change point_in_polygon() to accept the Even-odd rule as alternative
- and other minor edits
Update tests_geometry to the new funcionalities.
Eliminate double definitions.
Eliminate unneeded comments.
In common.scad redefine num_defined(), all_defined() and get_radius().
In geometry.scad:
- change name _dist to _dist2line
- simplify _point_above_below_segment() and triangle_area()
- change some arg names for uniformity (path>>poly)
- change point_in_polygon() to accept the Even-odd rule as alternative
- and other minor edits
Update tests_geometry to the new funcionalities.
Eliminate double definitions.
Eliminate unneeded comments.
In common.scad redefine num_defined(), all_defined() and get_radius().
In geometry.scad:
- change name _dist to _dist2line
- simplify _point_above_below_segment() and triangle_area()
- change some arg names for uniformity (path>>poly)
- change point_in_polygon() to accept the Even-odd rule as alternative
- and other minor edits
Update tests_geometry to the new funcionalities.
Besides param validation and some formating, changes:
A. add new functions:
1. _valid_line()
2. _valid_plane()
3. line_from_points()
4. projection_on_plane()
5. points_on_plane()
B. rename/redefine/remove functions:
1. points_are_coplanar() >> coplanar()
2. collinear() works with list of points as well as coplanar()
3. find_noncollinear_points >> noncollinear_triple
4. collinear_indexed() removed
5. polygon_is_convex() >> is_convex_polygon()
C. recode/optimize the codes of the functions:
1. point_on_segment2d()
2. point_left_of_line2d()
3. distance_from_line()
4. line_closest_point()
5. plane_from_polygon()
6. _general_plane_line_intersection()
7. polygon_line_intersection()
8. find_circle_2tangents()
9. find_circle_3points()
10. polygon_area()
11. is_convex_polygon()
12. reindex_polygon()
13. centroid()
14. polygon_is_clockwise()
15. clockwise_polygon()
16. ccw_polygon()
The function name changes were updated in:
test_geometry.scad
hull.scad
rounding.scad
vnf.scad
Regression tests for the new external functions were included in test_geometry.scad.
Unsolved questions:
1. why sorting the indices in plane_from_points and polygon_line_intersection?
2. aren't redundant plane_from_polygon() and plane_from_points()?
cumsum broken in two to hide recursion args and avoid repetitive arg validations.
back_substitute changed to avoid repetitive arg validations in the recursion.
minor change in deriv2 and deriv3 to avoid an unecessary call to is_matrix.
change in is_matrix for better performance
any() and all() broken in two to avoid repetitive arg validation in the recursion and to hide recursion args.
change in polymult to call convolve
break of poly_div in two to avoid repetitive arg validations in the recursion.