pub struct Rect {
pub left: f64,
pub top: f64,
pub right: f64,
pub bottom: f64,
}Expand description
Fields§
§left: f64The offset of the left edge of this rectangle from the x axis.
top: f64The offset of the top edge of this rectangle from the y axis.
right: f64The offset of the right edge of this rectangle from the x axis.
bottom: f64The offset of the bottom edge of this rectangle from the y axis.
Implementations§
Source§impl Rect
impl Rect
Sourcepub const LARGEST: Rect
pub const LARGEST: Rect
A rectangle that covers the entire coordinate space.
This covers the space from -1e9,-1e9 to 1e9,1e9. This is the space over which graphics operations are valid.
Sourcepub const fn from_ltrb(left: f64, top: f64, right: f64, bottom: f64) -> Rect
pub const fn from_ltrb(left: f64, top: f64, right: f64, bottom: f64) -> Rect
Construct a rectangle from its left, top, right, and bottom edges.
Sourcepub fn from_circle(center: Offset, radius: f64) -> Rect
pub fn from_circle(center: Offset, radius: f64) -> Rect
Construct a rectangle that bounds the given circle.
The center argument is assumed to be an offset from the origin.
Sourcepub fn from_center(center: Offset, width: f64, height: f64) -> Rect
pub fn from_center(center: Offset, width: f64, height: f64) -> Rect
Constructs a rectangle from its center point, width, and height.
The center argument is assumed to be an offset from the origin.
Sourcepub fn from_points(a: Offset, b: Offset) -> Rect
pub fn from_points(a: Offset, b: Offset) -> Rect
Construct the smallest rectangle that encloses the given offsets, treating them as vectors from the origin.
Sourcepub fn size(&self) -> Size
pub fn size(&self) -> Size
The distance between the upper-left corner and the lower-right corner of this rectangle.
Sourcepub fn is_infinite(&self) -> bool
pub fn is_infinite(&self) -> bool
Whether any of the coordinates of this rectangle are equal to positive infinity.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether this rectangle encloses a non-zero area. Negative areas are considered empty.
Sourcepub fn inflate(&self, delta: f64) -> Rect
pub fn inflate(&self, delta: f64) -> Rect
Returns a new rectangle with edges moved outwards by the given delta.
Sourcepub fn deflate(&self, delta: f64) -> Rect
pub fn deflate(&self, delta: f64) -> Rect
Returns a new rectangle with edges moved inwards by the given delta.
Sourcepub fn intersect(&self, other: Rect) -> Rect
pub fn intersect(&self, other: Rect) -> Rect
Returns a new rectangle that is the intersection of the given rectangle and this rectangle. The two rectangles must overlap for this to be meaningful. If the two rectangles do not overlap, then the resulting Rect will have a negative width or height.
Sourcepub fn expand_to_include(&self, other: Rect) -> Rect
pub fn expand_to_include(&self, other: Rect) -> Rect
Returns a new rectangle which is the bounding box containing this rectangle and the given rectangle.
Sourcepub fn overlaps(&self, other: Rect) -> bool
pub fn overlaps(&self, other: Rect) -> bool
Whether other has a nonzero area of overlap with this rectangle.
Sourcepub fn shortest_side(&self) -> f64
pub fn shortest_side(&self) -> f64
Sourcepub fn longest_side(&self) -> f64
pub fn longest_side(&self) -> f64
Sourcepub fn top_left(&self) -> Offset
pub fn top_left(&self) -> Offset
The offset to the intersection of the top and left edges of this rectangle.
See also Size::top_left.
Sourcepub fn top_center(&self) -> Offset
pub fn top_center(&self) -> Offset
The offset to the center of the top edge of this rectangle.
See also Size::top_center.
Sourcepub fn top_right(&self) -> Offset
pub fn top_right(&self) -> Offset
The offset to the intersection of the top and right edges of this rectangle.
See also Size::top_right.
Sourcepub fn center_left(&self) -> Offset
pub fn center_left(&self) -> Offset
The offset to the center of the left edge of this rectangle.
See also Size::center_left.
Sourcepub fn center(&self) -> Offset
pub fn center(&self) -> Offset
The offset to the point halfway between the left and right and the top and bottom edges of this rectangle.
See also Size::center.
Sourcepub fn center_right(&self) -> Offset
pub fn center_right(&self) -> Offset
The offset to the center of the right edge of this rectangle.
See also Size::center_right.
Sourcepub fn bottom_left(&self) -> Offset
pub fn bottom_left(&self) -> Offset
The offset to the intersection of the bottom and left edges of this rectangle.
See also Size::bottom_left.
Sourcepub fn bottom_center(&self) -> Offset
pub fn bottom_center(&self) -> Offset
The offset to the center of the bottom edge of this rectangle.
See also Size::bottom_center.
Sourcepub fn bottom_right(&self) -> Offset
pub fn bottom_right(&self) -> Offset
The offset to the intersection of the bottom and right edges of this rectangle.
See also Size::bottom_right.
Sourcepub fn contains(&self, offset: Offset) -> bool
pub fn contains(&self, offset: Offset) -> bool
Whether the point specified by the given offset (which is assumed to be relative to the origin) lies between the left and right and the top and bottom edges of this rectangle.
Rectangles include their top and left edges but exclude their bottom and right edges.
Sourcepub fn lerp(a: Option<Rect>, b: Option<Rect>, t: f64) -> Option<Rect>
pub fn lerp(a: Option<Rect>, b: Option<Rect>, t: f64) -> Option<Rect>
Linearly interpolate between two rectangles.
If either rect is null, Rect::ZERO is used as a substitute.
The t argument represents position on the timeline, with 0.0 meaning
that the interpolation has not started, returning a (or something
equivalent to a), 1.0 meaning that the interpolation has finished,
returning b (or something equivalent to b), and values in between
meaning that the interpolation is at the relevant point on the timeline
between a and b. The interpolation can be extrapolated beyond 0.0 and
1.0, so negative values and values greater than 1.0 are valid (and can
easily be generated by curves such as Curves.elasticInOut).
Values for t are usually obtained from an Animation<double>, such as
an AnimationController.