Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rect shifted logic #1398

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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