Tom Verbeure
11/12/2008 6:40:00 AM
On Nov 11, 10:13 pm, Peña, Botp <b...@delmonte-phil.com> wrote:
> From: Tom Verbeure [mailto:hom...@gmail.com]
> # indices = 1.upto(points.size)
> # zipped = indices.zip(distances, points)
>
> (1..points.size).zip(distances,points)
>
> but arrays have builtin indices, why not
>
> distances.zip(points)
>
> ?
In later steps, the list gets sorted by the 'distance' field, then
truncated and then sorted back in the original order, but with some
inside points removed.
Like this:
indices = (1..points.size).to_a
zipped = indices.zip(distances, points)
zipped = zipped.delete_if { |x| x[1].nil? }
zipped.sort! { |x,y| y[1] <=> x[1] }
zipped = zipped.slice(0, max_nr_points)
# Sort back in original order
zipped.sort! { |x,y| x[0] <=> y[0] }
points = zipped.collect { |p| p[2] }
Tom