image-rs / image

Encoding and decoding images in Rust
Apache License 2.0
4.86k stars 597 forks source link

EnumeratePixels and EnumerateRows should implement DoubleEndedIterator #2298

Open Pauan opened 1 month ago

Pauan commented 1 month ago

The EnumeratePixels and EnumerateRows iterators should implement DoubleEndedIterator.

This will make it possible to iterate in reverse order (for example right-to-left instead of left-to-right).

The Pixels and Rows iterators already implement DoubleEndedIterator.

Shnatsel commented 1 month ago

Could you provide an example where this would be actually useful? What do you need this functionality for?

Pauan commented 1 month ago

I'm creating a custom CAM program for CNC machines. The program loads an image, and then iterates over the pixels of the image to generate the GCode.

But it needs to iterate in a specific order to generate optimal GCode. The default order (left-to-right, top-to-bottom) creates suboptimal GCode, which slows down the CNC machine by ~50%.

With DoubleEndedIterator it can iterate in the perfect order.

Shnatsel commented 1 month ago

I see! Yes, an implementation of DoubleEndedIterator would be nice to have, and shouldn't be difficult. A PR for it would be welcome.