use crate::calculus::calculus::Point3; // "Ideal" aspect ratio, allowing fraction pub const ASPECT_RATIO: f32 = 9.0f32 / 5.0f32; pub const IMG_WIDTH: usize = 400; const IMG_HEIGHT_TMP: usize = (IMG_WIDTH as f32 / ASPECT_RATIO) as usize; pub const IMG_HEIGHT: usize = if (IMG_HEIGHT_TMP < 1) { 1 } else { IMG_HEIGHT_TMP }; pub const VIEWPORT_HEIGHT: usize = 2; pub const VIEWPORT_WIDTH: usize = VIEWPORT_HEIGHT * (IMG_WIDTH / IMG_HEIGHT); pub const FOCAL_LENGTH: f32 = 2.0; pub const CAMERA_CENTER: Point3 = Point3 { x: 0f32, y: 0f32, z: 0f32 }; #[derive(Debug, Copy, Clone)] pub struct Pixel { pub r: u8, pub g: u8, pub b: u8, } impl Pixel { pub fn from_frac(r: f32, g: f32, b: f32) -> Self { Self { r: (255.999 * r) as u8, g: (255.999 * g) as u8, b: (255.999 * b) as u8, } } } impl Default for Pixel { fn default() -> Self { Pixel { r:0, g:0, b:0 } } } pub type DisplayBuffer = [[Pixel; IMG_WIDTH]; IMG_HEIGHT];