Struct RectRange

Source
pub struct RectRange<T: Num + PartialOrd> { /* private fields */ }
Expand description

RectRange is rectangle representation using std::ops::Range.

Diffrent from Range, RectRange itself isn’t a iterator, but has IntoIterator implementation and iter method(with ‘clone’).

Implementations§

Source§

impl<T: Num + PartialOrd> RectRange<T>

Source

pub fn new(lx: T, ly: T, ux: T, uy: T) -> Option<RectRange<T>>

construct a range from left x, lower y, right x, upper y

Source

pub fn zero_start(x: T, y: T) -> Option<RectRange<T>>

construct a range x_range: 0..x, y_range: 0..y

Source

pub fn from_point<P: IntoTuple2<T>>(p: P) -> Option<RectRange<T>>

construct a range x_range: 0..p.x, y_range: 0..p.y

Source

pub fn from_ranges(x_range: Range<T>, y_range: Range<T>) -> Option<RectRange<T>>

construct a range x_range: 0..x, y_range: 0..y

Source

pub fn contains<P: IntoTuple2<T>>(&self, p: P) -> bool

checks if the range contains the point

Source

pub fn get_x(&self) -> &Range<T>

get a reference of x range

Source

pub fn get_y(&self) -> &Range<T>

get a reference of y range

Source

pub fn get_mut_x(&mut self) -> &mut Range<T>

get a mutable reference of x range

Source

pub fn get_mut_y(&mut self) -> &mut Range<T>

get a mutable reference of y range

Source

pub fn is_valid(&self) -> bool

checks if the range is valid or not

Source§

impl<T: Num + PartialOrd + Clone> RectRange<T>

Source

pub fn cloned_x(&self) -> Range<T>

get x range

Source

pub fn cloned_y(&self) -> Range<T>

get y range

Source

pub fn slide<P: IntoTuple2<T>>(self, t: P) -> RectRange<T>

slide range by the given point

Source

pub fn slide_start<P: IntoTuple2<T>>(self, t: P) -> RectRange<T>

slide start point without checking

Source

pub fn slide_end<P: IntoTuple2<T>>(self, t: P) -> RectRange<T>

slide end point without checking

Source

pub fn xlen(&self) -> T

the length in the x-axis deirection

Source

pub fn ylen(&self) -> T

the length of in the y-axis deirection

Source

pub fn area(&self) -> T

calc the area of the range

Source

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

judges if 2 ranges have intersection

Source

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

gets the intersection of 2 ranges

Source

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

get the lower left corner(inclusive)

Source

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

get the lower right corner(inclusive)

Source

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

get the upper left corner(inclusive)

Source

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

get the upper right corner(inclusive)

Source

pub fn is_edge<P: IntoTuple2<T>>(&self, p: P) -> bool

checks if the point is on the edge of the rectangle

Source

pub fn is_vert_edge<P: IntoTuple2<T>>(&self, p: P) -> bool

checks if the point is on the vertical edge of the rectangle

Source

pub fn is_horiz_edge<P: IntoTuple2<T>>(&self, p: P) -> bool

checks if the point is on the horizoni edge of the rectangle

Source§

impl<T: Num + PartialOrd + Copy> RectRange<T>

Source

pub fn from_rect<U>(rect: Rect<T, U>) -> Option<RectRange<T>>

Source

pub fn to_rect<U>(&self) -> Rect<T, U>

Source

pub fn from_corners<P: IntoTuple2<T>>(lu: P, rd: P) -> Option<RectRange<T>>

generate RectRange from corners(lower: inclusive, upper: exclusive)

Source

pub fn iter(&self) -> RectIter<T>

get iterator from reference

Source

pub fn scale(self, sc: T) -> RectRange<T>

expand the rectangle

Source§

impl<T: Num + PartialOrd + ToPrimitive + Copy> RectRange<T>

Source

pub fn to_u8(self) -> Option<RectRange<u8>>

Source

pub fn to_u16(self) -> Option<RectRange<u16>>

Source

pub fn to_u32(self) -> Option<RectRange<u32>>

Source

pub fn to_u64(self) -> Option<RectRange<u64>>

Source

pub fn to_i8(self) -> Option<RectRange<i8>>

Source

pub fn to_i16(self) -> Option<RectRange<i16>>

Source

pub fn to_i32(self) -> Option<RectRange<i32>>

Source

pub fn to_i64(self) -> Option<RectRange<i64>>

Source

pub fn to_usize(self) -> Option<RectRange<usize>>

Source§

impl<T: Num + PartialOrd + Copy + FromPrimitive + ToPrimitive> RectRange<T>

Source

pub fn len(&self) -> usize

returns self.xlen * self.ylen as usize

Source

pub fn nth(&self, n: usize) -> Option<(T, T)>

return ‘nth’ element same as RectIter::nth, but much faster(O(1))

Source

pub fn index<P: IntoTuple2<T>>(&self, p: P) -> Option<usize>

take Point and return 0-start unique index using the same order as RectIter

Trait Implementations§

Source§

impl<T: Clone + Num + PartialOrd> Clone for RectRange<T>

Source§

fn clone(&self) -> RectRange<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 + Num + PartialOrd> Debug for RectRange<T>

Source§

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

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

impl<'de, T> Deserialize<'de> for RectRange<T>
where T: Deserialize<'de> + Num + PartialOrd,

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<T: Hash + Num + PartialOrd> Hash for RectRange<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: Num + PartialOrd + Copy> IntoIterator for RectRange<T>

Source§

type Item = (T, T)

The type of the elements being iterated over.
Source§

type IntoIter = RectIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq + Num + PartialOrd> PartialEq for RectRange<T>

Source§

fn eq(&self, other: &RectRange<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> Serialize for RectRange<T>
where T: Serialize + Num + PartialOrd,

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<T: Eq + Num + PartialOrd> Eq for RectRange<T>

Source§

impl<T: Num + PartialOrd> StructuralPartialEq for RectRange<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for RectRange<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

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