pub struct Size {
pub width: f64,
pub height: f64,
}Expand description
A 2D size.
Fields§
§width: f64The width.
height: f64The height.
Implementations§
Source§impl Size
impl Size
Sourcepub const fn new(width: f64, height: f64) -> Size
pub const fn new(width: f64, height: f64) -> Size
Create a new Size with the provided width and height.
Sourcepub fn max_side(self) -> f64
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);Sourcepub fn min_side(self) -> f64
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);Sourcepub fn is_zero_area(self) -> bool
pub fn is_zero_area(self) -> bool
Whether this size has zero area.
Sourcepub fn min(self, other: Size) -> Size
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.));Sourcepub fn max(self, other: Size) -> Size
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.));Sourcepub fn clamp(self, min: Size, max: Size) -> Size
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.))Sourcepub const fn to_vec2(self) -> Vec2
pub const fn to_vec2(self) -> Vec2
Convert this size into a Vec2, with width mapped to x and height
mapped to y.
Sourcepub fn round(self) -> Size
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);Sourcepub fn ceil(self) -> Size
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);Sourcepub fn floor(self) -> Size
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);Sourcepub fn expand(self) -> Size
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);Sourcepub fn trunc(self) -> Size
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);Sourcepub fn aspect_ratio_width(self) -> f64
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.
Sourcepub 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.
pub fn aspect_ratio(self) -> f64
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.
Sourcepub fn to_rounded_rect(self, radii: impl Into<RoundedRectRadii>) -> RoundedRect
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.
Sourcepub fn get_coord_mut(&mut self, axis: Axis) -> &mut f64
pub fn get_coord_mut(&mut self, axis: Axis) -> &mut f64
Get a mutable reference to the member matching the given axis.
Trait Implementations§
Source§impl AddAssign for Size
impl AddAssign for Size
Source§fn add_assign(&mut self, other: Size)
fn add_assign(&mut self, other: Size)
+= operation. Read moreSource§impl DivAssign<f64> for Size
impl DivAssign<f64> for Size
Source§fn div_assign(&mut self, other: f64)
fn div_assign(&mut self, other: f64)
/= operation. Read moreSource§impl MulAssign<f64> for Size
impl MulAssign<f64> for Size
Source§fn mul_assign(&mut self, other: f64)
fn mul_assign(&mut self, other: f64)
*= operation. Read moreSource§impl SubAssign for Size
impl SubAssign for Size
Source§fn sub_assign(&mut self, other: Size)
fn sub_assign(&mut self, other: Size)
-= operation. Read moreimpl Copy for Size
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.