Size

Struct Size 

Source
pub struct Size {
    pub width: f64,
    pub height: f64,
}
Expand description

A 2D size.

Fields§

§width: f64

The width.

§height: f64

The height.

Implementations§

Source§

impl Size

Source

pub const ZERO: Size

A size with zero width or height.

Source

pub const INFINITY: Size

A size with width and height set to f64::INFINITY.

Source

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

Create a new Size with the provided width and height.

Source

pub fn max_side(self) -> f64

Returns the max of width and height.

§Examples
use kurbo::Size;
let size = Size::new(-10.5, 42.0);
assert_eq!(size.max_side(), 42.0);
Source

pub fn min_side(self) -> f64

Returns the min of width and height.

§Examples
use kurbo::Size;
let size = Size::new(-10.5, 42.0);
assert_eq!(size.min_side(), -10.5);
Source

pub fn area(self) -> f64

The area covered by this size.

Source

pub fn is_zero_area(self) -> bool

Whether this size has zero area.

Source

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

Returns the component-wise minimum of self and other.

§Examples
use kurbo::Size;

let this = Size::new(0., 100.);
let other = Size::new(10., 10.);

assert_eq!(this.min(other), Size::new(0., 10.));
Source

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

Returns the component-wise maximum of self and other.

§Examples
use kurbo::Size;

let this = Size::new(0., 100.);
let other = Size::new(10., 10.);

assert_eq!(this.max(other), Size::new(10., 100.));
Source

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

Returns a new size bounded by min and max.

§Examples
use kurbo::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

pub const fn to_vec2(self) -> Vec2

Convert this size into a Vec2, with width mapped to x and height mapped to y.

Source

pub fn round(self) -> Size

Returns a new Size, with width and height rounded to the nearest integer.

§Examples
use kurbo::Size;
let size_pos = Size::new(3.3, 3.6).round();
assert_eq!(size_pos.width, 3.0);
assert_eq!(size_pos.height, 4.0);
let size_neg = Size::new(-3.3, -3.6).round();
assert_eq!(size_neg.width, -3.0);
assert_eq!(size_neg.height, -4.0);
Source

pub fn ceil(self) -> Size

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

§Examples
use kurbo::Size;
let size_pos = Size::new(3.3, 3.6).ceil();
assert_eq!(size_pos.width, 4.0);
assert_eq!(size_pos.height, 4.0);
let size_neg = Size::new(-3.3, -3.6).ceil();
assert_eq!(size_neg.width, -3.0);
assert_eq!(size_neg.height, -3.0);
Source

pub fn floor(self) -> Size

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

§Examples
use kurbo::Size;
let size_pos = Size::new(3.3, 3.6).floor();
assert_eq!(size_pos.width, 3.0);
assert_eq!(size_pos.height, 3.0);
let size_neg = Size::new(-3.3, -3.6).floor();
assert_eq!(size_neg.width, -4.0);
assert_eq!(size_neg.height, -4.0);
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 kurbo::Size;
let size_pos = Size::new(3.3, 3.6).expand();
assert_eq!(size_pos.width, 4.0);
assert_eq!(size_pos.height, 4.0);
let size_neg = Size::new(-3.3, -3.6).expand();
assert_eq!(size_neg.width, -4.0);
assert_eq!(size_neg.height, -4.0);
Source

pub fn trunc(self) -> Size

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

§Examples
use kurbo::Size;
let size_pos = Size::new(3.3, 3.6).trunc();
assert_eq!(size_pos.width, 3.0);
assert_eq!(size_pos.height, 3.0);
let size_neg = Size::new(-3.3, -3.6).trunc();
assert_eq!(size_neg.width, -3.0);
assert_eq!(size_neg.height, -3.0);
Source

pub fn aspect_ratio_width(self) -> f64

Returns the aspect ratio of a rectangle with this size.

The aspect ratio is the ratio of the width to the height.

If the height is 0, the output will be sign(self.width) * infinity. If the width and height are both 0, then the output will be NaN.

Source

pub fn aspect_ratio(self) -> f64

👎Deprecated since 0.12.0: You should use aspect_ratio_width instead, as this method returns a potentially unexpected value.

Returns the inverse of the aspect ratio of a rectangle with this size.

Aspect ratios are usually defined as the ratio of the width to the height, but this method incorrectly returns the ratio of height to width. You should generally prefer aspect_ratio_width.

If the width is 0, the output will be sign(self.height) * infinity. If the width and height are both 0, then the output will be NaN.

Source

pub const fn to_rect(self) -> Rect

Convert this Size into a Rect with origin (0.0, 0.0).

Source

pub fn to_rounded_rect(self, radii: impl Into<RoundedRectRadii>) -> RoundedRect

Convert this Size into a RoundedRect with origin (0.0, 0.0) and the provided corner radius.

Source

pub fn is_finite(self) -> bool

Is this size finite?

Source

pub fn is_nan(self) -> bool

Is this size NaN?

Source

pub fn get_coord(self, axis: Axis) -> f64

Get the member matching the given axis.

Source

pub fn get_coord_mut(&mut self, axis: Axis) -> &mut f64

Get a mutable reference to the member matching the given axis.

Source

pub fn set_coord(&mut self, axis: Axis, value: f64)

Set the member matching the given axis to the given value.

Trait Implementations§

Source§

impl Add for Size

Source§

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 for Size

Source§

fn add_assign(&mut self, other: Size)

Performs the += operation. Read more
Source§

impl Clone for Size

Source§

fn clone(&self) -> Size

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 Size

Source§

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

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<'de> Deserialize<'de> for Size

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 Display for Size

Source§

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

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

impl Div<f64> for Size

Source§

type Output = Size

The resulting type after applying the / operator.
Source§

fn div(self, other: f64) -> Size

Performs the / operation. Read more
Source§

impl DivAssign<f64> for Size

Source§

fn div_assign(&mut self, other: f64)

Performs the /= operation. Read more
Source§

impl From<(f64, f64)> for Size

Source§

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

Converts to this type from the input type.
Source§

impl From<Size> for (f64, f64)

Source§

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

Converts to this type from the input type.
Source§

impl From<Size> for Size2D<f64, UnknownUnit>

Source§

fn from(value: Size) -> Self

Converts to this type from the input type.
Source§

impl From<Size2D<f64, UnknownUnit>> for Size

Source§

fn from(value: Size2D<f64, UnknownUnit>) -> Self

Converts to this type from the input type.
Source§

impl Mul<Size> for f64

Source§

type Output = Size

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<f64> for Size

Source§

type Output = Size

The resulting type after applying the * operator.
Source§

fn mul(self, other: f64) -> Size

Performs the * operation. Read more
Source§

impl MulAssign<f64> for Size

Source§

fn mul_assign(&mut self, other: f64)

Performs the *= operation. Read more
Source§

impl PartialEq for Size

Source§

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

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 for Size

Source§

type Output = Size

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for Size

Source§

fn sub_assign(&mut self, other: Size)

Performs the -= operation. Read more
Source§

impl Copy for Size

Source§

impl StructuralPartialEq for Size

Auto Trait Implementations§

§

impl Freeze for Size

§

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
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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>,