pub struct Rectangle<T = f32> {
pub x: T,
pub y: T,
pub width: T,
pub height: T,
}Expand description
An axis-aligned rectangle.
Fields§
§x: TX coordinate of the top-left corner.
y: TY coordinate of the top-left corner.
width: TWidth of the rectangle.
height: THeight of the rectangle.
Implementations§
Source§impl Rectangle<f32>
impl Rectangle<f32>
Sourcepub const INFINITE: Self
pub const INFINITE: Self
A rectangle starting at negative infinity and with infinite width and height.
Sourcepub fn with_radius(radius: f32) -> Self
pub fn with_radius(radius: f32) -> Self
Creates a new square Rectangle with the center at the origin and
with the given radius.
Sourcepub fn with_vertices(
top_left: Point,
top_right: Point,
bottom_left: Point,
) -> (Rectangle, Radians)
pub fn with_vertices( top_left: Point, top_right: Point, bottom_left: Point, ) -> (Rectangle, Radians)
Sourcepub fn offset(&self, container: &Rectangle) -> Vector
pub fn offset(&self, container: &Rectangle) -> Vector
Computes the offset that must be applied to the Rectangle to be placed
inside the given container.
Sourcepub fn is_within(&self, container: &Rectangle) -> bool
pub fn is_within(&self, container: &Rectangle) -> bool
Returns true if the current Rectangle is within the given
container. Includes the right and bottom edges.
Sourcepub fn intersection(&self, other: &Rectangle<f32>) -> Option<Rectangle<f32>>
pub fn intersection(&self, other: &Rectangle<f32>) -> Option<Rectangle<f32>>
Computes the intersection with the given Rectangle.
Sourcepub fn intersects(&self, other: &Self) -> bool
pub fn intersects(&self, other: &Self) -> bool
Returns whether the Rectangle intersects with the given one.
Sourcepub fn snap(self) -> Option<Rectangle<u32>>
pub fn snap(self) -> Option<Rectangle<u32>>
Snaps the Rectangle to unsigned integer coordinates.
Sourcepub fn zoom(self, zoom: f32) -> Self
pub fn zoom(self, zoom: f32) -> Self
Scales the Rectangle without changing its position, effectively
“zooming” it.
Sourcepub fn anchor(
&self,
size: Size,
align_x: impl Into<Horizontal>,
align_y: impl Into<Vertical>,
) -> Point
pub fn anchor( &self, size: Size, align_x: impl Into<Horizontal>, align_y: impl Into<Vertical>, ) -> Point
Sourcepub fn chord(&self, angle: impl Into<Radians>) -> (Point, Point)
pub fn chord(&self, angle: impl Into<Radians>) -> (Point, Point)
Returns the two endpoints of a chord through the rectangle’s center
at the given angle.
The angle is measured clockwise from the negative y-axis, so 0
produces a vertical chord and π/2 a horizontal one. The returned
points are (start, end), symmetric about Rectangle::center.
Trait Implementations§
Source§impl<T> AddAssign<Vector<T>> for Rectangle<T>where
T: AddAssign,
impl<T> AddAssign<Vector<T>> for Rectangle<T>where
T: AddAssign,
Source§fn add_assign(&mut self, translation: Vector<T>)
fn add_assign(&mut self, translation: Vector<T>)
+= operation. Read moreSource§impl Mul<Transformation> for Rectangle
impl Mul<Transformation> for Rectangle
Source§impl<T> SubAssign<Vector<T>> for Rectangle<T>where
T: SubAssign,
impl<T> SubAssign<Vector<T>> for Rectangle<T>where
T: SubAssign,
Source§fn sub_assign(&mut self, translation: Vector<T>)
fn sub_assign(&mut self, translation: Vector<T>)
-= operation. Read more