MipMap1D

Struct MipMap1D 

Source
pub struct MipMap1D<T: Num + ToPrimitive + FromPrimitive> { /* private fields */ }
Expand description

Creates several downsampled versions of given vector. This data structure takes 2x space of original data. Example:

use mipmap_1d::MipMap1D;

let data = vec![2, 4, 6, 8, 9];
let mipmap = MipMap1D::new(data);
assert_eq!(mipmap.num_levels(), 4);
assert_eq!(*mipmap.get_level(0).unwrap(), [2, 4, 6, 8, 9]);
assert_eq!(*mipmap.get_level(1).unwrap(), [3, 7, 9]);
assert_eq!(*mipmap.get_level(2).unwrap(), [5, 9]);
assert_eq!(*mipmap.get_level(3).unwrap(), [7]);
assert_eq!(mipmap.get_level(4), None);

Implementations§

Source§

impl<T: Num + ToPrimitive + FromPrimitive + Copy> MipMap1D<T>

Source

pub fn new(source: Vec<T>) -> Self

Source

pub fn num_levels(&self) -> usize

Returns the total number of downsampled levels. Equal to ceil(log2(source.len())

Source

pub fn get_level(&self, level: usize) -> Option<&Vec<T>>

Returns the data on given level. Level 0 returns the source data; the higher the level, the higher the compression (i.e. smaller vectors are returned). If the level is out of bounds, returns None

Trait Implementations§

Source§

impl<T: Debug + Num + ToPrimitive + FromPrimitive> Debug for MipMap1D<T>

Source§

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

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

impl<T: Default + Num + ToPrimitive + FromPrimitive> Default for MipMap1D<T>

Source§

fn default() -> MipMap1D<T>

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

impl<T: PartialEq + Num + ToPrimitive + FromPrimitive> PartialEq for MipMap1D<T>

Source§

fn eq(&self, other: &MipMap1D<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: Eq + Num + ToPrimitive + FromPrimitive> Eq for MipMap1D<T>

Source§

impl<T: Num + ToPrimitive + FromPrimitive> StructuralPartialEq for MipMap1D<T>

Auto Trait Implementations§

§

impl<T> Freeze for MipMap1D<T>

§

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

§

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

§

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

§

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

§

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