[−]Struct druid::piet::kurbo::Rect
A rectangle.
Fields
x0: f64
The minimum x coordinate (left edge).
y0: f64
The minimum y coordinate (top edge in y-down spaces).
x1: f64
The maximum x coordinate (right edge).
y1: f64
The maximum y coordinate (bottom edge in y-down spaces).
Implementations
impl Rect
pub const ZERO: Rect
The empty rectangle at the origin.
pub const fn new(x0: f64, y0: f64, x1: f64, y1: f64) -> Rect
A new rectangle from minimum and maximum coordinates.
pub fn from_points(p0: impl Into<Point>, p1: impl Into<Point>) -> Rect
A new rectangle from two points.
The result will have non-negative width and height.
pub fn from_origin_size(origin: impl Into<Point>, size: impl Into<Size>) -> Rect
A new rectangle from origin and size.
The result will have non-negative width and height.
pub fn from_center_size(center: impl Into<Point>, size: impl Into<Size>) -> Rect
A new rectangle from center and size.
pub fn with_origin(self, origin: impl Into<Point>) -> Rect
Create a new Rect
with the same size as self
and a new origin.
pub fn with_size(self, size: impl Into<Size>) -> Rect
Create a new Rect
with the same origin as self
and a new size.
pub fn inset(self, insets: impl Into<Insets>) -> Rect
Create a new Rect
by applying the Insets
.
This will not preserve negative width and height.
Examples
use kurbo::Rect; let inset_rect = Rect::new(0., 0., 10., 10.,).inset(2.); assert_eq!(inset_rect.width(), 14.0); assert_eq!(inset_rect.x0, -2.0); assert_eq!(inset_rect.x1, 12.0);
pub fn width(&self) -> f64
The width of the rectangle.
Note: nothing forbids negative width.
pub fn height(&self) -> f64
The height of the rectangle.
Note: nothing forbids negative height.
pub fn min_x(&self) -> f64
Returns the minimum value for the x-coordinate of the rectangle.
pub fn max_x(&self) -> f64
Returns the maximum value for the x-coordinate of the rectangle.
pub fn min_y(&self) -> f64
Returns the minimum value for the y-coordinate of the rectangle.
pub fn max_y(&self) -> f64
Returns the maximum value for the y-coordinate of the rectangle.
pub fn origin(&self) -> Point
The origin of the rectangle.
This is the top left corner in a y-down space and with non-negative width and height.
pub fn size(&self) -> Size
The size of the rectangle.
pub fn area(&self) -> f64
The area of the rectangle.
pub fn is_empty(&self) -> bool
Whether this rectangle has zero area.
Note: a rectangle with negative area is not considered empty.
pub fn center(&self) -> Point
The center point of the rectangle.
pub fn contains(&self, point: Point) -> bool
Returns true
if point
lies within self
.
pub fn abs(&self) -> Rect
Take absolute value of width and height.
The resulting rect has the same extents as the original, but is guaranteed to have non-negative width and height.
pub fn union(&self, other: Rect) -> Rect
The smallest rectangle enclosing two rectangles.
Results are valid only if width and height are non-negative.
pub fn union_pt(&self, pt: Point) -> Rect
Compute the union with one point.
This method includes the perimeter of zero-area rectangles.
Thus, a succession of union_pt
operations on a series of
points yields their enclosing rectangle.
Results are valid only if width and height are non-negative.
pub fn intersect(&self, other: Rect) -> Rect
The intersection of two rectangles.
The result is zero-area if either input has negative width or height. The result always has non-negative width and height.
pub fn inflate(&self, width: f64, height: f64) -> Rect
Expand a rectangle by a constant amount in both directions.
The logic simply applies the amount in each direction. If rectangle area or added dimensions are negative, this could give odd results.
pub fn round(self) -> Rect
Returns a new Rect
,
with each coordinate value rounded to the nearest integer.
Examples
use kurbo::Rect; let rect = Rect::new(3.3, 3.6, 3.0, -3.1).round(); assert_eq!(rect.x0, 3.0); assert_eq!(rect.y0, 4.0); assert_eq!(rect.x1, 3.0); assert_eq!(rect.y1, -3.0);
pub fn ceil(self) -> Rect
Returns a new Rect
,
with each coordinate value rounded up to the nearest integer,
unless they are already an integer.
Examples
use kurbo::Rect; let rect = Rect::new(3.3, 3.6, 3.0, -3.1).ceil(); assert_eq!(rect.x0, 4.0); assert_eq!(rect.y0, 4.0); assert_eq!(rect.x1, 3.0); assert_eq!(rect.y1, -3.0);
pub fn floor(self) -> Rect
Returns a new Rect
,
with each coordinate value rounded down to the nearest integer,
unless they are already an integer.
Examples
use kurbo::Rect; let rect = Rect::new(3.3, 3.6, 3.0, -3.1).floor(); assert_eq!(rect.x0, 3.0); assert_eq!(rect.y0, 3.0); assert_eq!(rect.x1, 3.0); assert_eq!(rect.y1, -4.0);
pub fn expand(self) -> Rect
Returns a new Rect
,
with each coordinate value rounded away from the center of the Rect
to the nearest integer, unless they are already an integer.
That is to say this function will return the smallest possible Rect
with integer coordinates that is a superset of self
.
Examples
use kurbo::Rect; // In positive space let rect = Rect::new(3.3, 3.6, 5.6, 4.1).expand(); assert_eq!(rect.x0, 3.0); assert_eq!(rect.y0, 3.0); assert_eq!(rect.x1, 6.0); assert_eq!(rect.y1, 5.0); // In both positive and negative space let rect = Rect::new(-3.3, -3.6, 5.6, 4.1).expand(); assert_eq!(rect.x0, -4.0); assert_eq!(rect.y0, -4.0); assert_eq!(rect.x1, 6.0); assert_eq!(rect.y1, 5.0); // In negative space let rect = Rect::new(-5.6, -4.1, -3.3, -3.6).expand(); assert_eq!(rect.x0, -6.0); assert_eq!(rect.y0, -5.0); assert_eq!(rect.x1, -3.0); assert_eq!(rect.y1, -3.0); // Inverse orientation let rect = Rect::new(5.6, -3.6, 3.3, -4.1).expand(); assert_eq!(rect.x0, 6.0); assert_eq!(rect.y0, -3.0); assert_eq!(rect.x1, 3.0); assert_eq!(rect.y1, -5.0);
pub fn trunc(self) -> Rect
Returns a new Rect
,
with each coordinate value rounded towards the center of the Rect
to the nearest integer, unless they are already an integer.
That is to say this function will return the biggest possible Rect
with integer coordinates that is a subset of self
.
Examples
use kurbo::Rect; // In positive space let rect = Rect::new(3.3, 3.6, 5.6, 4.1).trunc(); assert_eq!(rect.x0, 4.0); assert_eq!(rect.y0, 4.0); assert_eq!(rect.x1, 5.0); assert_eq!(rect.y1, 4.0); // In both positive and negative space let rect = Rect::new(-3.3, -3.6, 5.6, 4.1).trunc(); assert_eq!(rect.x0, -3.0); assert_eq!(rect.y0, -3.0); assert_eq!(rect.x1, 5.0); assert_eq!(rect.y1, 4.0); // In negative space let rect = Rect::new(-5.6, -4.1, -3.3, -3.6).trunc(); assert_eq!(rect.x0, -5.0); assert_eq!(rect.y0, -4.0); assert_eq!(rect.x1, -4.0); assert_eq!(rect.y1, -4.0); // Inverse orientation let rect = Rect::new(5.6, -3.6, 3.3, -4.1).trunc(); assert_eq!(rect.x0, 5.0); assert_eq!(rect.y0, -4.0); assert_eq!(rect.x1, 4.0); assert_eq!(rect.y1, -4.0);
pub fn to_rounded_rect(self, radius: f64) -> RoundedRect
Creates a new RoundedRect
from this Rect
and the provided
corner radius.
pub fn to_ellipse(self) -> Ellipse
Returns the Ellipse
that is bounded by this Rect
.
pub fn aspect_ratio(&self) -> f64
The aspect ratio of the Rect
.
This is defined as the height divided by the width. It measures the
"squareness" of the rectangle (a value of 1
is square).
If the width is 0
the output will be sign(y1 - y0) * infinity
.
If The width and height are 0
, the result will be NaN
.
pub fn contained_rect_with_aspect_ratio(&self, aspect_ratio: f64) -> Rect
Returns the largest possible Rect
that is fully contained in self
with the given aspect_ratio
.
The aspect ratio is specified fractionally, as height / width
.
The resulting rectangle will be centered if it is smaller than the input rectangle.
For the special case where the aspect ratio is 1.0
, the resulting
Rect
will be square.
Examples
let outer = Rect::new(0.0, 0.0, 10.0, 20.0); let inner = outer.contained_rect_with_aspect_ratio(1.0); // The new `Rect` is a square centered at the center of `outer`. assert_eq!(inner, Rect::new(0.0, 5.0, 10.0, 15.0));
Trait Implementations
impl Add<Insets> for Rect
type Output = Rect
The resulting type after applying the +
operator.
pub fn add(self, other: Insets) -> Rect
impl Add<Rect> for Insets
type Output = Rect
The resulting type after applying the +
operator.
pub fn add(self, other: Rect) -> Rect
impl Add<Vec2> for Rect
type Output = Rect
The resulting type after applying the +
operator.
pub fn add(self, v: Vec2) -> Rect
impl Clone for Rect
pub fn clone(&self) -> Rect
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for Rect
impl Data for Rect
[src]
impl Debug for Rect
impl Default for Rect
impl Display for Rect
impl From<(Point, Point)> for Rect
impl From<(Point, Size)> for Rect
impl From<Rect> for Region
[src]
impl Into<Value> for Rect
[src]
impl Mul<Rect> for TranslateScale
type Output = Rect
The resulting type after applying the *
operator.
pub fn mul(self, other: Rect) -> Rect
impl PartialEq<Rect> for Rect
impl Scalable for Rect
[src]
pub fn to_px(&self, scale: Scale) -> Rect
[src]
Converts a Rect
from display points into pixels,
using the x axis scale factor for x0
and x1
and the y axis scale factor for y0
and y1
.
pub fn to_dp(&self, scale: Scale) -> Rect
[src]
Converts a Rect
from pixels into display points,
using the x axis scale factor for x0
and x1
and the y axis scale factor for y0
and y1
.
impl Shape for Rect
type PathElementsIter = RectPathIter
The iterator returned by the path_elements
method. Read more
pub fn path_elements(&self, _tolerance: f64) -> RectPathIter
pub fn area(&self) -> f64
pub fn perimeter(&self, _accuracy: f64) -> f64
pub fn winding(&self, pt: Point) -> i32
Note: this function is carefully designed so that if the plane is tiled with rectangles, the winding number will be nonzero for exactly one of them.
pub fn bounding_box(&self) -> Rect
pub fn as_rect(&self) -> Option<Rect>
pub fn to_path(&self, tolerance: f64) -> BezPath
pub fn into_path(self, tolerance: f64) -> BezPath
pub fn path_segments(&self, tolerance: f64) -> Segments<Self::PathElementsIter>ⓘ
pub fn contains(&self, pt: Point) -> bool
pub fn as_line(&self) -> Option<Line>
pub fn as_rounded_rect(&self) -> Option<RoundedRect>
pub fn as_circle(&self) -> Option<Circle>
pub fn as_path_slice(&self) -> Option<&[PathEl]>
impl StructuralPartialEq for Rect
impl Sub<Insets> for Rect
type Output = Rect
The resulting type after applying the -
operator.
pub fn sub(self, other: Insets) -> Rect
impl Sub<Rect> for Insets
type Output = Rect
The resulting type after applying the -
operator.
pub fn sub(self, other: Rect) -> Rect
impl Sub<Rect> for Rect
type Output = Insets
The resulting type after applying the -
operator.
pub fn sub(self, other: Rect) -> Insets
impl Sub<Vec2> for Rect
type Output = Rect
The resulting type after applying the -
operator.
pub fn sub(self, v: Vec2) -> Rect
impl ValueType for Rect
[src]
pub fn try_from_value(value: &Value) -> Result<Self, ValueTypeError>
[src]
Auto Trait Implementations
impl RefUnwindSafe for Rect
[src]
impl Send for Rect
[src]
impl Sync for Rect
[src]
impl Unpin for Rect
[src]
impl UnwindSafe for Rect
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> AnyEq for T where
T: PartialEq<T> + Any,
[src]
T: PartialEq<T> + Any,
pub fn equals(&self, other: &(dyn Any + 'static)) -> bool
[src]
pub fn as_any(&self) -> &(dyn Any + 'static)
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> RoundFrom<T> for T
pub fn round_from(x: T) -> T
impl<T, U> RoundInto<U> for T where
U: RoundFrom<T>,
U: RoundFrom<T>,
pub fn round_into(self) -> U
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,