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) -> Self
pub const fn new(width: f64, height: f64) -> Self
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 is_empty(self) -> bool
👎Deprecated since 0.11.1: use is_zero_area instead
pub fn is_empty(self) -> bool
Whether this size has zero area.
Note: a size with negative area is not considered empty.
Sourcepub fn min(self, other: Size) -> Self
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.));Sourcepub fn max(self, other: Size) -> Self
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.));Sourcepub fn clamp(self, min: Size, max: Size) -> Self
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.))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(self) -> f64
pub fn aspect_ratio(self) -> f64
Returns the aspect ratio of a rectangle with the given size.
If the width is 0, the output will be sign(self.height) * infinity. If The width and
height are 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.
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 more