Skip to content

Clarify behavior of GenericImage::copy_within #3006

@RunDevelopment

Description

@RunDevelopment

/// 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions