Skip to content

Commit 5f65b60

Browse files
authored
Merge pull request #1493 from noahprice-dev/patch-1
Add `Rect::origin` and update `Rect::new` to specify the origin location of rectangles.
2 parents 89f3ebe + c218534 commit 5f65b60

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ In this file will be listed the changes, especially the breaking ones that one s
22
when upgrading from a version of rust-sdl2 to another.
33

44
### Next
5+
[PR #1493](https://github.com/Rust-SDL2/rust-sdl2/pull/1493) Add `Rect::origin` and specifies origin location in `Rect::new`.
56

67
[PR #1472](https://github.com/Rust-SDL2/rust-sdl2/pull/1472) Add `Canvas::render_geometry`, `Canvas::render_geometry_raw` and an example that uses them both. Both these bindings use `SDL_RenderGeometryRaw`.
78

src/sdl2/rect.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::ptr;
1212

1313
/// The maximal integer value that can be used for rectangles.
1414
///
15-
/// This value is smaller than strictly needed, but is useful in ensuring that
15+
/// This value is smaller than is strictly needed, but is useful in ensuring that
1616
/// rect sizes will never have to be truncated when clamping.
1717
pub fn max_int_value() -> u32 {
1818
i32::MAX as u32 / 2
@@ -115,7 +115,7 @@ impl Hash for Rect {
115115
}
116116

117117
impl Rect {
118-
/// Creates a new rectangle from the given values.
118+
/// Creates a new rectangle from the given values with an origin in the Upper Left.
119119
///
120120
/// The width and height are clamped to ensure that the right and bottom
121121
/// sides of the rectangle does not exceed i32::MAX (the value
@@ -236,7 +236,17 @@ impl Rect {
236236
pub fn bottom(&self) -> i32 {
237237
self.raw.y + self.raw.h
238238
}
239-
239+
240+
/// Returns the origin of the rectangle (Top Left)
241+
///
242+
/// ```
243+
/// use sdl2::rect::Rect;
244+
/// assert_eq!(Rect::new(5, 5, 10, 10).origin(), (5,5));
245+
/// ```
246+
pub fn origin(&self) -> (i32, i32) {
247+
(self.left(), self.top())
248+
}
249+
240250
/// Shifts this rectangle to the left by `offset`.
241251
///
242252
/// # Example

0 commit comments

Comments
 (0)