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
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 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 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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)