#[repr(C)]pub struct Rangef {
pub min: f32,
pub max: f32,
}
Expand description
Inclusive range of floats, i.e. min..=max
, but more ergonomic than RangeInclusive
.
Fields§
§min: f32
§max: f32
Implementations§
source§impl Rangef
impl Rangef
sourcepub const EVERYTHING: Rangef = _
pub const EVERYTHING: Rangef = _
Infinite range that contains everything, from -∞ to +∞, inclusive.
sourcepub const NOTHING: Rangef = _
pub const NOTHING: Rangef = _
The inverse of Self::EVERYTHING
: stretches from positive infinity to negative infinity.
Contains nothing.
pub fn new(min: f32, max: f32) -> Rangef
pub fn point(min_and_max: f32) -> Rangef
pub fn contains(self, x: f32) -> bool
sourcepub fn as_positive(self) -> Rangef
pub fn as_positive(self) -> Rangef
Flip min
and max
if needed, so that min <= max
after.
sourcepub fn intersection(self, other: Rangef) -> Rangef
pub fn intersection(self, other: Rangef) -> Rangef
The overlap of two ranges, i.e. the range that is contained by both.
If the ranges do not overlap, returns a range with span() < 0.0
.
assert_eq!(Rangef::new(0.0, 10.0).intersection(Rangef::new(5.0, 15.0)), Rangef::new(5.0, 10.0));
assert_eq!(Rangef::new(0.0, 10.0).intersection(Rangef::new(10.0, 20.0)), Rangef::new(10.0, 10.0));
assert!(Rangef::new(0.0, 10.0).intersection(Rangef::new(20.0, 30.0)).span() < 0.0);
sourcepub fn intersects(self, other: Rangef) -> bool
pub fn intersects(self, other: Rangef) -> bool
Do the two ranges intersect?
assert!(Rangef::new(0.0, 10.0).intersects(Rangef::new(5.0, 15.0)));
assert!(Rangef::new(0.0, 10.0).intersects(Rangef::new(5.0, 6.0)));
assert!(Rangef::new(0.0, 10.0).intersects(Rangef::new(10.0, 20.0)));
assert!(!Rangef::new(0.0, 10.0).intersects(Rangef::new(20.0, 30.0)));
Trait Implementations§
source§impl<'de> Deserialize<'de> for Rangef
impl<'de> Deserialize<'de> for Rangef
source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Rangef, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Rangef, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Serialize for Rangef
impl Serialize for Rangef
source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Copy for Rangef
impl Pod for Rangef
impl StructuralPartialEq for Rangef
Auto Trait Implementations§
impl Freeze for Rangef
impl RefUnwindSafe for Rangef
impl Send for Rangef
impl Sync for Rangef
impl Unpin for Rangef
impl UnwindSafe for Rangef
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
source§type Bits = T
type Bits = T
Self
must have the same layout as the specified Bits
except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern
.source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
If this function returns true, then it must be valid to reinterpret
bits
as &Self
.source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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