Range

Struct Range 

Source
pub struct Range<T> {
    pub start: T,
    pub end: T,
}
Expand description

A 1D range. Internally represented as start and end. (as opposed to a start and length) If range A contains value x and range B contains value x, then A intersects B. There is no protection against “degenerate” Ranges where start>end.

A point is consindered inside of a range if the point is in [start,end].

Fields§

§start: T§end: T

Implementations§

Source§

impl<T> Range<T>

Source

pub fn new(start: T, end: T) -> Range<T>

Source§

impl<T> Range<T>
where T: Copy + Ord + Sub<Output = T> + Signed,

Source

pub fn distance_to_point(&self, pos: T) -> Option<T>

Source

pub fn difference_to_point(&self, pos: T) -> Option<T>

Positive if point is to the right of the range. Negative if point is to the left of range.

Source§

impl<T> Range<T>
where T: Copy + PartialOrd,

Source

pub fn contains_ext(&self, pos: T) -> Ordering

Like contains() but returns Ord. If the pos is strictly less than the range.start, return less. If the pos is greater of equal to the range.end, return greater. else, return equal.

Source

pub fn contains(&self, pos: T) -> bool

Returns true if the point is inside of the range or on top of.

Source

pub fn subdivide(&self, divider: T) -> (Range<T>, Range<T>)

Subdivides the range. No floating point calculations are done.

Source

pub fn is_valid(&self) -> bool

Source

pub fn grow_to_fit(&mut self, b: &Range<T>)

Source

pub fn contains_range(&self, val: &Range<T>) -> bool

Returns true if self contains the specified range.

Source

pub fn intersects(&self, val: &Range<T>) -> bool

Returns true if two ranges intersect.

Source§

impl<T> Range<T>
where T: Copy + Sub<Output = T>,

Source

pub fn distance(&self) -> T

Source§

impl<T> Range<T>
where T: Sub<Output = T> + Add<Output = T> + Copy,

Source

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

Source§

impl<S> Range<S>

Source

pub fn inner_as<B>(self) -> Range<B>
where B: 'static + Copy, S: AsPrimitive<B>,

Source

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

Source

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

Source§

impl<T> Range<T>
where T: Sub<Output = T> + Add<Output = T> + Copy,

Source

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

Create a range from a point and radius.

Source§

impl<T> Range<T>
where T: Copy + Ord,

Source

pub fn get_intersection(&self, val: &Range<T>) -> Option<Range<T>>

Creates a range that represents the intersection range.

Trait Implementations§

Source§

impl<T> Clone for Range<T>
where T: Clone,

Source§

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

Returns a duplicate 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 for Range<T>
where T: Debug,

Source§

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

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

impl<T> Default for Range<T>
where T: Default,

Source§

fn default() -> Range<T>

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

impl<B> From<[B; 2]> for Range<B>

Source§

fn from(a: [B; 2]) -> Range<B>

Converts to this type from the input type.
Source§

impl<T> Hash for Range<T>
where T: Hash,

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

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 for Range<T>
where T: PartialEq,

Source§

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

Source§

impl<T> Eq for Range<T>
where T: Eq,

Source§

impl<T> StructuralPartialEq for Range<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Range<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.