diff options
Diffstat (limited to 'engine/src/data_types')
| -rw-r--r-- | engine/src/data_types/color.rs | 1 | ||||
| -rw-r--r-- | engine/src/data_types/dimens.rs | 54 | ||||
| -rw-r--r-- | engine/src/data_types/matrix.rs | 2 | ||||
| -rw-r--r-- | engine/src/data_types/vector.rs | 24 |
4 files changed, 78 insertions, 3 deletions
diff --git a/engine/src/data_types/color.rs b/engine/src/data_types/color.rs index cef3b92..c5316e6 100644 --- a/engine/src/data_types/color.rs +++ b/engine/src/data_types/color.rs @@ -1,7 +1,6 @@ use std::ops::{Add, Div, Mul, Neg, Sub}; #[derive(Debug, Clone, Default)] -#[repr(C)] pub struct Color<Value> { pub red: Value, diff --git a/engine/src/data_types/dimens.rs b/engine/src/data_types/dimens.rs index 5002436..8bf239f 100644 --- a/engine/src/data_types/dimens.rs +++ b/engine/src/data_types/dimens.rs @@ -1,3 +1,5 @@ +use std::num::NonZeroU32; + /// 2D dimensions. #[derive(Debug, Clone, Copy)] pub struct Dimens<Value> @@ -6,6 +8,34 @@ pub struct Dimens<Value> pub height: Value, } +impl<Value: Clone> From<Value> for Dimens<Value> +{ + fn from(value: Value) -> Self + { + Self { width: value.clone(), height: value } + } +} + +impl<Value> From<(Value, Value)> for Dimens<Value> +{ + fn from(value: (Value, Value)) -> Self + { + Self { width: value.0, height: value.1 } + } +} + +impl Dimens<u32> +{ + #[must_use] + pub fn try_into_nonzero(self) -> Option<Dimens<NonZeroU32>> + { + Some(Dimens { + width: NonZeroU32::new(self.width)?, + height: NonZeroU32::new(self.height)?, + }) + } +} + /// 3D dimensions. #[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] pub struct Dimens3<Value> @@ -14,3 +44,27 @@ pub struct Dimens3<Value> pub height: Value, pub depth: Value, } + +impl<Value: Clone> From<Value> for Dimens3<Value> +{ + fn from(value: Value) -> Self + { + Self { + width: value.clone(), + height: value.clone(), + depth: value, + } + } +} + +impl<Value: Clone> From<(Value, Value, Value)> for Dimens3<Value> +{ + fn from(value: (Value, Value, Value)) -> Self + { + Self { + width: value.0, + height: value.1, + depth: value.2, + } + } +} diff --git a/engine/src/data_types/matrix.rs b/engine/src/data_types/matrix.rs index 3a29ae2..b754b62 100644 --- a/engine/src/data_types/matrix.rs +++ b/engine/src/data_types/matrix.rs @@ -4,7 +4,7 @@ use crate::vector::Vec3; pub struct Matrix<Value, const ROWS: usize, const COLUMNS: usize> { /// Items must be layed out this way for it to work with OpenGL shaders. - items: [[Value; ROWS]; COLUMNS], + pub items: [[Value; ROWS]; COLUMNS], } impl<Value, const ROWS: usize, const COLUMNS: usize> Matrix<Value, ROWS, COLUMNS> diff --git a/engine/src/data_types/vector.rs b/engine/src/data_types/vector.rs index 802a4a7..dc6df30 100644 --- a/engine/src/data_types/vector.rs +++ b/engine/src/data_types/vector.rs @@ -14,6 +14,29 @@ impl Vec2<u32> pub const ZERO: Self = Self { x: 0, y: 0 }; } +impl<Value> Add for Vec2<Value> +where + Value: Add<Value, Output = Value>, +{ + type Output = Self; + + fn add(self, rhs: Self) -> Self::Output + { + Self::Output { x: self.x + rhs.x, y: self.y + rhs.y } + } +} + +impl<Value> AddAssign for Vec2<Value> +where + Value: Add<Value, Output = Value> + Clone, +{ + fn add_assign(&mut self, rhs: Self) + { + self.x = self.x.clone() + rhs.x; + self.y = self.y.clone() + rhs.y; + } +} + impl<Value> Add<Value> for Vec2<Value> where Value: Add<Output = Value> + Clone, @@ -75,7 +98,6 @@ where } #[derive(Debug, Default, Clone, Copy, PartialEq)] -#[repr(C)] pub struct Vec3<Value> { pub x: Value, |
