veloren/common/src/figure/cell.rs

39 lines
677 B
Rust
Raw Normal View History

// Library
use vek::*;
2019-01-14 18:49:53 +00:00
// Crate
use crate::vol::Vox;
/// A type representing a single voxel in a figure
#[derive(Copy, Clone, Debug)]
pub enum Cell {
Filled([u8; 3]),
Empty,
}
impl Cell {
pub fn new(rgb: Rgb<u8>) -> Self {
Cell::Filled(rgb.into_array())
}
2019-01-14 18:49:53 +00:00
pub fn get_color(&self) -> Option<Rgb<u8>> {
match self {
2019-01-14 18:49:53 +00:00
Cell::Filled(col) => Some(Rgb::from(*col)),
Cell::Empty => None,
}
}
2019-01-14 18:49:53 +00:00
}
2019-01-14 18:49:53 +00:00
impl Vox for Cell {
fn empty() -> Self {
Cell::Empty
}
fn is_empty(&self) -> bool {
match self {
2019-01-14 18:49:53 +00:00
Cell::Filled(_) => false,
Cell::Empty => true,
}
}
}