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
32
33
34
35
36
37
38
39
40
41
42
43
use super::ViewElement;

pub mod colchar;
pub mod vec2d;

use colchar::ColChar;
use vec2d::Vec2D;

/// Old name for [`Pixel`], this is now deprecated
#[deprecated = "Renamed to Pixel, please use that instead"]
pub type Point = Pixel;

/// The `Pixel` holds a single [`Vec2D`] (the coordinates at which it is printed when blit to a [`View`](super::View)) and a [`ColChar`]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Pixel {
    /// The position of the `Pixel`
    pub pos: Vec2D,
    /// The appearance/colour of the `Pixel`
    pub fill_char: ColChar,
}

impl Pixel {
    /// Create a new `Pixel` from a [`Vec2D`] and [`ColChar`]
    #[must_use]
    pub const fn new(pos: Vec2D, fill_char: ColChar) -> Self {
        Self { pos, fill_char }
    }
}

impl From<(Vec2D, ColChar)> for Pixel {
    fn from(value: (Vec2D, ColChar)) -> Self {
        Self {
            pos: value.0,
            fill_char: value.1,
        }
    }
}

impl ViewElement for Pixel {
    fn active_pixels(&self) -> Vec<Pixel> {
        vec![*self]
    }
}