Struct sdl2::rect::Rect
[−]
[src]
pub struct Rect { // some fields omitted }
Immutable rectangle type, consisting of x, y, width and height.
Rectangle invariants:
width
andheight
are positive and non-zero.width
andheight
are less than1<<31
(2,147,483,648).x + width
andy + height
do not overflow.
These invariants exist in the wrapper because many SDL functions that accept rectangles don't behave predictably if the above conditions aren't met.
Methods
impl Rect
fn raw(&self) -> *const SDL_Rect
fn raw_from_option(v: Option<&Rect>) -> *const SDL_Rect
fn raw_mut_from_option(v: Option<&mut Rect>) -> *mut SDL_Rect
fn raw_slice(slice: &[Rect]) -> *const SDL_Rect
fn from_ll(raw: SDL_Rect) -> SdlResult<Option<Rect>>
fn new(x: i32, y: i32, width: u32, height: u32) -> SdlResult<Option<Rect>>
Creates a new rectangle.
If width
or height
is zero, Ok(None)
is returned.
If the arguments violate any of the other rectangle invariants, an error is returned.
fn new_unwrap(x: i32, y: i32, width: u32, height: u32) -> Rect
Creates a new rectangle. Convenience function that unwraps the result of Rect::new()
twice.
Make sure to only use this function if you're certain the rectangle meets all the invariants.
fn offset(&self, x: i32, y: i32) -> SdlResult<Rect>
Offsets the rectangle's x and y coordinates.
If the new rectangle violates any invariants, an error is returned.
fn xywh(&self) -> (i32, i32, u32, u32)
fn x(&self) -> i32
fn y(&self) -> i32
fn width(&self) -> u32
fn height(&self) -> u32
fn from_enclose_points(points: &[Point], clip: Option<Rect>) -> SdlResult<Option<Rect>>
Calculate a minimal rectangle enclosing a set of points.
Returns Ok(None)
if there are no points, or no points within the clipping rectangle.
Returns an error if the resulting rectangle's dimensions are too large for the points.
fn has_intersection(&self, other: &Rect) -> bool
Determine whether two rectangles intersect.
fn intersect(&self, other: &Rect) -> Option<Rect>
Calculate the intersection of two rectangles. The bitwise AND operator &
can also be used.
fn union(&self, other: &Rect) -> Rect
Calculate the union of two rectangles. The bitwise OR operator |
can also be used.
fn intersect_line(&self, start: Point, end: Point) -> Option<(Point, Point)>
Calculate the intersection of a rectangle and line segment. return points of intersection.
Trait Implementations
impl Into<(i32, i32, u32, u32)> for Rect
impl BitAnd<Rect> for Rect
Intersect
impl<'a> BitAnd<&'a Rect> for Rect
Intersect
impl<'a> BitAnd<Rect> for &'a Rect
Intersect
impl<'a> BitAnd<&'a Rect> for &'a Rect
Intersect
impl BitOr<Rect> for Rect
Union
impl<'a> BitOr<&'a Rect> for Rect
Union
impl<'a> BitOr<Rect> for &'a Rect
Union
impl<'a> BitOr<&'a Rect> for &'a Rect
Union