make width and height private to make it read only

This commit is contained in:
Vinzenz Schroeter 2024-05-17 18:43:39 +02:00
parent ab66a6a33e
commit 5a717beda5
4 changed files with 37 additions and 21 deletions

View file

@ -1,10 +1,8 @@
/// A 2D grid of bytes
#[derive(Debug, Clone, PartialEq)]
pub struct ByteGrid {
/// Size in the x-axis
pub width: usize,
/// Size in the y-axis
pub height: usize,
width: usize,
height: usize,
data: Vec<u8>,
}
@ -57,6 +55,16 @@ impl ByteGrid {
pub fn mut_data_ref(&mut self) -> &mut [u8] {
self.data.as_mut_slice()
}
/// the size in x-direction
pub fn width(&self) -> usize {
self.width
}
/// the height in y-direction
pub fn height(&self) -> usize {
self.height
}
}
impl From<ByteGrid> for Vec<u8> {

View file

@ -74,8 +74,8 @@ impl From<Command> for Packet {
CommandCode::CharBrightness.into(),
x,
y,
grid.width as u16,
grid.height as u16,
grid.width() as u16,
grid.height() as u16,
),
grid.into(),
),
@ -95,11 +95,11 @@ impl From<Command> for Packet {
compression,
) => {
debug_assert_eq!(pixel_x % 8, 0);
debug_assert_eq!(pixels.width % 8, 0);
debug_assert_eq!(pixels.width() % 8, 0);
let tile_x = pixel_x / TILE_SIZE;
let tile_w = pixels.width as u16 / TILE_SIZE;
let pixel_h = pixels.height as u16;
let tile_w = pixels.width() as u16 / TILE_SIZE;
let pixel_h = pixels.height() as u16;
let payload = into_compressed(compression, pixels.into());
let command = match compression {
CompressionCode::Uncompressed => {
@ -153,8 +153,8 @@ impl From<Command> for Packet {
CommandCode::Cp437Data.into(),
x,
y,
grid.width as u16,
grid.height as u16,
grid.width() as u16,
grid.height() as u16,
),
grid.into(),
),

View file

@ -3,10 +3,8 @@ use crate::{BitVec, PIXEL_HEIGHT, PIXEL_WIDTH};
/// A grid of pixels stored in packed bytes.
#[derive(Debug, Clone, PartialEq)]
pub struct PixelGrid {
/// the width in pixels
pub width: usize,
/// the height in pixels
pub height: usize,
width: usize,
height: usize,
bit_vec: BitVec,
}
@ -80,6 +78,16 @@ impl PixelGrid {
pub fn mut_data_ref(&mut self) -> &mut [u8] {
self.bit_vec.mut_data_ref()
}
/// the size in x-direction in pixels
pub fn width(&self) -> usize {
self.width
}
/// the height in y-direction in pixels
pub fn height(&self) -> usize {
self.height
}
}
impl From<PixelGrid> for Vec<u8> {