Rect

Rect

  • min : glam::Vec2
  • max : glam::Vec2

Description

A rectangle defined by two opposite corners.

The rectangle is axis aligned, and defined by its minimum and maximum coordinates, stored in Rect::min and Rect::max, respectively. The minimum/maximum invariant must be upheld by the user when directly assigning the fields, otherwise some methods produce invalid results. It is generally recommended to use one of the constructor methods instead, which will ensure this invariant is met, unless you already have the minimum and maximum corners.

Functions

FunctionSummary
as_irect(_self) Returns self as [`IRect`] (i32)
as_urect(_self) Returns self as [`URect`] (u32)
center(_self) The center point of the rectangle. # Examples ``` # use bevy_math::{Rect, Vec2}; let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 assert!(r.center().abs_diff_eq(Vec2::new(2.5, 0.5), 1e-5)); ```
clone(_self)No Documentation 🚧
contains(_self, point) Check if a point lies within this rectangle, inclusive of its edges. # Examples ``` # use bevy_math::Rect; let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 assert!(r.contains(r.center())); assert!(r.contains(r.min)); assert!(r.contains(r.max)); ```
eq(_self, other)No Documentation 🚧
from_center_half_size(origin, half_size) Create a new rectangle from its center and half-size. # Panics This method panics if any of the c
from_center_size(origin, size) Create a new rectangle from its center and size. # Panics This method panics if any of the compon
from_corners(p0, p1) Create a new rectangle from two corner points. The two points do not need to be the minimum and/or
half_size(_self) Rectangle half-size. # Examples ``` # use bevy_math::{Rect, Vec2}; let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 assert!(r.half_size().abs_diff_eq(Vec2::new(2.5, 0.5), 1e-5)); `
height(_self) Rectangle height (max.y - min.y). # Examples ``` # use bevy_math::Rect; let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 assert!((r.height() - 1.).abs() <= 1e-5); ```
inflate(_self, expansion) Create a new rectangle by expanding it evenly on all sides. A positive expansion value produces a
intersect(_self, other) Build a new rectangle formed of the intersection of this rectangle and another rectangle. The inte
is_empty(_self) Check if the rectangle is empty. # Examples ``` # use bevy_math::{Rect, Vec2}; let r = Rect::from_corners(Vec2::ZERO, Vec2::new(0., 1.)); // w=0 h=1 assert!(r.is_empty()); ```
new(x0, y0, x1, y1) Create a new rectangle from two corner points. The two points do not need to be the minimum and/or
normalize(_self, other) Build a new rectangle from this one with its coordinates expressed relative to `other` in a normal
size(_self) Rectangle size. # Examples ``` # use bevy_math::{Rect, Vec2}; let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 assert!(r.size().abs_diff_eq(Vec2::new(5., 1.), 1e-5)); ```
union(_self, other) Build a new rectangle formed of the union of this rectangle and another rectangle. The union is th
union_point(_self, other) Build a new rectangle formed of the union of this rectangle and a point. The union is the smallest
width(_self) Rectangle width (max.x - min.x). # Examples ``` # use bevy_math::Rect; let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 assert!((r.width() - 5.).abs() <= 1e-5); ```