[go: up one dir, main page]

Struct euclid::rect::TypedRect

source ·
pub struct TypedRect<T, U = UnknownUnit> {
    pub origin: TypedPoint2D<T, U>,
    pub size: TypedSize2D<T, U>,
}
Expand description

A 2d Rectangle optionally tagged with a unit.

Fields§

§origin: TypedPoint2D<T, U>§size: TypedSize2D<T, U>

Implementations§

source§

impl<T, U> TypedRect<T, U>

source

pub fn new( origin: TypedPoint2D<T, U>, size: TypedSize2D<T, U>, ) -> TypedRect<T, U>

Constructor.

source§

impl<T, U> TypedRect<T, U>
where T: Copy + Clone + Zero + PartialOrd + PartialEq + Add<T, Output = T> + Sub<T, Output = T>,

source

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

source

pub fn max_x(&self) -> T

source

pub fn min_x(&self) -> T

source

pub fn max_y(&self) -> T

source

pub fn min_y(&self) -> T

source

pub fn max_x_typed(&self) -> Length<T, U>

source

pub fn min_x_typed(&self) -> Length<T, U>

source

pub fn max_y_typed(&self) -> Length<T, U>

source

pub fn min_y_typed(&self) -> Length<T, U>

source

pub fn intersection(&self, other: &TypedRect<T, U>) -> Option<TypedRect<T, U>>

source

pub fn translate(&self, other: &TypedPoint2D<T, U>) -> TypedRect<T, U>

Translates the rect by a vector.

source

pub fn contains(&self, other: &TypedPoint2D<T, U>) -> bool

Returns true if this rectangle contains the point. Points are considered in the rectangle if they are on the left or top edge, but outside if they are on the right or bottom edge.

source

pub fn contains_rect(&self, rect: &TypedRect<T, U>) -> bool

Returns true if this rectangle contains the interior of rect. Always returns true if rect is empty, and always returns false if rect is nonempty but this rectangle is empty.

source

pub fn inflate(&self, width: T, height: T) -> TypedRect<T, U>

source

pub fn inflate_typed( &self, width: Length<T, U>, height: Length<T, U>, ) -> TypedRect<T, U>

source

pub fn top_right(&self) -> TypedPoint2D<T, U>

source

pub fn bottom_left(&self) -> TypedPoint2D<T, U>

source

pub fn bottom_right(&self) -> TypedPoint2D<T, U>

source

pub fn translate_by_size(&self, size: &TypedSize2D<T, U>) -> TypedRect<T, U>

source§

impl<T, U> TypedRect<T, U>
where T: Copy + Clone + PartialOrd + Add<T, Output = T> + Sub<T, Output = T> + Zero,

source

pub fn union(&self, other: &TypedRect<T, U>) -> TypedRect<T, U>

source§

impl<T, U> TypedRect<T, U>

source

pub fn scale<Scale: Copy>(&self, x: Scale, y: Scale) -> TypedRect<T, U>
where T: Copy + Clone + Mul<Scale, Output = T>,

source§

impl<T: Copy + PartialEq + Zero, U> TypedRect<T, U>

source

pub fn zero() -> TypedRect<T, U>

Constructor, setting all sides to zero.

source

pub fn is_empty(&self) -> bool

Returns true if the size is zero, regardless of the origin’s value.

source§

impl<T: Copy, Unit> TypedRect<T, Unit>

source

pub fn to_untyped(&self) -> Rect<T>

Drop the units, preserving only the numeric value.

source

pub fn from_untyped(r: &Rect<T>) -> TypedRect<T, Unit>

Tag a unitless value with units.

source§

impl<T0: NumCast + Copy, Unit> TypedRect<T0, Unit>

source

pub fn cast<T1: NumCast + Copy>(&self) -> Option<TypedRect<T1, Unit>>

Cast from one numeric representation to another, preserving the units.

When casting from floating point to integer coordinates, the decimals are truncated as one would expect from a simple cast, but this behavior does not always make sense geometrically. Consider using round(), round_in or round_out() before casting.

source§

impl<T: Floor + Ceil + Round + Add<T, Output = T> + Sub<T, Output = T>, U> TypedRect<T, U>

source

pub fn round(&self) -> Self

Return a rectangle with edges rounded to integer coordinates, such that the returned rectangle has the same set of pixel centers as the original one. Edges at offset 0.5 round up. Suitable for most places where integral device coordinates are needed, but note that any translation should be applied first to avoid pixel rounding errors. Note that this is not rounding to nearest integer if the values are negative. They are always rounding as floor(n + 0.5).

source

pub fn round_in(&self) -> Self

Return a rectangle with edges rounded to integer coordinates, such that the original rectangle contains the resulting rectangle.

source

pub fn round_out(&self) -> Self

