Struct figures::Rect

source ·
pub struct Rect<Unit> {
    pub origin: Point<Unit>,
    pub size: Size<Unit>,
}
Expand description

A 2d area expressed as an origin (Point) and a Size.

Fields§

§origin: Point<Unit>

The origin of the rectangle

§size: Size<Unit>

The size of the rectangle.

Implementations§

source§

impl<Unit> Rect<Unit>

source

pub const fn new(origin: Point<Unit>, size: Size<Unit>) -> Self

Returns a new rectangle.

source

pub fn from_extents(p1: Point<Unit>, p2: Point<Unit>) -> Selfwhere Unit: Unit,

Returns a new rectangle using the given points to form the top-left and bottom-right of the rectangle.

The order of the parameters does not matter. The minimum values will form the top-left and the maximum values will form the bottom-right.

source

pub fn expand_rounded(self) -> Selfwhere Unit: Round + Unit,

Expands this rect to the nearest whole number.

This function will never return a smaller rectangle.

source

pub fn map<NewUnit>(self, map: impl FnMut(Unit) -> NewUnit) -> Rect<NewUnit>

Maps each component to map and returns a new value with the mapped components.

source

pub fn inset(self, amount: impl Into<Unit>) -> Selfwhere Unit: Add<Unit, Output = Unit> + AddAssign<Unit> + SubAssign<Unit> + Copy,

Returns a rectangle that has been inset by amount on all sides.

source

pub fn cast<NewUnit>(self) -> Rect<NewUnit>where NewUnit: From<Unit>,

Converts the contents of this point to NewUnit using From.

source

pub fn try_cast<NewUnit>(self) -> Result<Rect<NewUnit>, NewUnit::Error>where NewUnit: TryFrom<Unit>,

Converts the contents of this rect to NewUnit using TryFrom.

Errors

Returns <NewUnit as TryFrom>::Error when the inner type cannot be converted. For this crate’s types, this genenerally will be

source

pub fn contains(&self, point: Point<Unit>) -> boolwhere Unit: Unit,

Returns true if this rect contains point.

source

pub fn intersects(&self, other: &Self) -> boolwhere Unit: Add<Output = Unit> + Ord + Copy,

Returns true if the areas of self and other overlap.

This function does not return true if the edges touch but do not overlap.

use figures::{Point, Rect, Size};

let a: Rect<i32> = Rect::new(Point::new(1, 1), Size::new(2, 2));
let b = Rect::new(Point::new(2, 2), Size::new(1, 1));
assert!(a.intersects(&b));
let c = Rect::new(Point::new(3, 1), Size::new(1, 1));
assert!(!a.intersects(&c));
source

pub fn intersection(&self, other: &Self) -> Option<Rect<Unit>>where Unit: Unit,

Returns the overlapping rectangle of self and other. If the rectangles do not overlap, None will be returned.

use figures::{Point, Rect, Size};

let a: Rect<i32> = Rect::new(Point::new(1, 1), Size::new(3, 3));
let b = Rect::new(Point::new(2, 2), Size::new(3, 3));
assert_eq!(
    a.intersection(&b),
    Some(Rect::new(Point::new(2, 2), Size::new(2, 2)))
);
let c = Rect::new(Point::new(4, 1), Size::new(1, 1));
assert_eq!(a.intersection(&c), None);
source

pub fn extent(&self) -> Point<Unit>where Unit: Unit,

Returns the non-origin point.

source§

impl<Unit> Rect<Unit>where Unit: Add<Output = Unit> + Ord + Copy,

source

pub fn extents(&self) -> (Point<Unit>, Point<Unit>)

Returns the top-left and bottom-right points of this rectangle.

The first point returned will always be the top-right point, even if the size of the rectangle is negative.

Trait Implementations§

source§

impl<Unit> Add<Point<Unit>> for Rect<Unit>where Unit: Add<Output = Unit>,

§

type Output = Rect<Unit>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Point<Unit>) -> Self::Output

Performs the + operation. Read more
source§

impl<Unit: Clone> Clone for Rect<Unit>

source§

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

Returns a copy 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<Unit: Debug> Debug for Rect<Unit>

source§

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

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

impl<Unit> Default for Rect<Unit>where Unit: Default,

source§

fn default() -> Self

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

impl<'de, Unit> Deserialize<'de> for Rect<Unit>where Unit: Deserialize<'de>,

source§

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<Unit> From<Size<Unit>> for Rect<Unit>where Unit: Default,

source§

fn from(size: Size<Unit>) -> Self

Converts to this type from the input type.
source§

impl<Unit: Hash> Hash for Rect<Unit>

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<Unit> IntoSigned for Rect<Unit>where Unit: IntoSigned,

§

type Signed = Rect<<Unit as IntoSigned>::Signed>

The signed representation of this type.
source§

fn into_signed(self) -> Self::Signed

Returns this value as an unsigned value. Values that are larger than can fit in an i32 are converted to i32::MAX.
source§

impl<Unit> IntoUnsigned for Rect<Unit>where Unit: IntoUnsigned,

§

type Unsigned = Rect<<Unit as IntoUnsigned>::Unsigned>

The unsigned representation of this type.
source§

fn into_unsigned(self) -> Self::Unsigned

Returns this value as an unsigned value. Negative values will be converted to 0.
source§

impl<Unit: PartialEq> PartialEq for Rect<Unit>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Unit> Ranged for Rect<Unit>where Unit: Ranged,

source§

const MAX: Self = _

The maximum value for this type.
source§

const MIN: Self = _

The minimum value for this type.
source§

impl<Unit> Serialize for Rect<Unit>where Unit: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<Unit> Sub<Point<Unit>> for Rect<Unit>where Unit: Sub<Output = Unit>,

§

type Output = Rect<Unit>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Point<Unit>) -> Self::Output

Performs the - operation. Read more
source§

impl<Unit> Zero for Rect<Unit>where Unit: Zero,

source§

const ZERO: Self = _

The zero value for this type.
source§

fn is_zero(&self) -> bool

Returns true if self represents 0.
source§

impl<Unit: Copy> Copy for Rect<Unit>

source§

impl<Unit: Eq> Eq for Rect<Unit>

source§

impl<Unit> StructuralEq for Rect<Unit>

source§

impl<Unit> StructuralPartialEq for Rect<Unit>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<A> Cast for A

§

fn cast<To>(self) -> Towhere To: CastFrom<A>,

Casts self to the To type. This may be a lossy operation.
§

impl<A> CastFrom<A> for A

§

fn from_cast(from: A) -> A

Returns from as Self.
§

impl<A, B> CastInto<A> for Bwhere A: CastFrom<B>,

§

fn cast_into(self) -> A

Returns self as To.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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<Unit> IntoComponents<Unit> for Unitwhere Unit: Copy,

source§

fn into_components(self) -> (Unit, Unit)

Extracts this type’s 2d vector components.
source§

fn to_vec<Type>(self) -> Typewhere Type: FromComponents<Unit>,

Converts this type to another type using FromComponents and IntoComponents.
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

§

impl<T> WasmNotSend for Twhere T: Send,

§

impl<T> WasmNotSendSync for Twhere T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for Twhere T: Sync,