Closed yoanlcq closed 5 years ago
The 0px space is an interesting use case.
When width and height is 0, the formula for minimum required buffer size fails:
let buf = &mut self.buf[start .. start + self.stride * height + width - self.stride];
OK, removing the restriction on width/height wasn't too hard. I've left requirement for stride
to be non-0, because buf.chunks(0)
makes no sense.
Thanks, and good point ! At first sight I would have thought it would be OK for stride to be zero, but indeed it's not. Infinite loops are no fun :)
Currently, width and height are not allowed to be zero. In a way, this makes sense, but IMHO it is surprising and impractical.
Vec
or slice to be empty; In fact this is true of all collections that I know of, and it's quite convenient. Images are "different" because there's no such thing as a 0x0 image; However, there is such a thing as an empty 2D container; For instance...I decided to change my API so that it returns glyph bitmaps as
ImgVec
s for convenience, but suddenly I get a panic; turns out, the ' ' (space) character effectively yields a 0x0 bitmap. My issue is that it is was actually fine, and the code should have kept running as normal. Now I have to check that the height is non-zero every time, and my API now returnsOption<ImgVec<...>>
instead of justImgVec<...>
, introducing some noise and branching (but these are nitpicks).Of course the issue was not hard to find and it's not going to show up anytime soon. The point is that my code worked fine until I brought
imgref
in... x)This kind of decision is inherently opinionated and I don't wish to enforce my point of view. It might also be interesting to see what's the stance of similar crates on the matter. :)