Return a rectangle with edges rounded to integer coordinates, such that the original rectangle is contained in the resulting rectangle.

source§

impl<T: NumCast + Copy, Unit> TypedRect<T, Unit>

source

pub fn to_f32(&self) -> TypedRect<f32, Unit>

Cast into an f32 vector.

source

pub fn to_uint(&self) -> TypedRect<usize, Unit>

Cast into an usize vector, truncating decimals if any.

When casting from floating point vectors, it is worth considering whether to round(), round_in() or round_out() before the cast in order to obtain the desired conversion behavior.

source

pub fn to_i32(&self) -> TypedRect<i32, Unit>

Cast into an i32 vector, truncating decimals if any.

When casting from floating point vectors, it is worth considering whether to round(), round_in() or round_out() before the cast in order to obtain the desired conversion behavior.

source

pub fn to_i64(&self) -> TypedRect<i64, Unit>

Cast into an i64 vector, truncating decimals if any.

When casting from floating point vectors, it is worth considering whether to round(), round_in() or round_out() before the cast in order to obtain the desired conversion behavior.

Trait Implementations§

source§

impl<T: Copy, U> Clone for TypedRect<T, U>

source§

fn clone(&self) -> TypedRect<T, U>

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<T: Debug, U> Debug for TypedRect<T, U>

source§

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

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

impl<T: Decodable, U: Decodable> Decodable for TypedRect<T, U>

source§

fn decode<__D: Decoder>(d: &mut __D) -> Result<TypedRect<T, U>, __D::Error>

Deserialize a value using a Decoder.
source§

impl<T: Copy + Deserialize, U> Deserialize for TypedRect<T, U>

source§

fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>
where D: Deserializer,

Deserialize this value given this Deserializer.
source§

impl<T: Display, U> Display for TypedRect<T, U>

source§

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

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

impl<T: Copy + Div<T, Output = T>, U1, U2> Div<ScaleFactor<T, U1, U2>> for TypedRect<T, U2>

§

type Output = TypedRect<T, U1>

The resulting type after applying the / operator.
source§

fn div(self, scale: ScaleFactor<T, U1, U2>) -> TypedRect<T, U1>

Performs the / operation. Read more
source§

impl<T: Copy + Div<T, Output = T>, U> Div<T> for TypedRect<T, U>

§

type Output = TypedRect<T, U>

The resulting type after applying the / operator.
source§

fn div(self, scale: T) -> TypedRect<T, U>

Performs the / operation. Read more
source§

impl<T: Encodable, U: Encodable> Encodable for TypedRect<T, U>

source§

fn encode<__S: Encoder>(&self, s: &mut __S) -> Result<(), __S::Error>

Serialize a value using an Encoder.
source§

impl<T: HeapSizeOf, U> HeapSizeOf for TypedRect<T, U>

source§

fn heap_size_of_children(&self) -> usize

Measure the size of any heap-allocated structures that hang off this value, but not the space taken up by the value itself (i.e. what size_of:: measures, more or less); that space is handled by the implementation of HeapSizeOf for Box below.
source§

impl<T: Copy + Mul<T, Output = T>, U1, U2> Mul<ScaleFactor<T, U1, U2>> for TypedRect<T, U1>

§

type Output = TypedRect<T, U2>

The resulting type after applying the * operator.
source§

fn mul(self, scale: ScaleFactor<T, U1, U2>) -> TypedRect<T, U2>

Performs the * operation. Read more
source§

impl<T: Copy + Mul<T, Output = T>, U> Mul<T> for TypedRect<T, U>

§

type Output = TypedRect<T, U>

The resulting type after applying the * operator.
source§

fn mul(self, scale: T) -> TypedRect<T, U>

Performs the * operation. Read more
source§

impl<T: PartialEq, U> PartialEq for TypedRect<T, U>

source§

fn eq(&self, other: &TypedRect<T, U>) -> 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<T: Serialize, U> Serialize for TypedRect<T, U>

source§

fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer,

Serializes this value into this serializer.
source§

impl<T: Copy, U> Copy for TypedRect<T, U>

source§

impl<T: Eq, U> Eq for TypedRect<T, U>

Auto Trait Implementations§

§

impl<T, U> Freeze for TypedRect<T, U>
where T: Freeze,

§

impl<T, U> RefUnwindSafe for TypedRect<T, U>

§

impl<T, U> Send for TypedRect<T, U>
where T: Send, U: Send,

§

impl<T, U> Sync for TypedRect<T, U>
where T: Sync, U: Sync,

§

impl<T, U> Unpin for TypedRect<T, U>
where T: Unpin, U: Unpin,

§

impl<T, U> UnwindSafe for TypedRect<T, U>
where T: UnwindSafe, U: 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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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

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

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.