Rect

Struct Rect 

Source
pub struct Rect<T: Copy> { /* private fields */ }
Expand description

矩形结构体

§Note

若启用perffeature,所有方法都将不会进行标准化检查,以提高性能, 该情况下,如有必要,需手动进行标准化检查,以保证方法计算结果的正确性

Implementations§

Source§

impl<T: Copy + Ord> Rect<T>

Source

pub fn new(left: T, top: T, right: T, bottom: T) -> Self

创建一个新的矩形

§Example
use ponsic_types::Rect;
let rect = Rect::new(1, 2, 3, 4);
Source§

impl<T: Copy> Rect<T>

Source

pub fn left(&self) -> T

返回矩形的左边界坐标

§Note

若矩形不是标准化的,该函数可能不会返回实际的左边界坐标, 若要标准化矩形,请使用 [normalize()]

Source

pub fn top(&self) -> T

返回矩形的上边界坐标

§Note

若矩形不是标准化的,该函数可能不会返回实际的上边界坐标, 若要标准化矩形,请使用 [normalize()]

Source

pub fn right(&self) -> T

返回矩形的右边界坐标

§Note

若矩形不是标准化的,该函数可能不会返回实际的右边界坐标, 若要标准化矩形,请使用 [normalize()]

Source

pub fn bottom(&self) -> T

返回矩形的下边界坐标

§Note

若矩形不是标准化的,该函数可能不会返回实际的下边界坐标, 若要标准化矩形,请使用 [normalize()]

Source

pub fn left_top(&self) -> Point<T>

返回矩形的左上角坐标

§Note

若矩形不是标准化的,该函数可能不会返回实际的左上角坐标, 若要标准化矩形,请使用 [normalize()]

Source

pub fn right_top(&self) -> Point<T>

返回矩形的右上角坐标

§Note

若矩形不是标准化的,该函数可能不会返回实际的右上角坐标, 若要标准化矩形,请使用 [normalize()]

Source

pub fn left_bottom(&self) -> Point<T>

返回矩形的左下角坐标

§Note

若矩形不是标准化的,该函数可能不会返回实际的左下角坐标, 若要标准化矩形,请使用 [normalize()]

Source

pub fn right_bottom(&self) -> Point<T>

返回矩形的右下角坐标

§Note

若矩形不是标准化的,该函数可能不会返回实际的右下角坐标, 若要标准化矩形,请使用 [normalize()]

Source§

impl<T: Copy + Ord> Rect<T>

若启用perffeature,以下方法将不会进行标准化检查,以提高性能

Source

pub fn set_left(&mut self, left: T)

设置矩形的左边界坐标

Source

pub fn set_top(&mut self, top: T)

设置矩形的上边界坐标

Source

pub fn set_right(&mut self, right: T)

设置矩形的右边界坐标

Source

pub fn set_bottom(&mut self, bottom: T)

设置矩形的下边界坐标

Source

pub fn set_left_top(&mut self, left: T, top: T)

设置矩形的左上角坐标

Source

pub fn set_right_top(&mut self, right: T, top: T)

设置矩形的右上角坐标

Source

pub fn set_left_bottom(&mut self, left: T, bottom: T)

设置矩形的左下角坐标

Source

pub fn set_right_bottom(&mut self, right: T, bottom: T)

设置矩形的右下角坐标

Source§

impl<T: Copy + Sub<Output = T>> Rect<T>

Source

pub fn width(&self) -> T

返回矩形的宽度

§Note

若矩形不是标准化的,该函数可能会返回负值, 若要标准化矩形,请使用 [normalize()]

Source

pub fn height(&self) -> T

返回矩形的高度

§Note

若矩形不是标准化的,该函数可能会返回负值, 若要标准化矩形,请使用 [normalize()]

Source

pub fn size(&self) -> Size<T>

返回矩形的尺寸

§Note

若矩形不是标准化的,该函数返回值可能包含负值, 若要标准化矩形,请使用 [normalize()]

Source§

impl<T: Copy + Ord> Rect<T>

Source

pub fn contains(&self, point: Point<T>) -> bool

判断点是否在矩形区域内

§Note

如果点在矩形的边界上,此函数也会返回 false; 如果需要包含点在矩形边界上的情况,请使用 [contains_with_bound()]

Source

pub fn contains_with_bound(&self, point: Point<T>) -> bool

判断点是否在矩形区域内

§Note

如果点在矩形的边界上,此函数也会返回 true; 如果需要排除点在矩形边界上的情况,请使用 [contains_with_bound()]

Source

pub fn intersects(&self, other: &Rect<T>) -> bool

判断此矩形与另一个矩形是否存在交集

如果另一个矩形与此矩形存在公共区域,则返回 true

Source

pub fn intersected(&self, other: &Self) -> Option<Self>

计算两个矩形的交集

此函数会计算两个矩形的重叠部分,并返回一个包含该信息的新矩形

§Note

若两个矩形没有交集,则返回 None

Source

pub fn united(&self, other: &Rect<T>) -> Rect<T>

计算两个矩形的并集

此函数会计算两个矩形所在位置的最小轮廓矩形,并返回一个包含该信息的新矩形

Source§

impl<T: Copy + AddAssign + Ord> Rect<T>

Source

pub fn adjust(&mut self, left: T, top: T, right: T, bottom: T)

调整矩形的位置

Source§

impl<T: Copy + Add<Output = T> + Div<i32, Output = T>> Rect<T>

Source

pub fn center(&self) -> Point<T>

返回矩形的中心点坐标

Trait Implementations§

Source§

impl<T: Copy + Ord> BitAnd for Rect<T>

Source§

type Output = Option<Rect<T>>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<T: Copy + Ord> BitOr for Rect<T>

Source§

type Output = Rect<T>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<T: Clone + Copy> Clone for Rect<T>

Source§

fn clone(&self) -> Rect<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Copy> Debug for Rect<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default + Copy> Default for Rect<T>

Source§

fn default() -> Rect<T>

Returns the “default value” for a type. Read more
Source§

impl<T: Copy + Add<Output = T>> From<(Point<T>, Size<T>)> for Rect<T>

Source§

fn from((pos, size): (Point<T>, Size<T>)) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash + Copy> Hash for Rect<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq + Copy> PartialEq for Rect<T>

Source§

fn eq(&self, other: &Rect<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Copy + Copy> Copy for Rect<T>

Source§

impl<T: Eq + Copy> Eq for Rect<T>

Source§

impl<T: Copy> StructuralPartialEq for Rect<T>

Auto Trait Implementations§

§

impl<T> Freeze for Rect<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Rect<T>
where T: RefUnwindSafe,

§

impl<T> Send for Rect<T>
where T: Send,

§

impl<T> Sync for Rect<T>
where T: Sync,

§

impl<T> Unpin for Rect<T>
where T: Unpin,

§

impl<T> UnwindSafe for Rect<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.