georust/gdal

Buffer indexing

srenevey opened this issue · 3 comments

Using gdal 0.17.0, the following code prints different sequences of values:

// 3 columns, 4 rows
let buffer = Buffer::new((3, 4), (0..3 * 4).collect());
println!("{:?}", buffer.data()); // prints [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
let shape = buffer.shape();
for col in 0..shape.0 {
  for row in 0..shape.1 {
    print!("{}", buffer[(col, row)]); // prints 0 1 2 3 3 4 5 6 6 7 8 9
  }
}

I'm expecting to see the same sequence in both cases. What am I doing wrong?

Currently there's a bug in the bounds checking done on indexing (see #550). It's supposed to be (row, col), but we might drop the Index impl altogether (if you think it's useful, please post there).

That still doesn't seem to explain the output you're getting, but I'm not yet awake 🙂.

Thank you for your answer. When will the fix be merged?

This was fixed in #550 and will hopefully be published soon.