@@ -214,20 +214,23 @@ function get_normals(points::AbstractArray; k::Int=10)
214214end
215215
216216"""
217- sort_pts(pts::AbstractMatrix; xy::Bool=true )
217+ sort_pts(pts::AbstractMatrix)
218218
219219Description:
220220---
221- If `xy` is true, sort the points in `pts` by the y-, and then x-coordinates (2/3D).
222- If `xy` is false, sort the points by the z-, y-, and then x-coordinates (3D).
221+ Sort the points in `pts` by the y-, and then x-coordinates (2D).
222+ Sort the points in `pts` by the y-, and then x-coordinates (3D), where `z = false` (by default is `true`).
223+ Sort the points in `pts` by the y-, x-, and then z-coordinates (3D).
224+
223225"""
224- function sort_pts (pts:: AbstractMatrix ; xy:: Bool = true )
225- if size (pts, 2 ) == 2 || xy
226- perm = sortperm (axes (pts, 1 ), by = i -> (pts[i, 2 ], pts[i, 1 ]))
227- elseif size (pts, 2 ) == 3 🍻
228- perm = sortperm (axes (pts, 1 ), by = i -> (pts[i, 2 ], pts[i, 1 ], pts[i, 3 ]))
226+ function sort_pts (pts:: AbstractMatrix ; z:: Bool = true )
227+ dims = size (pts, 2 )
228+ if (dims == 2 ) || ! z
229+ sorted_points = sortslices (pts; dims= 1 , by = r -> (r[1 ], r[2 ]))
230+ elseif dims == 3
231+ sorted_points = sortslices (pts; dims= 1 , by = r -> (r[3 ], r[1 ], r[2 ]))
229232 else
230233 throw (ArgumentError (" The input points should have 2 or 3 rows (2/3D)" ))
231234 end
232- return Array (pts[perm, :] )
235+ return Array (sorted_points )
233236end
0 commit comments