Struct shape_core::Rectangle
source · #[repr(C)]pub struct Rectangle<T> {
pub min: Point<T>,
pub max: Point<T>,
}
Expand description
Fields§
§min: Point<T>
origin x points of the rectangle
max: Point<T>
origin y points of the rectangle
Implementations§
source§impl<T> Rectangle<T>
impl<T> Rectangle<T>
Constructors for rectangle_2d
sourcepub fn from_origin<P>(origin: P, width: T, height: T) -> Selfwhere
T: Clone + Add<Output = T>,
P: Into<Point<T>>,
pub fn from_origin<P>(origin: P, width: T, height: T) -> Selfwhere T: Clone + Add<Output = T>, P: Into<Point<T>>,
sourcepub fn from_center<P>(center: P, width: T, height: T) -> Selfwhere
T: Clone + One + Add<Output = T> + Sub<Output = T> + Div<Output = T>,
P: Into<Point<T>>,
pub fn from_center<P>(center: P, width: T, height: T) -> Selfwhere T: Clone + One + Add<Output = T> + Sub<Output = T> + Div<Output = T>, P: Into<Point<T>>,
source§impl<T> Rectangle<T>
impl<T> Rectangle<T>
sourcepub fn width(&self) -> Twhere
T: Clone + Sub<Output = T>,
pub fn width(&self) -> Twhere T: Clone + Sub<Output = T>,
Get the width of the rectangle
Examples
let rect = Rectangle::new(0.0, 0.0, 1.0, 1.0);
assert_eq!(rect.width(), 1.0);
sourcepub fn height(&self) -> Twhere
T: Clone + Sub<Output = T>,
pub fn height(&self) -> Twhere T: Clone + Sub<Output = T>,
Get the height of the rectangle
Examples
let rect = Rectangle::new(0.0, 0.0, 1.0, 1.0);
assert_eq!(rect.height(), 1.0);
sourcepub fn origin(&self) -> Point<T>where
T: Clone,
pub fn origin(&self) -> Point<T>where T: Clone,
Get the origin of the rectangle
Examples
let rect = Rectangle::from_center((0.0, 0.0), 1.0, 1.0);
assert_eq!(rect.origin(), Point::new(-0.5, -0.5));
sourcepub fn center(&self) -> Point<T>where
T: Clone + One + Add<Output = T> + Sub<Output = T> + Div<Output = T>,
pub fn center(&self) -> Point<T>where T: Clone + One + Add<Output = T> + Sub<Output = T> + Div<Output = T>,
Get the center point of the rectangle
Examples
let rect = Rectangle::new(0.0, 0.0, 1.0, 1.0);
assert_eq!(rect.center(), Point::new(0.5, 0.5));
pub fn contains(&self, point: &Point<T>) -> boolwhere T: Clone + PartialOrd,
pub fn overlaps(&self, other: &Rectangle<T>) -> boolwhere T: Clone + PartialOrd,
pub fn area(&self) -> Twhere T: Clone + Mul<Output = T> + Sub<Output = T>,
Trait Implementations§
source§impl<'de, T> Deserialize<'de> for Rectangle<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Rectangle<T>where T: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<T: PartialEq> PartialEq<Rectangle<T>> for Rectangle<T>
impl<T: PartialEq> PartialEq<Rectangle<T>> for Rectangle<T>
source§impl<T> Shape2D for Rectangle<T>where
T: Signed + Clone + PartialOrd,
impl<T> Shape2D for Rectangle<T>where T: Signed + Clone + PartialOrd,
source§fn is_valid(&self) -> bool
fn is_valid(&self) -> bool
A valid rectangle means it has a positive area.
Examples
let rect = Rectangle::new(0.0, 0.0, 1.0, 1.0);
assert!(rect.is_valid());
source§fn vertices(&self, _: usize) -> impl Iterator<Item = Point<Self::Value>> + '_
fn vertices(&self, _: usize) -> impl Iterator<Item = Point<Self::Value>> + '_
Returns four vertices counterclockwise in the ↑Y coordinate system