Rectf

Struct Rectf 

Source
#[repr(C)]
pub struct Rectf { pub left: f32, pub top: f32, pub right: f32, pub bottom: f32, }
Expand description

Represents a rectangle defined by the coordinates of the upper-left corner (left, top) and the coordinates of the lower-right corner (right, bottom).

Fields§

§left: f32

The x-coordinate of the left edge of the rectangle.

§top: f32

The y-coordinate of the top edge of the rectangle.

§right: f32

The x-coordinate of the right edge of the rectangle.

§bottom: f32

The y-coordinate of the bottom edge of the rectangle.

Implementations§

Source§

impl Rectf

Source

pub const INFINITE: Rectf

A rect that holds the entire real space

Source

pub fn new(left: f32, top: f32, right: f32, bottom: f32) -> Rectf

Constructs the rectangle from components.

Source

pub fn from_points(p1: impl Into<Point2f>, p2: impl Into<Point2f>) -> Rectf

Constructs a rectangle that will encompass all of the axis-aligned space between the two provided points.

Source

pub fn from_center_size( center: impl Into<Point2f>, size: impl Into<Sizef>, ) -> Rectf

Constructs a rectangle given its desired center point and desired width and height.

Source

pub fn from_center_half_extent( center: impl Into<Point2f>, half_extents: impl Into<Vector2f>, ) -> Rectf

Constructs a rectangle given its desired center and the desired distance from the center to the corners.

Source

pub fn to_i32(&self) -> Recti

Converts this rectangle’s components to signed integers. Truncates values, perform manual rounding if you would like a different behavior.

Source

pub fn to_u32(&self) -> Rectu

Converts the components of the rectangle to unsigned integers. Beware this conversion if the components could be negative, you will experience unsigned casting underflow.

Source

pub fn rounded(&self) -> Rectf

Rounds the components to the nearest integers, rounding half-way values away from zero.

Source

pub fn size(&self) -> Sizef

Gets the width and height of this rectangle.

Source

pub fn center(&self) -> Point2f

Gets the center point of this rectangle.

Source

pub fn half_extent(&self) -> Vector2f

Gets the half-extent of the rectangle i.e. the vector from the center to the most-positive corner.

Source

pub fn corner(&self, corner: RectCorner) -> Point2f

Get the point of the specified corner.

Source

pub fn contains_point(&self, point: impl Into<Point2f>) -> bool

Determines if the specified point is located inside the rectangle.

Source

pub fn normalized(self) -> Self

Normalizes the rectangle to enforce the invariants left < right and top < bottom.

Source

pub fn translated_by(self, translation: impl Into<Vector2f>) -> Self

Translates the rectangle by the given vector.

Source

pub fn expanded_by(self, thickness: impl Into<Thicknessf>) -> Self

Expands the rectangle by the given margin.

Source

pub fn shrunken_by(self, thickness: impl Into<Thicknessf>) -> Self

Shrinks the rectangle by the given margin.

Source

pub fn combined_with(&self, other: impl Into<Rectf>) -> Self

Constructs a rectangle that contains both rectangles. Normalizes both arguments before performing the operation.

Trait Implementations§

Source§

impl Add<Vector2f> for Rectf

Source§

type Output = Rectf

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vector2f) -> Rectf

Performs the + operation. Read more
Source§

impl Clone for Rectf

Source§

fn clone(&self) -> Rectf

Returns a duplicate 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 Rectf

Source§

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

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

impl Default for Rectf

Source§

fn default() -> Rectf

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

impl<'de> Deserialize<'de> for Rectf

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 Rectf

Source§

fn from(p: [f32; 4]) -> Rectf

Converts to this type from the input type.
Source§

impl From<(Point2f, Point2f)> for Rectf

Source§

fn from((p1, p2): (Point2f, Point2f)) -> Rectf

Converts to this type from the input type.
Source§

impl From<(Point2f, Sizef)> for Rectf

Source§

fn from((center, size): (Point2f, Sizef)) -> Rectf

Converts to this type from the input type.
Source§

impl From<(Point2f, Vector2f)> for Rectf

Source§

fn from((center, half_extent): (Point2f, Vector2f)) -> Rectf

Converts to this type from the input type.
Source§

impl PartialEq for Rectf

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Rectf

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 Sub<Vector2f> for Rectf

Source§

type Output = Rectf

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vector2f) -> Rectf

Performs the - operation. Read more
Source§

impl Copy for Rectf

Source§

impl StructuralPartialEq for Rectf

Auto Trait Implementations§

§

impl Freeze for Rectf

§

impl RefUnwindSafe for Rectf

§

impl Send for Rectf

§

impl Sync for Rectf

§

impl Unpin for Rectf

§

impl UnwindSafe for Rectf

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

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