Struct ggez::graphics::Rect

source ·
pub struct Rect {
    pub x: f32,
    pub y: f32,
    pub w: f32,
    pub h: f32,
}
Expand description

A simple 2D rectangle.

The origin of the rectangle is at the top-left, with x increasing to the right and y increasing down.

Fields§

§x: f32

X coordinate of the left edge of the rect.

§y: f32

Y coordinate of the top edge of the rect.

§w: f32

Total width of the rect

§h: f32

Total height of the rect.

Implementations§

source§

impl Rect

source

pub const fn new(x: f32, y: f32, w: f32, h: f32) -> Self

Create a new Rect.

source

pub fn fraction(x: f32, y: f32, w: f32, h: f32, reference: &Rect) -> Rect

Creates a new Rect a la Love2D’s love.graphics.newQuad, as a fraction of the reference rect’s size.

source

pub fn new_i32(x: i32, y: i32, w: i32, h: i32) -> Self

Create a new rect from i32 coordinates. Loses precision if the integers are too big to fit in f32’s.

source

pub const fn zero() -> Self

Create a new Rect with all values zero.

source

pub const fn one() -> Self

Creates a new Rect at [0.0, 0.0] with width and height 1.

source

pub const fn size(&self) -> Vector2<f32>

Gets the Rect’s width and height as a Vector2.

source

pub const fn point(&self) -> Point2<f32>

Gets the Rect’s x and y coordinates as a Point2.

source

pub fn center(&self) -> Point2<f32>

Gets the Rect’s center x and y coordinates as a Point2.

source

pub const fn left(&self) -> f32

Returns the left edge of the Rect

source

pub fn right(&self) -> f32

Returns the right edge of the Rect

source

pub const fn top(&self) -> f32

Returns the top edge of the Rect

source

pub fn bottom(&self) -> f32

Returns the bottom edge of the Rect

source

pub fn contains<P>(&self, point: P) -> boolwhere P: Into<Point2<f32>>,

Checks whether the Rect contains a Point

source

pub fn overlaps(&self, other: &Rect) -> bool

Checks whether the Rect overlaps another Rect

source

pub fn overlaps_circle( &self, point: impl Into<Point2<f32>>, radius: f32 ) -> bool

Checks whether the Rect overlaps a circle.

source

pub fn translate<V>(&mut self, offset: V)where V: Into<Vector2<f32>>,

Translates the Rect by an offset of (x, y)

source

pub fn move_to<P>(&mut self, destination: P)where P: Into<Point2<f32>>,

Moves the Rect’s origin to (x, y)

source

pub fn scale(&mut self, sx: f32, sy: f32)

Scales the Rect by a factor of (sx, sy), growing towards the bottom-left

source

pub fn rotate(&mut self, rotation: f32)

Calculated the new Rect around the rotated one.

source

pub fn combine_with(self, other: Rect) -> Rect

Returns a new Rect that includes all points of these two Rects.

Trait Implementations§

source§

impl AbsDiffEq<Rect> for Rect

§

type Epsilon = f32

Used for specifying relative comparisons.
source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
source§

impl Clone for Rect

source§

fn clone(&self) -> Rect

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Rect

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Rect

source§

fn default() -> Rect

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Rect

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<[f32; 4]> for Rect

source§

fn from(val: [f32; 4]) -> Self

Converts to this type from the input type.
source§

impl From<Rect> for [f32; 4]

source§

fn from(val: Rect) -> Self

Converts to this type from the input type.
source§

impl PartialEq<Rect> for Rect

source§

fn eq(&self, other: &Rect) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl RelativeEq<Rect> for Rect

source§

fn default_max_relative() -> Self::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
source§

fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool

The inverse of RelativeEq::relative_eq.
source§

impl Serialize for Rect

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for Rect

source§

impl StructuralPartialEq for Rect

Auto Trait Implementations§

§

impl RefUnwindSafe for Rect

§

impl Send for Rect

§

impl Sync for Rect

§

impl Unpin for Rect

§

impl UnwindSafe for Rect

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

impl<T> Has<T> for T

source§

fn retrieve(&self) -> &T

Method to retrieve the context type.
source§

impl<T> HasMut<T> for T

source§

fn retrieve_mut(&mut self) -> &mut T

Method to retrieve the context type as mutable.
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,