pub fn offset_within(self, dx: isize, dy: isize, width: usize, height: usize) -> Option<Loc> {
        if let Some(x) = add(self.x, dx) {
            if let Some(y) = add(self.y, dy) {
                if x < width && y < height {
                    return Some(Loc::new(x, y));
                }
            }
        }

        return None;

        fn add(left: usize, right: isize) -> Option<usize> {
            match right.cmp(&0) {
                Ordering::Greater => left.checked_add(right as usize),
                Ordering::Less => left.checked_sub((-right) as usize),
                Ordering::Equal => Some(left),
            }
        }
    }
/// This adds a delta to a location, and returns the new location so long as
/// it is in the indicated rage; if not it returns None. It can have an x
/// co-ordinate from 0 to width-1, and y can go from 0 to height-1.
This adds a delta to a location, and returns the new location so long as
it is in the indicated rage; if not it returns None. It can have an x
co-ordinate from 0 to width-1, and y can go from 0 to height-1.
This adds a delta to a location and returns the new location so long as it is in the indicated rage ; if not it returns None . It can have an x co - ordinate from 0 to width - 1 and y can go from 0 to height - 1 .
pub fn offset_within(self, dx: isize, dy: isize, width: usize, height: usize) -> Option<Loc> {
        if let Some(x) = add(self.x, dx) {
            if let Some(y) = add(self.y, dy) {
                if x < width && y < height {
                    return Some(Loc::new(x, y));
                }
            }
        }
        return None;
        fn add(left: usize, right: isize) -> Option<usize> {
            match right.cmp(&0) {
                Ordering::Greater => left.checked_add(right as usize),
                Ordering::Less => left.checked_sub((-right) as usize),
                Ordering::Equal => Some(left),
            }
        }
    }
pub fn offset_within ( self , dx : isize , dy : isize , width : usize , height : usize ) -> Option < Loc > { if let Some ( x ) = add ( self . x , dx ) { if let Some ( y ) = add ( self . y , dy ) { if x < width && y < height { return Some ( Loc :: new ( x , y ) ) ; } } } return None ; fn add ( left : usize , right : isize ) -> Option < usize > { match right . cmp ( & 0 ) { Ordering :: Greater => left . checked_add ( right as usize ) , Ordering :: Less => left . checked_sub ( ( - right ) as usize ) , Ordering :: Equal => Some ( left ) , } } }
This adds a delta to a location, and returns the new location so long as
it is in the indicated rage; if not it returns None.
This adds a delta to a location and returns the new location so long as it is in the indicated rage ; if not it returns None .
self
dx
isize
dy
isize
width
usize
height
usize
self
dx
isize
dy
isize
width
usize
height
usize