Struct sdl2::rect::Rect
[−]
[src]
pub struct Rect { /* fields omitted */ }
A rectangle.
Methods
impl Rect
[src]
fn new(x: i32, y: i32, width: u32, height: u32) -> Rect
Creates a new rectangle from the given values.
The width and height are clamped to ensure that the right and bottom sides of the rectangle does not exceed i32::max_value(). (The value 2147483647, the maximal positive size of an i32)
This means that the rect size will behave oddly if you move it very far to the right or downwards on the screen.
fn from_center<P>(center: P, width: u32, height: u32) -> Rect where P: Into<Point>
Creates a new rectangle centered on the given position.
The width and height are clamped to ensure that the right and bottom sides of the rectangle does not exceed i32::max_value(). (The value 2147483647, the maximal positive size of an i32)
This means that the rect size will behave oddly if you move it very far to the right or downwards on the screen.
fn x(&self) -> i32
The horizontal position of this rectangle.
fn y(&self) -> i32
The vertical position of this rectangle.
fn width(&self) -> u32
The width of this rectangle.
fn height(&self) -> u32
The height of this rectangle.
fn size(&self) -> (u32, u32)
Returns the width and height of this rectangle.
fn set_x(&mut self, x: i32)
Sets the horizontal position of this rectangle to the given value, clamped to be less than or equal to i32::max_value() / 2.
fn set_y(&mut self, y: i32)
Sets the vertical position of this rectangle to the given value, clamped to be less than or equal to i32::max_value() / 2.
fn set_width(&mut self, width: u32)
Sets the width of this rectangle to the given value, clamped to be less than or equal to i32::max_value() / 2.
fn set_height(&mut self, height: u32)
Sets the height of this rectangle to the given value, clamped to be less than or equal to i32::max_value() / 2.
fn left(&self) -> i32
Returns the x-position of the left side of this rectangle.
fn right(&self) -> i32
Returns the x-position of the right side of this rectangle.
fn top(&self) -> i32
Returns the y-position of the top side of this rectangle.
fn bottom(&self) -> i32
Returns the y-position of the bottom side of this rectangle.
fn center(&self) -> Point
Returns the center position of this rectangle.
Note that if the width or height is not a multiple of two, the center will be rounded down.
Example
use sdl2::rect::{Rect,Point}; let rect = Rect::new(1,0,2,3); assert_eq!(Point::new(2,1),rect.center());
fn top_left(&self) -> Point
Returns the top-left corner of this rectangle.
Example
use sdl2::rect::{Rect, Point}; let rect = Rect::new(1, 0, 2, 3); assert_eq!(Point::new(1, 0), rect.top_left());
fn top_right(&self) -> Point
Returns the top-right corner of this rectangle.
Example
use sdl2::rect::{Rect, Point}; let rect = Rect::new(1, 0, 2, 3); assert_eq!(Point::new(3, 0), rect.top_right());
fn bottom_left(&self) -> Point
Returns the bottom-left corner of this rectangle.
Example
use sdl2::rect::{Rect, Point}; let rect = Rect::new(1, 0, 2, 3); assert_eq!(Point::new(1, 3), rect.bottom_left());
fn bottom_right(&self) -> Point
Returns the bottom-right corner of this rectangle.
Example
use sdl2::rect::{Rect, Point}; let rect = Rect::new(1, 0, 2, 3); assert_eq!(Point::new(3, 3), rect.bottom_right());
fn set_right(&mut self, right: i32)
Sets the position of the right side of this rectangle to the given value, clamped to be less than or equal to i32::max_value() / 2.
fn set_bottom(&mut self, bottom: i32)
Sets the position of the bottom side of this rectangle to the given value, clamped to be less than or equal to i32::max_value() / 2.
fn center_on<P>(&mut self, point: P) where P: Into<(i32, i32)>
Centers the rectangle on the given point.
fn offset(&mut self, x: i32, y: i32)
Move this rect and clamp the positions to prevent over/underflow. This also clamps the size to prevent overflow.
fn reposition<P>(&mut self, point: P) where P: Into<(i32, i32)>
Moves this rect to the given position after clamping the values.
fn resize(&mut self, width: u32, height: u32)
Resizes this rect to the given size after clamping the values.
fn contains<P>(&self, point: P) -> bool where P: Into<(i32, i32)>
Checks whether this rect contains a given point.
fn raw(&self) -> *const SDL_Rect
Returns the underlying C Rect.
fn raw_mut(&mut self) -> *mut SDL_Rect
fn raw_slice(slice: &[Rect]) -> *const SDL_Rect
fn from_ll(raw: SDL_Rect) -> Rect
fn from_enclose_points(points: &[Point],
clipping_rect: Option<Rect>)
-> Option<Rect>
clipping_rect: Option<Rect>)
-> Option<Rect>
Calculate a minimal rectangle enclosing a set of points. If a clipping rectangle is given, only points that are within it will be considered.
fn has_intersection(&self, other: Rect) -> bool
Determine whether two rectangles intersect.
fn intersection(&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)>
Calculates the intersection of a rectangle and a line segment and returns the points of their intersection.
Trait Implementations
impl Debug for Rect
[src]
impl Clone for Rect
[src]
fn clone(&self) -> Rect
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Copy for Rect
[src]
impl PartialEq for Rect
[src]
fn eq(&self, __arg_0: &Rect) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Rect) -> bool
This method tests for !=
.
impl Eq for Rect
[src]
impl Hash for Rect
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0
Feeds a slice of this type into the state provided.
impl Into<(i32, i32, u32, u32)> for Rect
[src]
impl From<(i32, i32, u32, u32)> for Rect
[src]
impl BitAnd<Rect> for Rect
[src]
type Output = Option<Rect>
The resulting type after applying the &
operator
fn bitand(self, rhs: Rect) -> Option<Rect>
The method for the &
operator