Created
July 29, 2020 15:49
-
-
Save richardpringle/7d5e9004fdf7cde30392331ae63bb0f2 to your computer and use it in GitHub Desktop.
Ray Tracer Scalar Division and Multiplication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl<T: Mul<Output = T> + Copy> Mul<T> for Tuple<T> { | |
type Output = Self; | |
fn mul(self, rhs: T) -> Self::Output { | |
let Self(x, y, z, w) = self; | |
Self(x * rhs, y * rhs, z * rhs, w * rhs) | |
} | |
} | |
impl<T: Div<Output = T> + Copy> Div<T> for Tuple<T> { | |
type Output = Self; | |
fn div(self, rhs: T) -> Self::Output { | |
let Self(x, y, z, w) = self; | |
Self(x / rhs, y / rhs, z / rhs, w / rhs) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I reverse the order for multiplication?
impl<T: Mul<Output = T> + Copy> Mul<Tuple<T>> for T { // ...