[][src]Trait psyche_utils::grid::GridSampleZeroValue

pub trait GridSampleZeroValue<T> {
    fn sample_zero_value() -> T;
}

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

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));
Loading content...

Implementations on Foreign Types

impl GridSampleZeroValue<f32> for f32[src]

impl GridSampleZeroValue<f64> for f64[src]

Loading content...

Implementors

Loading content...