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 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_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<'de> Deserialize<'de> for Size
impl<'de> Deserialize<'de> for Size
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§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