BlockiesHelper

Trait BlockiesHelper 

Source
pub trait BlockiesHelper<const S: usize, T: Clone> {
    const SIZE: usize = S;

    // Required methods
    fn flatten(self) -> Vec<T>;
    fn scale(self, output_dim: (usize, usize)) -> Vec<Vec<T>>;
}
Expand description

Additional helper functions for generated Blockies objects

Provided Associated Constants§

Source

const SIZE: usize = S

Size of Blockies

Same as const S value (const generic)

Required Methods§

Source

fn flatten(self) -> Vec<T>

Flatten Blockies 2D data to 1D vector

§Return
  • 1D vector of T
§Example
use eth_blockies::{Blockies, BlockiesHelper};

// original data (2d)
let blockies_data_2d: Blockies<4, usize>  = [
        [ 11, 12, 13, 14, ],
        [ 21, 22, 23, 24, ],
        [ 31, 32, 33, 34, ],
        [ 41, 42, 43, 44, ],
    ];

// flatten data to 1d array
let blockies_data_1d: Vec<usize> =
    blockies_data_2d.flatten();

assert_eq!(blockies_data_1d, vec![
    11, 12, 13, 14, 21, 22, 23, 24,
    31, 32, 33, 34, 41, 42, 43, 44,
]);
Source

fn scale(self, output_dim: (usize, usize)) -> Vec<Vec<T>>

Scale Blockies data to given dimension

  • Note that this function does not perform any kind of pixel blending at edges.
    Therefore, lower dimension may generate unbalanced image,
    only if both (width, height) are not multiples of SIZE.
§Arguments
  • output_dim - Width and height of output after scaling
§Return
  • 2D vector of T
§Example
use eth_blockies::{Blockies, BlockiesHelper};

// original data (2d)
let blockies_data_4x4: Blockies<4, usize> = [
        [ 11, 12, 13, 14, ],
        [ 21, 22, 23, 24, ],
        [ 31, 32, 33, 34, ],
        [ 41, 42, 43, 44, ],
    ];

// scale: 4x4 -> 8x8
let blockies_data_8x8: Vec<Vec<usize>> =
    blockies_data_4x4.scale((8, 8));

assert_eq!(blockies_data_8x8, vec![
        vec![ 11, 11, 12, 12, 13, 13, 14, 14, ],
        vec![ 11, 11, 12, 12, 13, 13, 14, 14, ],
        vec![ 21, 21, 22, 22, 23, 23, 24, 24, ],
        vec![ 21, 21, 22, 22, 23, 23, 24, 24, ],
        vec![ 31, 31, 32, 32, 33, 33, 34, 34, ],
        vec![ 31, 31, 32, 32, 33, 33, 34, 34, ],
        vec![ 41, 41, 42, 42, 43, 43, 44, 44, ],
        vec![ 41, 41, 42, 42, 43, 43, 44, 44, ],
]);

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.

Implementors§

Source§

impl<T: Clone, const S: usize> BlockiesHelper<S, T> for Blockies<S, T>