georust / gdal

Rust bindings for GDAL
https://crates.io/crates/gdal
MIT License
359 stars 94 forks source link

Buffer indexing #554

Closed srenevey closed 2 weeks ago

srenevey commented 1 month ago

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?

lnicola commented 1 month ago

Currently there's a bug in the bounds checking done on indexing (see https://github.com/georust/gdal/pull/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 :slightly_smiling_face:.

srenevey commented 1 month ago

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

lnicola commented 2 weeks ago

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