Struct Insets
pub struct Insets {
pub x0: f64,
pub y0: f64,
pub x1: f64,
pub y1: f64,
}Expand description
Insets from the edges of a rectangle.
The inset value for each edge can be thought of as a delta computed from
the center of the rect to that edge. For instance, with an inset of 2.0 on
the x-axis, a rectangle with the origin (0.0, 0.0) with that inset added
will have the new origin at (-2.0, 0.0).
Put alternatively, a positive inset represents increased distance from center, and a negative inset represents decreased distance from center.
§Examples
Positive insets added to a Rect produce a larger Rect:
let rect = Rect::from_origin_size((0., 0.,), (10., 10.,));
let insets = Insets::uniform_xy(3., 0.,);
let inset_rect = rect + insets;
assert_eq!(inset_rect.width(), 16.0, "10.0 + 3.0 × 2");
assert_eq!(inset_rect.x0, -3.0);Negative insets added to a Rect produce a smaller Rect:
let rect = Rect::from_origin_size((0., 0.,), (10., 10.,));
let insets = Insets::uniform_xy(-3., 0.,);
let inset_rect = rect + insets;
assert_eq!(inset_rect.width(), 4.0, "10.0 - 3.0 × 2");
assert_eq!(inset_rect.x0, 3.0);Insets operate on the absolute rectangle Rect::abs, and so ignore
existing negative widths and heights.
let rect = Rect::new(7., 11., 0., 0.,);
let insets = Insets::uniform_xy(0., 1.,);
assert_eq!(rect.width(), -7.0);
let inset_rect = rect + insets;
assert_eq!(inset_rect.width(), 7.0);
assert_eq!(inset_rect.x0, 0.0);
assert_eq!(inset_rect.height(), 13.0);The width and height of an inset operation can still be negative if the
Insets’ dimensions are greater than the dimensions of the original Rect.
let rect = Rect::new(0., 0., 3., 5.);
let insets = Insets::uniform_xy(0., 7.,);
let inset_rect = rect - insets;
assert_eq!(inset_rect.height(), -9., "5 - 7 × 2")Rect - Rect = Insets:
let rect = Rect::new(0., 0., 5., 11.);
let insets = Insets::uniform_xy(1., 7.,);
let inset_rect = rect + insets;
let insets2 = inset_rect - rect;
assert_eq!(insets2.x0, insets.x0);
assert_eq!(insets2.y1, insets.y1);
assert_eq!(insets2.x_value(), insets.x_value());
assert_eq!(insets2.y_value(), insets.y_value());Fields§
§x0: f64The minimum x coordinate (left edge).
y0: f64The minimum y coordinate (top edge in y-down spaces).
x1: f64The maximum x coordinate (right edge).
y1: f64The maximum y coordinate (bottom edge in y-down spaces).
Implementations§
§impl Insets
impl Insets
pub const fn uniform_xy(x: f64, y: f64) -> Insets
pub const fn uniform_xy(x: f64, y: f64) -> Insets
New insets with uniform values along each axis.
pub const fn new(x0: f64, y0: f64, x1: f64, y1: f64) -> Insets
pub const fn new(x0: f64, y0: f64, x1: f64, y1: f64) -> Insets
New insets. The ordering of the arguments is “left, top, right, bottom”, assuming a y-down coordinate space.
pub const fn x_value(self) -> f64
pub const fn x_value(self) -> f64
The total delta on the x-axis represented by these insets.
§Examples
use kurbo::Insets;
let insets = Insets::uniform_xy(3., 8.);
assert_eq!(insets.x_value(), 6.);
let insets = Insets::new(5., 0., -12., 0.,);
assert_eq!(insets.x_value(), -7.);pub const fn y_value(self) -> f64
pub const fn y_value(self) -> f64
The total delta on the y-axis represented by these insets.
§Examples
use kurbo::Insets;
let insets = Insets::uniform_xy(3., 7.);
assert_eq!(insets.y_value(), 14.);
let insets = Insets::new(5., 10., -12., 4.,);
assert_eq!(insets.y_value(), 14.);pub const fn size(self) -> Size
pub const fn size(self) -> Size
Returns the total delta represented by these insets as a Size.
This is equivalent to creating a Size from the values returned by
x_value and y_value.
This function may return a size with negative values.
§Examples
use kurbo::{Insets, Size};
let insets = Insets::new(11.1, -43.3, 3.333, -0.0);
assert_eq!(insets.size(), Size::new(insets.x_value(), insets.y_value()));pub const fn are_nonnegative(self) -> bool
pub const fn are_nonnegative(self) -> bool
Return true iff all values are nonnegative.
pub const fn nonnegative(self) -> Insets
pub const fn nonnegative(self) -> Insets
Return new Insets with all negative values replaced with 0.0.
This is provided as a convenience for applications where negative insets are not meaningful.
§Examples
use kurbo::Insets;
let insets = Insets::new(-10., 3., -0.2, 4.);
let nonnegative = insets.nonnegative();
assert_eq!(nonnegative.x_value(), 0.0);
assert_eq!(nonnegative.y_value(), 7.0);Trait Implementations§
impl Copy for Insets
impl StructuralPartialEq for Insets
Auto Trait Implementations§
impl Freeze for Insets
impl RefUnwindSafe for Insets
impl Send for Insets
impl Sync for Insets
impl Unpin for Insets
impl UnsafeUnpin for Insets
impl UnwindSafe for Insets
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more