Struct rgx::math::size::Size

source ·
pub struct Size<T = f32> {
    pub w: T,
    pub h: T,
}
Expand description

Size.

Fields§

§w: T

Width.

§h: T

Height.

Implementations§

source§

impl<T> Size<T>

source

pub fn map<S>(self, f: impl Fn(T) -> S) -> Size<S>

Map a size to another size.

source§

impl<T: Sized> Size<T>

source

pub const fn new(width: T, height: T) -> Self

Create a new size.

source§

impl Size<f32>

source

pub fn expand(self) -> Size

Returns a new Size, with width and height rounded away from zero to the nearest integer, unless they are already an integer.

Examples
use rgx::math::Size;

let size_pos = Size::new(3.3, 3.6).expand();
assert_eq!(size_pos.w, 4.0);
assert_eq!(size_pos.h, 4.0);

let size_neg = Size::new(-3.3, -3.6).expand();
assert_eq!(size_neg.w, -4.0);
assert_eq!(size_neg.h, -4.0);
source

pub fn is_empty(self) -> bool

Whether this size has zero area.

Note: a size with negative area is not considered empty.

source

pub fn clamp(self, min: Size, max: Size) -> Self

Returns a new size bounded by min and max.

Examples
use rgx::math::Size;

let this = Size::new(0., 100.);
let min = Size::new(10., 10.,);
let max = Size::new(50., 50.);

assert_eq!(this.clamp(min, max), Size::new(10., 50.))
source§

impl<T: Mul<Output = T>> Size<T>

source

pub fn area(self) -> T

The area covered by this size.

Trait Implementations§

source§

impl<T: Add<Output = T>> Add<Size<T>> for Point2D<T>

§

type Output = Point2D<T, ()>

The resulting type after applying the + operator.
source§

fn add(self, other: Size<T>) -> Self

Performs the + operation. Read more
source§

impl<T: Clone> Clone for Size<T>

source§

fn clone(&self) -> Size<T>

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<T: Debug> Debug for Size<T>

source§

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

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

impl<T: Default> Default for Size<T>

source§

fn default() -> Size<T>

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

impl Div<f32> for Size<f32>

§

type Output = Size<f32>

The resulting type after applying the / operator.
source§

fn div(self, rhs: f32) -> Self::Output

Performs the / operation. Read more
source§

impl<T> From<[T; 2]> for Size<T>

source§

fn from([w, h]: [T; 2]) -> Self

Converts to this type from the input type.
source§

impl<T> From<(T, T)> for Size<T>

source§

fn from((w, h): (T, T)) -> Self

Converts to this type from the input type.
source§

impl From<LogicalSize> for Size

source§

fn from(other: LogicalSize) -> Self

Converts to this type from the input type.
source§

impl<T> From<Size<T>> for [T; 2]

source§

fn from(size: Size<T>) -> Self

Converts to this type from the input type.
source§

impl From<Size<u32>> for Size<f32>

source§

fn from(other: Size<u32>) -> Self

Converts to this type from the input type.
source§

impl From<Size<usize>> for Size<u32>

source§

fn from(other: Size<usize>) -> Self

Converts to this type from the input type.
source§

impl<T: Copy> From<T> for Size<T>

source§

fn from(n: T) -> Self

Converts to this type from the input type.
source§

impl<T> From<Vector2D<T, ()>> for Size<T>

source§

fn from(other: Vector2D<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Mul<Output = T> + Copy> Mul<T> for Size<T>

§

type Output = Size<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
source§

impl<T: PartialEq> PartialEq<Size<T>> for Size<T>

source§

fn eq(&self, other: &Size<T>) -> 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<T: Zero + PartialEq> Zero for Size<T>

source§

const ZERO: Self = _

source§

fn is_zero(&self) -> bool

source§

impl<T: Copy> Copy for Size<T>

source§

impl<T: Eq> Eq for Size<T>

source§

impl<T> StructuralEq for Size<T>

source§

impl<T> StructuralPartialEq for Size<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Size<T>where T: RefUnwindSafe,

§

impl<T> Send for Size<T>where T: Send,

§

impl<T> Sync for Size<T>where T: Sync,

§

impl<T> Unpin for Size<T>where T: Unpin,

§

impl<T> UnwindSafe for Size<T>where T: UnwindSafe,

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

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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