pub struct Rect {
pub min: Vec2,
pub max: Vec2,
}Expand description
2D 矩形,用于边界检测和 UI 布局
矩形使用最小点和最大点表示,确保 min.x <= max.x 和 min.y <= max.y。
Fields§
§min: Vec2最小点(左下角)
max: Vec2最大点(右上角)
Implementations§
Source§impl Rect
impl Rect
Sourcepub fn from_center_size(center: Vec2, size: Vec2) -> Rect
pub fn from_center_size(center: Vec2, size: Vec2) -> Rect
从中心点和大小创建矩形
§示例
use anvilkit_core::math::geometry::Rect;
use glam::Vec2;
let rect = Rect::from_center_size(Vec2::new(5.0, 5.0), Vec2::new(10.0, 20.0));
assert_eq!(rect.center(), Vec2::new(5.0, 5.0));Sourcepub fn from_position_size(position: Vec2, size: Vec2) -> Rect
pub fn from_position_size(position: Vec2, size: Vec2) -> Rect
从位置和大小创建矩形(位置为左下角)
Sourcepub fn contains(&self, point: Vec2) -> bool
pub fn contains(&self, point: Vec2) -> bool
检查点是否在矩形内
§示例
use anvilkit_core::math::geometry::Rect;
use glam::Vec2;
let rect = Rect::new(Vec2::ZERO, Vec2::new(10.0, 10.0));
assert!(rect.contains(Vec2::new(5.0, 5.0)));
assert!(!rect.contains(Vec2::new(15.0, 5.0)));Sourcepub fn intersects(&self, other: &Rect) -> bool
pub fn intersects(&self, other: &Rect) -> bool
检查是否与另一个矩形相交
§示例
use anvilkit_core::math::geometry::Rect;
use glam::Vec2;
let rect1 = Rect::new(Vec2::ZERO, Vec2::new(10.0, 10.0));
let rect2 = Rect::new(Vec2::new(5.0, 5.0), Vec2::new(15.0, 15.0));
assert!(rect1.intersects(&rect2));Sourcepub fn intersects_circle(&self, circle: &Circle) -> bool
pub fn intersects_circle(&self, circle: &Circle) -> bool
检查是否与圆形相交
Sourcepub fn intersection(&self, other: &Rect) -> Option<Rect>
pub fn intersection(&self, other: &Rect) -> Option<Rect>
Sourcepub fn expand_to_include(&mut self, point: Vec2)
pub fn expand_to_include(&mut self, point: Vec2)
扩展矩形以包含指定点
Trait Implementations§
impl Copy for Rect
impl StructuralPartialEq for Rect
Auto Trait Implementations§
impl Freeze for Rect
impl RefUnwindSafe for Rect
impl Send for Rect
impl Sync for Rect
impl Unpin for Rect
impl UnsafeUnpin for Rect
impl UnwindSafe for Rect
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.