1use serde::{Deserialize, Serialize};
6
7mod matrix;
8mod vector;
9
10#[cfg(test)]
11#[path = "types_tests.rs"]
12mod tests;
13
14pub use matrix::{Mat3, Mat4, Quat};
15pub use vector::{Vec2, Vec3, Vec4};
16
17#[repr(C)]
21#[derive(
22 Clone,
23 Copy,
24 PartialEq,
25 Eq,
26 Debug,
27 Default,
28 Serialize,
29 Deserialize,
30 bytemuck::Pod,
31 bytemuck::Zeroable,
32)]
33pub struct Rgba8 {
34 pub r: u8,
36 pub g: u8,
38 pub b: u8,
40 pub a: u8,
42}
43
44impl Rgba8 {
45 pub const WHITE: Self = Self::new(255, 255, 255, 255);
47
48 #[must_use]
50 pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self {
51 Self { r, g, b, a }
52 }
53
54 #[must_use]
56 pub const fn opaque(r: u8, g: u8, b: u8) -> Self {
57 Self::new(r, g, b, 255)
58 }
59
60 #[must_use]
62 pub fn to_f32(self) -> [f32; 4] {
63 [
64 f32::from(self.r) / 255.0,
65 f32::from(self.g) / 255.0,
66 f32::from(self.b) / 255.0,
67 f32::from(self.a) / 255.0,
68 ]
69 }
70}