Struct kurbo::Size [−][src]
Expand description
A 2D size.
Fields
width: f64
The width.
height: f64
The height.
Implementations
Create a new Size
with the provided width
and height
.
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);
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);
Whether this size has zero area.
Note: a size with negative area is not considered empty.
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.))
Convert this size into a Vec2
, with width
mapped to x
and height
mapped to y
.
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);
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);
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);
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);
Returns a new Size
,
with width
and height
rounded down towards zero 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);
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
.
Convert this Size
into a RoundedRect
with origin (0.0, 0.0)
and
the provided corner radius.
Trait Implementations
Performs the +=
operation. Read more
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>,
Deserialize this value from the given Serde deserializer. Read more
Performs the /=
operation. Read more
Performs the *=
operation. Read more
Performs the -=
operation. Read more
Auto Trait Implementations
impl RefUnwindSafe for Size
impl UnwindSafe for Size
Blanket Implementations
Mutably borrows from an owned value. Read more