From bbbb85d5ba411cf98f09235fbe03391b4b1bf121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20M=C3=BCller?= Date: Sat, 10 Jun 2023 20:56:50 +0200 Subject: [PATCH] changed width and height in Image struct from usize to u32 --- src/image/mod.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/image/mod.rs b/src/image/mod.rs index 685524b..1fec483 100644 --- a/src/image/mod.rs +++ b/src/image/mod.rs @@ -1,6 +1,6 @@ //! //! This module provides the struct and basic functions to represent images. -//! The image struct has the width and height dimensions of the image in px as usize. +//! The image struct has the width and height dimensions of the image in px as u32. //! The pixels of the image itself are stored in a vector where a tuple with four elements represent the RGBA values of a pixel. //! //! A pixel is a tuple with four elements where the elements are RGBA. For convenience the tuple is as an generic Datatype specified @@ -42,9 +42,9 @@ where T: Into + PartialEq + Default + Copy + From + PartialOrd, { ///the width of the Picture in px - width: usize, + width: u32, ///the height of the Picture in px - height: usize, + height: u32, ///the raw RGBA data of the Picture where the RGBA values of an pixel is one tuple pixels: Vec<(T, T, T, T)>, ///the absolute path where the picture is located @@ -58,8 +58,8 @@ where { ///gives an Image with specified values if the Vec matches the width times the height of the Image /// if the width and height dont make sense for the Image then will this function panic. - pub fn new(width: usize, height: usize, pixels: Vec<(T, T, T, T)>, path: PathBuf) -> Self { - if width * height != pixels.len() { + pub fn new(width: u32, height: u32, pixels: Vec<(T, T, T, T)>, path: PathBuf) -> Self { + if width * height != pixels.len() as u32 { panic!("The Image does not have the same number of pixel as width and height implies") } else { Self { @@ -72,11 +72,11 @@ where } /// Returns the width of the image - pub fn width(&self) -> usize { + pub fn width(&self) -> u32 { self.width } /// Returns the height of the image - pub fn height(&self) -> usize { + pub fn height(&self) -> u32 { self.height } /// Returns a specified pixel of the image