|
/// Copies all of the pixels from one part of this image to another part of this image. |
|
/// |
|
/// The destination rectangle of the copy is specified with the top-left corner placed at (x, y). |
|
/// |
|
/// # Returns |
|
/// `true` if the copy was successful, `false` if the image could not |
|
/// be copied due to size constraints. |
|
fn copy_within(&mut self, source: Rect, x: u32, y: u32) -> bool { |
|
let Rect { |
|
x: sx, |
|
y: sy, |
|
width, |
|
height, |
|
} = source; |
|
let dx = x; |
|
let dy = y; |
|
assert!(sx < self.width() && dx < self.width()); |
|
assert!(sy < self.height() && dy < self.height()); |
|
if self.width() - dx.max(sx) < width || self.height() - dy.max(sy) < height { |
|
return false; |
|
} |
This method panics when the offset of the source rectangle or target rectangle (given by x and y) are outside the bounds of the image. This panic is not documented and seems unintentional given that copy_within could just return false.
What is the intended behavior here?
If panicking is intended, it should be documented. If not, then it should return false.
I git blamed a bit and found the source.
image/src/images/generic_image.rs
Lines 278 to 298 in 03f097f
This method panics when the offset of the source rectangle or target rectangle (given by
xandy) are outside the bounds of the image. This panic is not documented and seems unintentional given thatcopy_withincould just returnfalse.What is the intended behavior here?
If panicking is intended, it should be documented. If not, then it should return
false.I git blamed a bit and found the source.