Struct kas::geom::Size

source ·
pub struct Size(pub i32, pub i32);
Expand description

A 2D size, also known as an extent

This is both a size and a relative position. One can add or subtract a size from a Coord. One can multiply a size by a scalar.

A Size is expected to be non-negative; some methods such as Size::new and implementations of subtraction will check this, but only in debug mode (similar to overflow checks on integers).

Subtraction is defined to be saturating subtraction.

This may be converted to Offset with from / into.

Tuple Fields§

§0: i32§1: i32

Implementations§

source§

impl Size

source

pub const ZERO: Size = _

The constant (0, 0)

source

pub const MIN: Size = _

The minimum value

source

pub const MAX: Size = _

The maximum value

source

pub fn lt(self, rhs: Size) -> bool

True when for all components, lhs < rhs

source

pub fn le(self, rhs: Size) -> bool

True when for all components, lhs ≤ rhs

source

pub fn ge(self, rhs: Size) -> bool

True when for all components, lhs ≥ rhs

source

pub fn gt(self, rhs: Size) -> bool

True when for all components, lhs > rhs

source

pub fn min(self, other: Size) -> Size

Return the minimum, componentwise

source

pub fn max(self, other: Size) -> Size

Return the maximum, componentwise

source

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

Restrict a value to the specified interval, componentwise

source

pub fn transpose(self) -> Size

Return the transpose (swap x and y values)

source

pub fn cwise_mul(self, rhs: Size) -> Size

Return the result of component-wise multiplication

source

pub fn cwise_div(self, rhs: Size) -> Size

Return the result of component-wise division

source

pub fn distance_l1(self) -> i32

Return the L1 (rectilinear / taxicab) distance

source

pub fn distance_l_inf(self) -> i32

Return the L-inf (max) distance

source

pub fn extract<D>(self, dir: D) -> i32
where D: Directional,

Extract one component, based on a direction

This merely extracts the horizontal or vertical component. It never negates it, even if the axis is reversed.

source

pub fn set_component<D>(&mut self, dir: D, value: i32)
where D: Directional,

Set one component of self, based on a direction

This does not negate components when the direction is reversed.

source§

impl Size

source

pub fn new(w: i32, h: i32) -> Size

Construct

In debug mode, this asserts that components are non-negative.

source

pub fn splat(n: i32) -> Size

Construct, using the same value on all axes

In debug mode, this asserts that components are non-negative.

source

pub fn aspect_scale_to(self, target: Size) -> Option<Size>

Scale to fit within the target size, keeping aspect ratio

If either dimension of self is 0, this returns None.

source§

impl Size

source

pub fn as_physical(self) -> Size

Convert to a “physical” [winit::dpi::Size]

This implies that the Size was calculated using the correct scale factor. Before the window has been constructed (when the scale factor is supposedly unknown) this should not be used.

source

pub fn as_logical(self) -> Size

Convert to a “logical” [winit::dpi::Size]

This implies that the Size was calculated using scale_factor = 1.

Trait Implementations§

source§

impl Add<Size> for Coord

§

type Output = Coord

The resulting type after applying the + operator.
source§

fn add(self, other: Size) -> Coord

Performs the + operation. Read more
source§

impl Add for Size

§

type Output = Size

The resulting type after applying the + operator.
source§

fn add(self, other: Size) -> Size

Performs the + operation. Read more
source§

impl AddAssign<Size> for Coord

source§

fn add_assign(&mut self, rhs: Size)

Performs the += operation. Read more
source§

impl AddAssign for Size

source§

fn add_assign(&mut self, rhs: Size)

Performs the += operation. Read more
source§

impl Clone for Size

source§

fn clone(&self) -> Size

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 Conv<(i32, i32)> for Size

source§

fn conv(v: (i32, i32)) -> Size

Convert from T to Self Read more
source§

fn try_conv(v: (i32, i32)) -> Result<Size, Error>

Try converting from T to Self Read more
source§

impl Conv<(u16, u16)> for Size

source§

fn try_conv(v: (u16, u16)) -> Result<Size, Error>

Try converting from T to Self Read more
§

fn conv(v: T) -> Self

Convert from T to Self Read more
source§

impl Conv<(u32, u32)> for Size

