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

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

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

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

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

Source§

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

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 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 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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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> ToSmolStr for T
where T: Display + ?Sized,

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> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T, Right> ClosedAdd<Right> for T
where T: Add<Right, Output = T> + AddAssign<Right>,

Source§

impl<T, Right> ClosedAddAssign<Right> for T
where T: ClosedAdd<Right> + AddAssign<Right>,

Source§

impl<T, Right> ClosedDiv<Right> for T
where T: Div<Right, Output = T> + DivAssign<Right>,

Source§

impl<T, Right> ClosedDivAssign<Right> for T
where T: ClosedDiv<Right> + DivAssign<Right>,

Source§

impl<T, Right> ClosedMul<Right> for T
where T: Mul<Right, Output = T> + MulAssign<Right>,

Source§

impl<T, Right> ClosedMulAssign<Right> for T
where T: ClosedMul<Right> + MulAssign<Right>,

Source§

impl<T, Right> ClosedSub<Right> for T
where T: Sub<Right, Output = T> + SubAssign<Right>,

Source§

impl<T, Right> ClosedSubAssign<Right> for T
where T: ClosedSub<Right> + SubAssign<Right>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,