Skip to content

Commit

Permalink
Merge pull request #1398 from Player01osu/fix-rect-shifted-logic
Browse files Browse the repository at this point in the history
Fix rect shifted logic
  • Loading branch information
Cobrand authored Jun 13, 2024
2 parents c4ed97c + 93be31c commit 79f9ac7
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/sdl2/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ impl Rect {
///
/// ```
/// use sdl2::rect::Rect;
/// assert_eq!(Rect::new(0, 0, 10, 10).left_shifted(5), Rect::new(-5, 0, 10, 10));
/// assert_eq!(Rect::new(5, 5, 10, 10).left_shifted(5), Rect::new(0, 5, 10, 10));
/// ```
pub fn left_shifted(mut self, offset: i32) -> Rect {
self.offset(-offset, self.y());
self.offset(-offset, 0);
self
}

Expand All @@ -244,10 +244,10 @@ impl Rect {
///
/// ```
/// use sdl2::rect::Rect;
/// assert_eq!(Rect::new(0, 0, 10, 10).right_shifted(5), Rect::new(5, 0, 10, 10));
/// assert_eq!(Rect::new(5, 5, 10, 10).right_shifted(5), Rect::new(10, 5, 10, 10));
/// ```
pub fn right_shifted(mut self, offset: i32) -> Rect {
self.offset(offset, self.y());
self.offset(offset, 0);
self
}

Expand All @@ -257,10 +257,10 @@ impl Rect {
///
/// ```
/// use sdl2::rect::Rect;
/// assert_eq!(Rect::new(0, 0, 10, 10).top_shifted(5), Rect::new(0, -5, 10, 10));
/// assert_eq!(Rect::new(5, 5, 10, 10).top_shifted(5), Rect::new(5, 0, 10, 10));
/// ```
pub fn top_shifted(mut self, offset: i32) -> Rect {
self.offset(self.x(), -offset);
self.offset(0, -offset);
self
}

Expand All @@ -270,10 +270,10 @@ impl Rect {
///
/// ```
/// use sdl2::rect::Rect;
/// assert_eq!(Rect::new(0, 0, 10, 10).bottom_shifted(5), Rect::new(0, 5, 10, 10));
/// assert_eq!(Rect::new(5, 5, 10, 10).bottom_shifted(5), Rect::new(5, 10, 10, 10));
/// ```
pub fn bottom_shifted(mut self, offset: i32) -> Rect {
self.offset(self.x(), offset);
self.offset(0, offset);
self
}

Expand Down Expand Up @@ -1094,12 +1094,12 @@ mod test {
#[test]
fn shifted() {
// Groups all functions into a single assertion
let rect = Rect::new(0, 0, 10, 10)
let rect = Rect::new(5, 5, 10, 10)
.left_shifted(5)
.right_shifted(5)
.top_shifted(5)
.bottom_shifted(5);
assert_eq!(rect, Rect::new(0, 0, 10, 10));
assert_eq!(rect, Rect::new(5, 5, 10, 10));
}

#[test]
Expand Down

0 comments on commit 79f9ac7

Please sign in to comment.