spans now good (other than direction) + refactor

This commit is contained in:
2025-08-11 02:24:27 -04:00
parent 132113f09e
commit 95a07786bb
22 changed files with 545 additions and 371 deletions

59
src/layout/vec2.rs Normal file
View File

@@ -0,0 +1,59 @@
use crate::util::{F32Util, impl_op};
use std::ops::*;
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Default, bytemuck::Pod, bytemuck::Zeroable)]
pub struct Vec2 {
pub x: f32,
pub y: f32,
}
pub const fn vec2(x: f32, y: f32) -> Vec2 {
Vec2::new(x, y)
}
impl Vec2 {
pub const ZERO: Self = Self::new(0.0, 0.0);
pub const ONE: Self = Self::new(1.0, 1.0);
pub const fn new(x: f32, y: f32) -> Self {
Self { x, y }
}
pub const fn lerp(self, from: impl const Into<Self>, to: impl const Into<Self>) -> Self {
let from = from.into();
let to = to.into();
Self {
x: self.x.lerp(from.x, to.x),
y: self.y.lerp(from.y, to.y),
}
}
}
impl const From<f32> for Vec2 {
fn from(v: f32) -> Self {
Self { x: v, y: v }
}
}
// this version looks kinda cool... is it more readable? more annoying to copy and change though
impl_op!(impl Add for Vec2: add x y);
impl_op!(Vec2 Sub sub; x y);
impl_op!(Vec2 Mul mul; x y);
impl_op!(Vec2 Div div; x y);
impl Neg for Vec2 {
type Output = Self;
fn neg(mut self) -> Self::Output {
self.x = -self.x;
self.y = -self.y;
self
}
}
impl From<(f32, f32)> for Vec2 {
fn from((x, y): (f32, f32)) -> Self {
Self { x, y }
}
}