diff --git a/src/funs/extent.rs b/src/funs/extent.rs index 00dcb7f..9f3251e 100644 --- a/src/funs/extent.rs +++ b/src/funs/extent.rs @@ -126,6 +126,8 @@ pub trait Clamp { pure fn clamp(mn: &self, mx: &self) -> self; } +#[inline(always)] pub pure fn clamp(x: &T, mn: &T, mx: &T) -> T { x.clamp(mn, mx) } + pub impl u8: Clamp { #[inline(always)] pure fn clamp(mn: &u8, mx: &u8) -> u8 { min(&max(&self, mn), mx) } } pub impl u16: Clamp { #[inline(always)] pure fn clamp(mn: &u16, mx: &u16) -> u16 { min(&max(&self, mn), mx) } } pub impl u32: Clamp { #[inline(always)] pure fn clamp(mn: &u32, mx: &u32) -> u32 { min(&max(&self, mn), mx) } } @@ -140,52 +142,26 @@ pub impl f32: Clamp { #[inline(always)] pure fn clamp(mn: &f32, mx: &f32) pub impl f64: Clamp { #[inline(always)] pure fn clamp(mn: &f64, mx: &f64) -> f64 { min(&max(&self, mn), mx) } } pub impl float: Clamp { #[inline(always)] pure fn clamp(mn: &float, mx: &float) -> float { min(&max(&self, mn), mx) } } -pub trait ClampV { - pure fn clamp(mn: &T, mx: &T) -> self; - pure fn clamp_v(mn: &self, mx: &self) -> self; -} - -pub impl Vec2: ClampV { +pub impl Vec2: Clamp { #[inline(always)] - pure fn clamp(mn: &T, mx: &T) -> Vec2 { - Vec2::new(self[0].clamp(mn, mx), - self[1].clamp(mn, mx)) - } - - #[inline(always)] - pure fn clamp_v(mn: &Vec2, mx: &Vec2) -> Vec2 { + pure fn clamp(mn: &Vec2, mx: &Vec2) -> Vec2 { Vec2::new(self[0].clamp(&mn[0], &mx[0]), self[1].clamp(&mn[1], &mx[1])) } } -pub impl Vec3: ClampV { +pub impl Vec3: Clamp { #[inline(always)] - pure fn clamp(mn: &T, mx: &T) -> Vec3 { - Vec3::new(self[0].clamp(mn, mx), - self[1].clamp(mn, mx), - self[2].clamp(mn, mx)) - } - - #[inline(always)] - pure fn clamp_v(mn: &Vec3, mx: &Vec3) -> Vec3 { + pure fn clamp(mn: &Vec3, mx: &Vec3) -> Vec3 { Vec3::new(self[0].clamp(&mn[0], &mx[0]), self[1].clamp(&mn[1], &mx[1]), self[2].clamp(&mn[2], &mx[2])) } } -pub impl Vec4: ClampV { +pub impl Vec4: Clamp { #[inline(always)] - pure fn clamp(mn: &T, mx: &T) -> Vec4 { - Vec4::new(self[0].clamp(mn, mx), - self[1].clamp(mn, mx), - self[2].clamp(mn, mx), - self[3].clamp(mn, mx)) - } - - #[inline(always)] - pure fn clamp_v(mn: &Vec4, mx: &Vec4) -> Vec4 { + pure fn clamp(mn: &Vec4, mx: &Vec4) -> Vec4 { Vec4::new(self[0].clamp(&mn[0], &mx[0]), self[1].clamp(&mn[1], &mx[1]), self[2].clamp(&mn[2], &mx[2]), diff --git a/src/funs/mix.rs b/src/funs/mix.rs index 6e94580..6af376e 100644 --- a/src/funs/mix.rs +++ b/src/funs/mix.rs @@ -5,6 +5,8 @@ pub trait Mix { pure fn mix(other: &self, value: &self) -> self; } +#[inline(always)] pub pure fn mix(a: &T, b: &T, value: &T) -> T { a.mix(b, value) } + pub impl f32: Mix { #[inline(always)] pure fn mix(other: &f32, value: &f32) -> f32 { @@ -26,54 +28,26 @@ pub impl float: Mix { } } - - -pub trait MixV { - pure fn mix(other: &self, value: &T) -> self; - pure fn mix_v(other: &self, values: &self) -> self; -} - -pub impl Vec2: MixV { +pub impl Vec2: Mix { #[inline(always)] - pure fn mix(other: &Vec2, value: &T) -> Vec2 { - Vec2::new(self[0].mix(&other[0], value), - self[1].mix(&other[1], value)) - } - - #[inline(always)] - pure fn mix_v(other: &Vec2, values: &Vec2) -> Vec2 { + pure fn mix(other: &Vec2, values: &Vec2) -> Vec2 { Vec2::new(self[0].mix(&other[0], &values[0]), self[1].mix(&other[1], &values[1])) } } -pub impl Vec3: MixV { +pub impl Vec3: Mix { #[inline(always)] - pure fn mix(other: &Vec3, value: &T) -> Vec3 { - Vec3::new(self[0].mix(&other[0], value), - self[1].mix(&other[1], value), - self[2].mix(&other[2], value)) - } - - #[inline(always)] - pure fn mix_v(other: &Vec3, values: &Vec3) -> Vec3 { + pure fn mix(other: &Vec3, values: &Vec3) -> Vec3 { Vec3::new(self[0].mix(&other[0], &values[0]), self[1].mix(&other[1], &values[1]), self[2].mix(&other[2], &values[2])) } } -pub impl Vec4: MixV { +pub impl Vec4: Mix { #[inline(always)] - pure fn mix(other: &Vec4, value: &T) -> Vec4 { - Vec4::new(self[0].mix(&other[0], value), - self[1].mix(&other[1], value), - self[2].mix(&other[2], value), - self[3].mix(&other[3], value)) - } - - #[inline(always)] - pure fn mix_v(other: &Vec4, values: &Vec4) -> Vec4 { + pure fn mix(other: &Vec4, values: &Vec4) -> Vec4 { Vec4::new(self[0].mix(&other[0], &values[0]), self[1].mix(&other[1], &values[1]), self[2].mix(&other[2], &values[2]),