Skip to content

Commit 79f9ac7

Browse files
authored
Merge pull request #1398 from Player01osu/fix-rect-shifted-logic
Fix rect shifted logic
2 parents c4ed97c + 93be31c commit 79f9ac7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/sdl2/rect.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ impl Rect {
231231
///
232232
/// ```
233233
/// use sdl2::rect::Rect;
234-
/// assert_eq!(Rect::new(0, 0, 10, 10).left_shifted(5), Rect::new(-5, 0, 10, 10));
234+
/// assert_eq!(Rect::new(5, 5, 10, 10).left_shifted(5), Rect::new(0, 5, 10, 10));
235235
/// ```
236236
pub fn left_shifted(mut self, offset: i32) -> Rect {
237-
self.offset(-offset, self.y());
237+
self.offset(-offset, 0);
238238
self
239239
}
240240

@@ -244,10 +244,10 @@ impl Rect {
244244
///
245245
/// ```
246246
/// use sdl2::rect::Rect;
247-
/// assert_eq!(Rect::new(0, 0, 10, 10).right_shifted(5), Rect::new(5, 0, 10, 10));
247+
/// assert_eq!(Rect::new(5, 5, 10, 10).right_shifted(5), Rect::new(10, 5, 10, 10));
248248
/// ```
249249
pub fn right_shifted(mut self, offset: i32) -> Rect {
250-
self.offset(offset, self.y());
250+
self.offset(offset, 0);
251251
self
252252
}
253253

@@ -257,10 +257,10 @@ impl Rect {
257257
///
258258
/// ```
259259
/// use sdl2::rect::Rect;
260-
/// assert_eq!(Rect::new(0, 0, 10, 10).top_shifted(5), Rect::new(0, -5, 10, 10));
260+
/// assert_eq!(Rect::new(5, 5, 10, 10).top_shifted(5), Rect::new(5, 0, 10, 10));
261261
/// ```
262262
pub fn top_shifted(mut self, offset: i32) -> Rect {
263-
self.offset(self.x(), -offset);
263+
self.offset(0, -offset);
264264
self
265265
}
266266

@@ -270,10 +270,10 @@ impl Rect {
270270
///
271271
/// ```
272272
/// use sdl2::rect::Rect;
273-
/// assert_eq!(Rect::new(0, 0, 10, 10).bottom_shifted(5), Rect::new(0, 5, 10, 10));
273+
/// assert_eq!(Rect::new(5, 5, 10, 10).bottom_shifted(5), Rect::new(5, 10, 10, 10));
274274
/// ```
275275
pub fn bottom_shifted(mut self, offset: i32) -> Rect {
276-
self.offset(self.x(), offset);
276+
self.offset(0, offset);
277277
self
278278
}
279279

@@ -1094,12 +1094,12 @@ mod test {
10941094
#[test]
10951095
fn shifted() {
10961096
// Groups all functions into a single assertion
1097-
let rect = Rect::new(0, 0, 10, 10)
1097+
let rect = Rect::new(5, 5, 10, 10)
10981098
.left_shifted(5)
10991099
.right_shifted(5)
11001100
.top_shifted(5)
11011101
.bottom_shifted(5);
1102-
assert_eq!(rect, Rect::new(0, 0, 10, 10));
1102+
assert_eq!(rect, Rect::new(5, 5, 10, 10));
11031103
}
11041104

11051105
#[test]

0 commit comments

Comments
 (0)