source§

fn try_conv(v: (u32, u32)) -> Result<Size, Error>

Try converting from T to Self Read more
§

fn conv(v: T) -> Self

Convert from T to Self Read more
source§

impl Conv<Offset> for Size

Convert an Offset into a Size

In debug mode this asserts that the result is non-negative.

source§

fn try_conv(v: Offset) -> Result<Size, Error>

Try converting from T to Self Read more
§

fn conv(v: T) -> Self

Convert from T to Self Read more
source§

impl<X> Conv<PhysicalSize<X>> for Size
where X: Cast<i32>,

source§

fn try_conv(size: PhysicalSize<X>) -> Result<Size, Error>

Try converting from T to Self Read more
§

fn conv(v: T) -> Self

Convert from T to Self Read more
source§

impl Conv<Size> for (u16, u16)

source§

fn try_conv(size: Size) -> Result<(u16, u16), Error>

Try converting from T to Self Read more
§

fn conv(v: T) -> Self

Convert from T to Self Read more
source§

impl Conv<Size> for (u32, u32)

source§

fn try_conv(size: Size) -> Result<(u32, u32), Error>

Try converting from T to Self Read more
§

fn conv(v: T) -> Self

Convert from T to Self Read more
source§

impl Conv<Size> for DVec2

source§

fn try_conv(arg: Size) -> Result<DVec2, Error>

Try converting from T to Self Read more
§

fn conv(v: T) -> Self

Convert from T to Self Read more
source§

impl Conv<Size> for LogicalSize

source§

fn try_conv(size: Size) -> Result<LogicalSize, Error>

Try converting from T to Self Read more
§

fn conv(v: T) -> Self

Convert from T to Self Read more
source§

impl Conv<Size> for Offset

source§

fn try_conv(v: Size) -> Result<Offset, Error>

Try converting from T to Self Read more
§

fn conv(v: T) -> Self

Convert from T to Self Read more
source§

impl Conv<Size> for Vec2

source§

fn try_conv(arg: Size) -> Result<Vec2, Error>

Try converting from T to Self Read more
§

fn conv(v: T) -> Self

Convert from T to Self Read more
source§

impl Conv<Size> for Vec2

source§

fn try_conv(size: Size) -> Result<Vec2, Error>

Try converting from T to Self Read more
§

fn conv(v: T) -> Self

Convert from T to Self Read more
source§

impl ConvApprox<DVec2> for Size

source§

fn try_conv_approx(arg: DVec2) -> Result<Size, Error>

Try converting from T to Self, allowing approximation of value Read more
§

fn conv_approx(x: T) -> Self

Converting from T to Self, allowing approximation of value Read more
source§

impl ConvApprox<Vec2> for Size

source§

fn try_conv_approx(arg: Vec2) -> Result<Size, Error>

Try converting from T to Self, allowing approximation of value Read more
§

fn conv_approx(x: T) -> Self

Converting from T to Self, allowing approximation of value Read more
source§

impl ConvFloat<DVec2> for Size

source§

fn try_conv_trunc(x: DVec2) -> Result<Size, Error>

Try converting to integer with truncation Read more
source§

fn try_conv_nearest(x: DVec2) -> Result<Size, Error>

Try converting to the nearest integer Read more
source§

fn try_conv_floor(x: DVec2) -> Result<Size, Error>

Try converting the floor to an integer Read more
source§

fn try_conv_ceil(x: DVec2) -> Result<Size, Error>

Try convert the ceiling to an integer Read more
§

fn conv_trunc(x: T) -> Self

Convert to integer with truncatation Read more
§

fn conv_nearest(x: T) -> Self

Convert to the nearest integer Read more
§

fn conv_floor(x: T) -> Self

Convert the floor to an integer Read more
§

fn conv_ceil(x: T) -> Self

Convert the ceiling to an integer Read more
source§

impl ConvFloat<Vec2> for Size

source§

fn try_conv_trunc(x: Vec2) -> Result<Size, Error>

Try converting to integer with truncation Read more
source§

fn try_conv_nearest(x: Vec2) -> Result<Size, Error>

Try converting to the nearest integer Read more
source§

fn try_conv_floor(x: Vec2) -> Result<Size, Error>

