Skip to main content

RectExt

Trait RectExt 

Source
pub trait RectExt: Sized {
    type Val: Copy + Add<Output = Self::Val> + Sub<Output = Self::Val> + PartialOrd;

Show 46 methods // Required methods fn from_pos_size( pos: impl Into<Vec2<Self::Val>>, size: impl Into<Vec2<Self::Val>>, ) -> Self; fn width(&self) -> Self::Val; fn height(&self) -> Self::Val; fn x(&self) -> Self::Val; fn y(&self) -> Self::Val; fn set_width(&mut self, w: Self::Val); fn set_height(&mut self, h: Self::Val); fn set_x(&mut self, x: Self::Val); fn set_y(&mut self, y: Self::Val); // Provided methods fn from_ranges( lr: impl Into<Range<Self::Val>>, tb: impl Into<Range<Self::Val>>, ) -> Self { ... } fn from_points( a: impl Into<Vec2<Self::Val>>, b: impl Into<Vec2<Self::Val>>, ) -> Self { ... } fn pos(&self) -> Vec2<Self::Val> { ... } fn size(&self) -> Vec2<Self::Val> { ... } fn left(&self) -> Self::Val { ... } fn top(&self) -> Self::Val { ... } fn right(&self) -> Self::Val { ... } fn bottom(&self) -> Self::Val { ... } fn top_left(&self) -> Vec2<Self::Val> { ... } fn top_right(&self) -> Vec2<Self::Val> { ... } fn bot_right(&self) -> Vec2<Self::Val> { ... } fn bot_left(&self) -> Vec2<Self::Val> { ... } fn xrange(&self) -> Range<Self::Val> { ... } fn yrange(&self) -> Range<Self::Val> { ... } fn center(&self) -> Vec2<Self::Val> where Self::Val: Div<Output = Self::Val> + Two { ... } fn pad_rect(&self, padding: impl Into<Padding<Self::Val>>) -> Self where Self::Val: PartialOrd + Zero { ... } fn extend_rect(&self, margin: impl Into<Padding<Self::Val>>) -> Self { ... } fn bound_join(&self, other: impl Into<Self>) -> Self { ... } fn intersect(&self, other: impl Into<Self>) -> Self { ... } fn move_to(&mut self, pos: impl Into<Vec2<Self::Val>>) -> &mut Self { ... } fn encloses(&self, other: &Self) -> bool { ... } fn contains(&self, point: impl Into<Vec2<Self::Val>>) -> bool { ... } fn intersects(&self, other: &Self) -> bool { ... } fn area(&self) -> Self::Val where Self::Val: Mul<Output = Self::Val> { ... } fn is_empty(&self) -> bool where Self::Val: PartialEq + Zero { ... } fn clamp(&self, pt: impl Into<Vec2<Self::Val>>) -> Vec2<Self::Val> { ... } fn set_pos(&mut self, pos: impl Into<Vec2<Self::Val>>) { ... } fn set_size(&mut self, size: impl Into<Vec2<Self::Val>>) { ... } fn extend_bot(&mut self, amt: Self::Val) { ... } fn extend_right(&mut self, amt: Self::Val) { ... } fn extend_left(&mut self, amt: Self::Val) { ... } fn extend_top(&mut self, amt: Self::Val) { ... } fn moved_by(&self, amt: impl Into<Vec2<Self::Val>>) -> Self { ... } fn set_right(&mut self, r: Self::Val) { ... } fn set_left(&mut self, l: Self::Val) { ... } fn set_bottom(&mut self, b: Self::Val) { ... } fn set_top(&mut self, t: Self::Val) { ... }
}

Required Associated Types§

Source

type Val: Copy + Add<Output = Self::Val> + Sub<Output = Self::Val> + PartialOrd

Required Methods§

Source

fn from_pos_size( pos: impl Into<Vec2<Self::Val>>, size: impl Into<Vec2<Self::Val>>, ) -> Self

Create new rectangle from position of top left corner and size.

Source

fn width(&self) -> Self::Val

Get the width of the rectangle.

Source

fn height(&self) -> Self::Val

Get the height of the rectangle.

Source

fn x(&self) -> Self::Val

Get the x coordinate of the rectangle.

Source

fn y(&self) -> Self::Val

Get the y coordinate of the rectangle.

Source

fn set_width(&mut self, w: Self::Val)

Set the width of the rectangle.

Source

fn set_height(&mut self, h: Self::Val)

Set the height of the rectangle.

Source

fn set_x(&mut self, x: Self::Val)

Set the x coordinate of the rectangle.

Source

