1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! Turn positive Float values into binary `1u8`, and negative into `0u8`.
use anyhow::Result;

use crate::stream::{new_streamp, Streamp};
use crate::{map_block_convert_macro, Float};

/// Turn positive Float values into binary `1u8`, and negative into `0u8`.
pub struct BinarySlicer {
    src: Streamp<Float>,
    dst: Streamp<u8>,
}

impl BinarySlicer {
    /// Create new binary slicer.
    pub fn new(src: Streamp<Float>) -> Self {
        Self {
            src,
            dst: new_streamp(),
        }
    }

    fn process_one(&self, a: Float) -> u8 {
        if a > 0.0 {
            1
        } else {
            0
        }
    }
}

map_block_convert_macro![BinarySlicer, u8];