Struct axgeom::Rect

source ·
pub struct Rect<T> {
    pub x: Range<T>,
    pub y: Range<T>,
}
Expand description

An axis aligned rectangle. Stored as two Ranges.

Fields§

§x: Range<T>§y: Range<T>

Implementations§

source§

impl<S> Rect<S>

source

pub fn inner_into<A>(self) -> Rect<A>where S: Into<A>,

source

pub fn inner_try_into<A>(self) -> Result<Rect<A>, S::Error>where S: TryInto<A>,

source§

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

source

pub fn from_point(point: Vec2<T>, radius: Vec2<T>) -> Rect<T>

Create a rectangle from a point and radius.

source§

impl<T> Rect<T>

source

pub fn get_range(&self, axis: impl Axis) -> &Range<T>

Get the range of one axis.

source

pub fn get_range_mut(&mut self, axis: impl Axis) -> &mut Range<T>

Get the mutable range of one axis.

source§

impl<T> Rect<T>

source

pub fn new(xstart: T, xend: T, ystart: T, yend: T) -> Rect<T>

Constructor. (xstart,xend) is the x component range. (ystart,yend) is the y component range.

source§

impl<T: Copy> Rect<T>

source

pub fn top_left(&self) -> Vec2<T>

source

pub fn get_corners(&self) -> [Vec2<T>; 4]

Returns each corner in this order: topleft topright bottomright bottomleft

source

pub fn inner_as<B: 'static + Copy>(&self) -> Rect<B>where T: AsPrimitive<B>,

source

pub fn get(&self) -> ((T, T), (T, T))

(a,b) is the x component range. (c,d) is the y component range.

source§

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

source

pub fn contains_point(&self, a: Vec2<T>) -> bool

Returns true if the point is contained in the the ranges of both axis.

source§

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

source

pub fn grow(self, radius: T) -> Self

Grow a rectangle of a radius.

source§

impl<T: Copy + PartialOrd + Sub<Output = T> + Mul<Output = T> + Add<Output = T>> Rect<T>

source

pub fn distance_squared_to_point(&self, point: Vec2<T>) -> Option<T>

If the point is outside the rectangle, returns the squared distance from the closest corner of the rectangle. If the point is inside the rectangle, it will return None.

source

pub fn furthest_distance_squared_to_point(&self, point: Vec2<T>) -> T

If the point is outside the rectangle, returns the squared distance from a point to the furthest corner of the rectangle.

source§

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

source

pub fn derive_center(&self) -> Vec2<T>

source§

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

source

pub fn subdivide<A: Axis>(&self, axis: A, divider: T) -> (Rect<T>, Rect<T>)

Subdivides the rectangle. No floating point calculations are done. Important to note that a point that was in the original rectangle, could actually be inside both subdivded rectangles. This is because the ranges are inclusive on both sides [start,end].

source

pub fn is_valid(&self) -> bool

Returns true if the rectangle’s ranges are not degenerate.

source

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

Returns true if the specified rect is inside of this rect.

source

pub fn grow_to_fit_point(&mut self, point: Vec2<T>) -> &mut Self

source

pub fn grow_to_fit(&mut self, rect: &Rect<T>) -> &mut Self

Grow the rectangle to fit the specified rectangle by replacing values with the specified rectangle. No floating point computations.

source

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

source§

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

source

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

Get an intersecting rectangle. No floating point calculations as the new rectangle is made up of values from this rectangle and the specified rectangle.

Trait Implementations§

source§

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

source§

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

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> 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> Default for Rect<T>

source§

fn default() -> Rect<T>

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

impl<B: Copy> From<&Rect<B>> for [B; 4]

source§

fn from(a: &Rect<B>) -> Self

Converts to this type from the input type.
source§

impl<B> From<[B; 4]> for Rect<B>

source§

fn from(a: [B; 4]) -> Self

Converts to this type from the input type.
source§

impl<B> From<Rect<B>> for [B; 4]

source§

fn from(a: Rect<B>) -> Self

Converts to this type from the input type.
source§

impl<T: Hash> 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> PartialEq<Rect<T>> for Rect<T>

source§

fn eq(&self, other: &Rect<T>) -> 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: Copy> Copy for Rect<T>

source§

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

source§

impl<T> StructuralEq for Rect<T>

source§

impl<T> StructuralPartialEq for Rect<T>

Auto Trait Implementations§

§

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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