Trait GridSampleZeroValue

Source
pub trait GridSampleZeroValue<T> {
    // Required method
    fn sample_zero_value() -> T;
}
Expand description

Trait used to obtain zero value for given type. It is used by built-in samplers and it’s implemented for f32 and f64 types so if you want to sample any other type of grid, you have implement this trait for that type.

Required Methods§

Source

fn sample_zero_value() -> T

produce zero value for given type.

§Return

Zero value of given type.

§Example
use psyche_utils::grid::{Grid, GridSamplerCluster, GridSampleZeroValue};
use std::ops::Add;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
struct Integer(pub i32);

impl Add for Integer {
    type Output = Integer;
    fn add(self, other: Integer) -> Integer { Integer(self.0 + other.0) }
}

impl GridSampleZeroValue<Self> for Integer {
    fn sample_zero_value() -> Self { Integer(0) }
}

let grid = Grid::new(2, 2, Integer(1));
let sampler = GridSamplerCluster::new((0, 0), (1, 1));
assert_eq!(grid.sample(sampler).unwrap(), (Integer(4), 4));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl GridSampleZeroValue<f32> for f32

Source§

impl GridSampleZeroValue<f64> for f64

Implementors§