fn set_y(&mut self, y: Self::Val)

Set the y coordinate of the rectangle.

Provided Methods§

Source

fn from_ranges( lr: impl Into<Range<Self::Val>>, tb: impl Into<Range<Self::Val>>, ) -> Self

Create the rectangle from ranges of coordinates.

Source

fn from_points( a: impl Into<Vec2<Self::Val>>, b: impl Into<Vec2<Self::Val>>, ) -> Self

Create the rectangle from two points.

Source

fn pos(&self) -> Vec2<Self::Val>

Get the position of the rectangle.

Source

fn size(&self) -> Vec2<Self::Val>

Get the size of the rectangle.

Source

fn left(&self) -> Self::Val

Get the left coordinate of the rectangle.

Source

fn top(&self) -> Self::Val

Get the top coordinate of the rectangle.

Source

fn right(&self) -> Self::Val

Get the right coordinate of the rectangle.

Source

fn bottom(&self) -> Self::Val

Get the bottom coordinate of the rectangle.

Source

fn top_left(&self) -> Vec2<Self::Val>

Get the top left corner position.

Source

fn top_right(&self) -> Vec2<Self::Val>

Get the top right corner position.

Source

fn bot_right(&self) -> Vec2<Self::Val>

Get the bottom right corner position.

Source

fn bot_left(&self) -> Vec2<Self::Val>

Get the bottom left corner position.

Source

fn xrange(&self) -> Range<Self::Val>

Get the range in x coordinate.

Source

fn yrange(&self) -> Range<Self::Val>

Get the range in y coordinate.

Source

fn center(&self) -> Vec2<Self::Val>
where Self::Val: Div<Output = Self::Val> + Two,

Get the center of the rectangle.

Source

fn pad_rect(&self, padding: impl Into<Padding<Self::Val>>) -> Self
where Self::Val: PartialOrd + Zero,

Shrink the rectangle with padding.

Source

fn extend_rect(&self, margin: impl Into<Padding<Self::Val>>) -> Self

Enlarge the rectangle with the given padding.

Source

fn bound_join(&self, other: impl Into<Self>) -> Self

Create rectangle that encloses both of the rectangles.

Source

fn intersect(&self, other: impl Into<Self>) -> Self

Create rectangle that is the intersection of two rectangles.

Source

fn move_to(&mut self, pos: impl Into<Vec2<Self::Val>>) -> &mut Self

Change the position of the rectangle.

Source

fn encloses(&self, other: &Self) -> bool

Check whether this rectangle fully encloses the other rectangle.

Source

fn contains(&self, point: impl Into<Vec2<Self::Val>>) -> bool

Check whether this rectangle contains the given point.

Source

fn intersects(&self, other: &Self) -> bool

Check whether two rectangles intersect.

Source

fn area(&self) -> Self::Val
where Self::Val: Mul<Output = Self::Val>,

Get the area of the rectangle.

Source

fn is_empty(&self) -> bool
where Self::Val: PartialEq + Zero,

Check whether the rectangle is empty.

Source

fn clamp(&self, pt: impl Into<Vec2<Self::Val>>) -> Vec2<Self::Val>

Clamp the point to be contained in the rectangle.

Source

fn set_pos(&mut self, pos: impl Into<Vec2<Self::Val>>)

Sets the position to the given value.

Source

fn set_size(&mut self, size: impl Into<Vec2<Self::Val>>)

Sets the size of the rectangle.

Source

fn extend_bot(&mut self, amt: Self::Val)

Extend the rectangle from bottom by the given amount.

Source

fn extend_right(&mut self, amt: Self::Val)

Extend the rectangle from right by the given amount.

Source

fn extend_left(&mut self, amt: Self::Val)

Extend the rectangle from left by the given amount.

Source

fn extend_top(&mut self, amt: Self::Val)

Extend the rectangle from left by the given amount.

Source

fn moved_by(&self, amt: impl Into<Vec2<Self::Val>>) -> Self

Create new rectangle moved by the given amount.

Source

fn set_right(&mut self, r: Self::Val)

Set the right value.

Source

fn set_left(&mut self, l: Self::Val)

Set the left value.

Source

fn set_bottom(&mut self, b: Self::Val)

Set the bottom value.

Source

fn set_top(&mut self, t: Self::Val)

Set the top value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> RectExt for Rect<T>
where T: Copy + Add<Output = T> + Sub<Output = T> + PartialOrd,

Source§

type Val = T

Source§

impl<T> RectExt for Vec4<T>
where T: Copy + Add<Output = T> + Sub<Output = T> + PartialOrd,

Source§

type Val = T