Try converting the floor to an integer Read more
source§

fn try_conv_ceil(x: Vec2) -> Result<Size, Error>

Try convert the ceiling to an integer Read more
§

fn conv_trunc(x: T) -> Self

Convert to integer with truncatation Read more
§

fn conv_nearest(x: T) -> Self

Convert to the nearest integer Read more
§

fn conv_floor(x: T) -> Self

Convert the floor to an integer Read more
§

fn conv_ceil(x: T) -> Self

Convert the ceiling to an integer Read more
source§

impl Debug for Size

source§

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

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

impl Default for Size

source§

fn default() -> Size

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

impl Div<i32> for Size

Divide a Size by an integer

In debug mode this asserts that the result is non-negative.

§

type Output = Size

The resulting type after applying the / operator.
source§

fn div(self, x: i32) -> Size

Performs the / operation. Read more
source§

impl From<(i32, i32)> for Size

source§

fn from(v: (i32, i32)) -> Size

Converts to this type from the input type.
source§

impl From<Size> for Margins

source§

fn from(size: Size) -> Margins

Converts to this type from the input type.
source§

impl Hash for Size

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Mul<i32> for Size

Multiply a Size by an integer

In debug mode this asserts that the result is non-negative.

§

type Output = Size

The resulting type after applying the * operator.
source§

fn mul(self, x: i32) -> Size

Performs the * operation. Read more
source§

impl PartialEq for Size

source§

fn eq(&self, other: &Size) -> 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 Sub<Size> for Coord

§

type Output = Coord

The resulting type after applying the - operator.
source§

fn sub(self, other: Size) -> Coord

Performs the - operation. Read more
source§

impl Sub for Size

Subtract a Size from a Size

This is saturating subtraction: Size::ZERO - Size::splat(6) == Size::ZERO.

§

type Output = Size

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Size) -> Size

Performs the - operation. Read more
source§

impl SubAssign<Size> for Coord

source§

fn sub_assign(&mut self, rhs: Size)

Performs the -= operation. Read more
source§

impl SubAssign for Size

Subtract a Size from a Size

This is saturating subtraction.

source§

fn sub_assign(&mut self, rhs: Size)

Performs the -= operation. Read more
source§

impl Copy for Size

source§

impl Eq for Size

source§

impl StructuralEq for Size

source§

impl StructuralPartialEq for Size

Auto Trait Implementations§

§

impl RefUnwindSafe for Size

§

impl Send for Size

§

impl Sync for Size

§

impl Unpin for Size

§

impl UnwindSafe for Size

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
§

impl<S, T> Cast<T> for S
where T: Conv<S>,

§

fn cast(self) -> T

Cast from Self to T Read more
§

fn try_cast(self) -> Result<T, Error>

Try converting from Self to T Read more
§

impl<S, T> CastApprox<T> for S
where T: ConvApprox<S>,

§

fn try_cast_approx(self) -> Result<T, Error>

Try approximate conversion from Self to T Read more
§

fn cast_approx(self) -> T

Cast approximately from Self to T Read more
§

impl<S, T> CastFloat<T> for S
where T: ConvFloat<S>,

§

fn cast_trunc(self) -> T

Cast to integer, truncating Read more
§

fn cast_nearest(self) -> T

Cast to the nearest integer Read more
§

fn cast_floor(self) -> T

Cast the floor to an integer Read more
§

fn cast_ceil(self) -> T

Cast the ceiling to an integer Read more
§

fn try_cast_trunc(self) -> Result<T, Error>

Try converting to integer with truncation Read more
§

fn try_cast_nearest(self) -> Result<T, Error>

Try converting to the nearest integer Read more
§

fn try_cast_floor(self) -> Result<T, Error>

Try converting the floor to an integer Read more
§

fn try_cast_ceil(self) -> Result<T, Error>

Try convert the ceiling to an integer Read more
§

impl<S, T> ConvApprox<S> for T
where T: Conv<S>,

§

fn try_conv_approx(x: S) -> Result<T, Error>

Try converting from T to Self, allowing approximation of value Read more
§

fn conv_approx(x: S) -> T

Converting from T to Self, allowing approximation of value Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

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<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

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

§

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