gemini_engine/primitives/
pixel.rs

1use crate::{
2    containers::CanCollide,
3    core::{CanDraw, ColChar, Vec2D},
4};
5
6/// A singular point with a [`Vec2D`] position and [`ColChar`]
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub struct Pixel {
9    /// The position of the `Pixel`
10    pub pos: Vec2D,
11    /// The appearance/colour of the `Pixel`
12    pub fill_char: ColChar,
13}
14
15impl Pixel {
16    /// Create a new `Pixel`
17    #[must_use]
18    pub const fn new(pos: Vec2D, fill_char: ColChar) -> Self {
19        Self { pos, fill_char }
20    }
21}
22
23impl CanDraw for Pixel {
24    fn draw_to(&self, canvas: &mut impl crate::core::Canvas) {
25        canvas.plot(self.pos, self.fill_char);
26    }
27}
28
29impl CanCollide for Pixel {
30    fn collides_with_pos(&self, pos: Vec2D) -> bool {
31        self.pos == pos
32    }
33}