diff --git a/crates/comet_math/src/vector.rs b/crates/comet_math/src/vector.rs index 494e57b..fcda70a 100644 --- a/crates/comet_math/src/vector.rs +++ b/crates/comet_math/src/vector.rs @@ -62,34 +62,6 @@ impl Vec2 { y: factor * self.y, } } - - pub fn xx(&self) -> Vec2 { - Vec2 { - x: self.x, - y: self.x, - } - } - - pub fn xy(&self) -> Vec2 { - Vec2 { - x: self.x, - y: self.y, - } - } - - pub fn yx(&self) -> Vec2 { - Vec2 { - x: self.y, - y: self.x, - } - } - - pub fn yy(&self) -> Vec2 { - Vec2 { - x: self.y, - y: self.y, - } - } } impl Add for Vec2 { @@ -451,196 +423,6 @@ impl Vec3 { z: factor * self.z, } } - - pub fn xxx(&self) -> Vec3 { - Vec3 { - x: self.x, - y: self.x, - z: self.x, - } - } - pub fn xxy(&self) -> Vec3 { - Vec3 { - x: self.x, - y: self.x, - z: self.y, - } - } - pub fn xxz(&self) -> Vec3 { - Vec3 { - x: self.x, - y: self.x, - z: self.z, - } - } - pub fn xyx(&self) -> Vec3 { - Vec3 { - x: self.x, - y: self.y, - z: self.x, - } - } - pub fn xyy(&self) -> Vec3 { - Vec3 { - x: self.x, - y: self.y, - z: self.y, - } - } - pub fn xyz(&self) -> Vec3 { - Vec3 { - x: self.x, - y: self.y, - z: self.z, - } - } - pub fn xzx(&self) -> Vec3 { - Vec3 { - x: self.x, - y: self.z, - z: self.x, - } - } - pub fn xzy(&self) -> Vec3 { - Vec3 { - x: self.x, - y: self.z, - z: self.y, - } - } - pub fn xzz(&self) -> Vec3 { - Vec3 { - x: self.x, - y: self.z, - z: self.z, - } - } - pub fn yxx(&self) -> Vec3 { - Vec3 { - x: self.y, - y: self.x, - z: self.x, - } - } - pub fn yxy(&self) -> Vec3 { - Vec3 { - x: self.y, - y: self.x, - z: self.y, - } - } - pub fn yxz(&self) -> Vec3 { - Vec3 { - x: self.y, - y: self.x, - z: self.z, - } - } - pub fn yyx(&self) -> Vec3 { - Vec3 { - x: self.y, - y: self.y, - z: self.x, - } - } - pub fn yyy(&self) -> Vec3 { - Vec3 { - x: self.y, - y: self.y, - z: self.y, - } - } - pub fn yyz(&self) -> Vec3 { - Vec3 { - x: self.y, - y: self.y, - z: self.z, - } - } - pub fn yzx(&self) -> Vec3 { - Vec3 { - x: self.y, - y: self.z, - z: self.x, - } - } - pub fn yzy(&self) -> Vec3 { - Vec3 { - x: self.y, - y: self.z, - z: self.y, - } - } - pub fn yzz(&self) -> Vec3 { - Vec3 { - x: self.y, - y: self.z, - z: self.z, - } - } - pub fn zxx(&self) -> Vec3 { - Vec3 { - x: self.z, - y: self.x, - z: self.x, - } - } - pub fn zxy(&self) -> Vec3 { - Vec3 { - x: self.z, - y: self.x, - z: self.y, - } - } - pub fn zxz(&self) -> Vec3 { - Vec3 { - x: self.z, - y: self.x, - z: self.z, - } - } - pub fn zyx(&self) -> Vec3 { - Vec3 { - x: self.z, - y: self.y, - z: self.x, - } - } - pub fn zyy(&self) -> Vec3 { - Vec3 { - x: self.z, - y: self.y, - z: self.y, - } - } - pub fn zyz(&self) -> Vec3 { - Vec3 { - x: self.z, - y: self.y, - z: self.z, - } - } - pub fn zzx(&self) -> Vec3 { - Vec3 { - x: self.z, - y: self.z, - z: self.x, - } - } - pub fn zzy(&self) -> Vec3 { - Vec3 { - x: self.z, - y: self.z, - z: self.y, - } - } - pub fn zzz(&self) -> Vec3 { - Vec3 { - x: self.z, - y: self.z, - z: self.z, - } - } } impl Add for Vec3 { @@ -683,6 +465,18 @@ impl SubAssign for Vec3 { } } +impl Neg for Vec3 { + type Output = Vec3; + + fn neg(self) -> Vec3 { + Vec3 { + x: -self.x, + y: -self.y, + z: -self.z, + } + } +} + impl Mul for Vec3 { type Output = Vec3; @@ -987,2055 +781,6 @@ impl Vec4 { pub fn set_w(&mut self, new_w: f32) { self.w = new_w; } - - pub fn xxxx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.x, - w: self.x, - } - } - pub fn xxxy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.x, - w: self.y, - } - } - pub fn xxxz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.x, - w: self.z, - } - } - pub fn xxxw(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.x, - w: self.w, - } - } - pub fn xxyx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.y, - w: self.x, - } - } - pub fn xxyy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.y, - w: self.y, - } - } - pub fn xxyz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.y, - w: self.z, - } - } - pub fn xxyw(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.y, - w: self.w, - } - } - pub fn xxzx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.z, - w: self.x, - } - } - pub fn xxzy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.z, - w: self.y, - } - } - pub fn xxzz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.z, - w: self.z, - } - } - pub fn xxzw(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.z, - w: self.w, - } - } - pub fn xxwx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.w, - w: self.x, - } - } - pub fn xxwy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.w, - w: self.y, - } - } - pub fn xxwz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.w, - w: self.z, - } - } - pub fn xxww(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.x, - z: self.w, - w: self.w, - } - } - pub fn xyxx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.x, - w: self.x, - } - } - pub fn xyxy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.x, - w: self.y, - } - } - pub fn xyxz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.x, - w: self.z, - } - } - pub fn xyxw(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.x, - w: self.w, - } - } - pub fn xyyx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.y, - w: self.x, - } - } - pub fn xyyy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.y, - w: self.y, - } - } - pub fn xyyz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.y, - w: self.z, - } - } - pub fn xyyw(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.y, - w: self.w, - } - } - pub fn xyzx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.z, - w: self.x, - } - } - pub fn xyzy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.z, - w: self.y, - } - } - pub fn xyzz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.z, - w: self.z, - } - } - pub fn xyzw(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.z, - w: self.w, - } - } - pub fn xywx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.w, - w: self.x, - } - } - pub fn xywy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.w, - w: self.y, - } - } - pub fn xywz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.w, - w: self.z, - } - } - pub fn xyww(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.y, - z: self.w, - w: self.w, - } - } - pub fn xzxx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.x, - w: self.x, - } - } - pub fn xzxy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.x, - w: self.y, - } - } - pub fn xzxz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.x, - w: self.z, - } - } - pub fn xzxw(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.x, - w: self.w, - } - } - pub fn xzyx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.y, - w: self.x, - } - } - pub fn xzyy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.y, - w: self.y, - } - } - pub fn xzyz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.y, - w: self.z, - } - } - pub fn xzyw(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.y, - w: self.w, - } - } - pub fn xzzx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.z, - w: self.x, - } - } - pub fn xzzy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.z, - w: self.y, - } - } - pub fn xzzz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.z, - w: self.z, - } - } - pub fn xzzw(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.z, - w: self.w, - } - } - pub fn xzwx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.w, - w: self.x, - } - } - pub fn xzwy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.w, - w: self.y, - } - } - pub fn xzwz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.w, - w: self.z, - } - } - pub fn xzww(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.z, - z: self.w, - w: self.w, - } - } - pub fn xwxx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.x, - w: self.x, - } - } - pub fn xwxy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.x, - w: self.y, - } - } - pub fn xwxz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.x, - w: self.z, - } - } - pub fn xwxw(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.x, - w: self.w, - } - } - pub fn xwyx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.y, - w: self.x, - } - } - pub fn xwyy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.y, - w: self.y, - } - } - pub fn xwyz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.y, - w: self.z, - } - } - pub fn xwyw(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.y, - w: self.w, - } - } - pub fn xwzx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.z, - w: self.x, - } - } - pub fn xwzy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.z, - w: self.y, - } - } - pub fn xwzz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.z, - w: self.z, - } - } - pub fn xwzw(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.z, - w: self.w, - } - } - pub fn xwwx(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.w, - w: self.x, - } - } - pub fn xwwy(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.w, - w: self.y, - } - } - pub fn xwwz(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.w, - w: self.z, - } - } - pub fn xwww(&self) -> Vec4 { - Vec4 { - x: self.x, - y: self.w, - z: self.w, - w: self.w, - } - } - pub fn yxxx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.x, - w: self.x, - } - } - pub fn yxxy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.x, - w: self.y, - } - } - pub fn yxxz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.x, - w: self.z, - } - } - pub fn yxxw(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.x, - w: self.w, - } - } - pub fn yxyx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.y, - w: self.x, - } - } - pub fn yxyy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.y, - w: self.y, - } - } - pub fn yxyz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.y, - w: self.z, - } - } - pub fn yxyw(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.y, - w: self.w, - } - } - pub fn yxzx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.z, - w: self.x, - } - } - pub fn yxzy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.z, - w: self.y, - } - } - pub fn yxzz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.z, - w: self.z, - } - } - pub fn yxzw(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.z, - w: self.w, - } - } - pub fn yxwx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.w, - w: self.x, - } - } - pub fn yxwy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.w, - w: self.y, - } - } - pub fn yxwz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.w, - w: self.z, - } - } - pub fn yxww(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.x, - z: self.w, - w: self.w, - } - } - pub fn yyxx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.x, - w: self.x, - } - } - pub fn yyxy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.x, - w: self.y, - } - } - pub fn yyxz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.x, - w: self.z, - } - } - pub fn yyxw(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.x, - w: self.w, - } - } - pub fn yyyx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.y, - w: self.x, - } - } - pub fn yyyy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.y, - w: self.y, - } - } - pub fn yyyz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.y, - w: self.z, - } - } - pub fn yyyw(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.y, - w: self.w, - } - } - pub fn yyzx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.z, - w: self.x, - } - } - pub fn yyzy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.z, - w: self.y, - } - } - pub fn yyzz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.z, - w: self.z, - } - } - pub fn yyzw(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.z, - w: self.w, - } - } - pub fn yywx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.w, - w: self.x, - } - } - pub fn yywy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.w, - w: self.y, - } - } - pub fn yywz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.w, - w: self.z, - } - } - pub fn yyww(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.y, - z: self.w, - w: self.w, - } - } - pub fn yzxx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.x, - w: self.x, - } - } - pub fn yzxy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.x, - w: self.y, - } - } - pub fn yzxz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.x, - w: self.z, - } - } - pub fn yzxw(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.x, - w: self.w, - } - } - pub fn yzyx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.y, - w: self.x, - } - } - pub fn yzyy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.y, - w: self.y, - } - } - pub fn yzyz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.y, - w: self.z, - } - } - pub fn yzyw(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.y, - w: self.w, - } - } - pub fn yzzx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.z, - w: self.x, - } - } - pub fn yzzy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.z, - w: self.y, - } - } - pub fn yzzz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.z, - w: self.z, - } - } - pub fn yzzw(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.z, - w: self.w, - } - } - pub fn yzwx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.w, - w: self.x, - } - } - pub fn yzwy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.w, - w: self.y, - } - } - pub fn yzwz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.w, - w: self.z, - } - } - pub fn yzww(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.z, - z: self.w, - w: self.w, - } - } - pub fn ywxx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.x, - w: self.x, - } - } - pub fn ywxy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.x, - w: self.y, - } - } - pub fn ywxz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.x, - w: self.z, - } - } - pub fn ywxw(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.x, - w: self.w, - } - } - pub fn ywyx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.y, - w: self.x, - } - } - pub fn ywyy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.y, - w: self.y, - } - } - pub fn ywyz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.y, - w: self.z, - } - } - pub fn ywyw(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.y, - w: self.w, - } - } - pub fn ywzx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.z, - w: self.x, - } - } - pub fn ywzy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.z, - w: self.y, - } - } - pub fn ywzz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.z, - w: self.z, - } - } - pub fn ywzw(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.z, - w: self.w, - } - } - pub fn ywwx(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.w, - w: self.x, - } - } - pub fn ywwy(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.w, - w: self.y, - } - } - pub fn ywwz(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.w, - w: self.z, - } - } - pub fn ywww(&self) -> Vec4 { - Vec4 { - x: self.y, - y: self.w, - z: self.w, - w: self.w, - } - } - pub fn zxxx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.x, - w: self.x, - } - } - pub fn zxxy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.x, - w: self.y, - } - } - pub fn zxxz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.x, - w: self.z, - } - } - pub fn zxxw(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.x, - w: self.w, - } - } - pub fn zxyx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.y, - w: self.x, - } - } - pub fn zxyy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.y, - w: self.y, - } - } - pub fn zxyz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.y, - w: self.z, - } - } - pub fn zxyw(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.y, - w: self.w, - } - } - pub fn zxzx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.z, - w: self.x, - } - } - pub fn zxzy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.z, - w: self.y, - } - } - pub fn zxzz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.z, - w: self.z, - } - } - pub fn zxzw(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.z, - w: self.w, - } - } - pub fn zxwx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.w, - w: self.x, - } - } - pub fn zxwy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.w, - w: self.y, - } - } - pub fn zxwz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.w, - w: self.z, - } - } - pub fn zxww(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.x, - z: self.w, - w: self.w, - } - } - pub fn zyxx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.x, - w: self.x, - } - } - pub fn zyxy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.x, - w: self.y, - } - } - pub fn zyxz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.x, - w: self.z, - } - } - pub fn zyxw(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.x, - w: self.w, - } - } - pub fn zyyx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.y, - w: self.x, - } - } - pub fn zyyy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.y, - w: self.y, - } - } - pub fn zyyz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.y, - w: self.z, - } - } - pub fn zyyw(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.y, - w: self.w, - } - } - pub fn zyzx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.z, - w: self.x, - } - } - pub fn zyzy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.z, - w: self.y, - } - } - pub fn zyzz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.z, - w: self.z, - } - } - pub fn zyzw(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.z, - w: self.w, - } - } - pub fn zywx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.w, - w: self.x, - } - } - pub fn zywy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.w, - w: self.y, - } - } - pub fn zywz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.w, - w: self.z, - } - } - pub fn zyww(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.y, - z: self.w, - w: self.w, - } - } - pub fn zzxx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.x, - w: self.x, - } - } - pub fn zzxy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.x, - w: self.y, - } - } - pub fn zzxz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.x, - w: self.z, - } - } - pub fn zzxw(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.x, - w: self.w, - } - } - pub fn zzyx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.y, - w: self.x, - } - } - pub fn zzyy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.y, - w: self.y, - } - } - pub fn zzyz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.y, - w: self.z, - } - } - pub fn zzyw(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.y, - w: self.w, - } - } - pub fn zzzx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.z, - w: self.x, - } - } - pub fn zzzy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.z, - w: self.y, - } - } - pub fn zzzz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.z, - w: self.z, - } - } - pub fn zzzw(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.z, - w: self.w, - } - } - pub fn zzwx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.w, - w: self.x, - } - } - pub fn zzwy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.w, - w: self.y, - } - } - pub fn zzwz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.w, - w: self.z, - } - } - pub fn zzww(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.z, - z: self.w, - w: self.w, - } - } - pub fn zwxx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.x, - w: self.x, - } - } - pub fn zwxy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.x, - w: self.y, - } - } - pub fn zwxz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.x, - w: self.z, - } - } - pub fn zwxw(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.x, - w: self.w, - } - } - pub fn zwyx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.y, - w: self.x, - } - } - pub fn zwyy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.y, - w: self.y, - } - } - pub fn zwyz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.y, - w: self.z, - } - } - pub fn zwyw(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.y, - w: self.w, - } - } - pub fn zwzx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.z, - w: self.x, - } - } - pub fn zwzy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.z, - w: self.y, - } - } - pub fn zwzz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.z, - w: self.z, - } - } - pub fn zwzw(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.z, - w: self.w, - } - } - pub fn zwwx(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.w, - w: self.x, - } - } - pub fn zwwy(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.w, - w: self.y, - } - } - pub fn zwwz(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.w, - w: self.z, - } - } - pub fn zwww(&self) -> Vec4 { - Vec4 { - x: self.z, - y: self.w, - z: self.w, - w: self.w, - } - } - pub fn wxxx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.x, - w: self.x, - } - } - pub fn wxxy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.x, - w: self.y, - } - } - pub fn wxxz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.x, - w: self.z, - } - } - pub fn wxxw(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.x, - w: self.w, - } - } - pub fn wxyx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.y, - w: self.x, - } - } - pub fn wxyy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.y, - w: self.y, - } - } - pub fn wxyz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.y, - w: self.z, - } - } - pub fn wxyw(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.y, - w: self.w, - } - } - pub fn wxzx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.z, - w: self.x, - } - } - pub fn wxzy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.z, - w: self.y, - } - } - pub fn wxzz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.z, - w: self.z, - } - } - pub fn wxzw(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.z, - w: self.w, - } - } - pub fn wxwx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.w, - w: self.x, - } - } - pub fn wxwy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.w, - w: self.y, - } - } - pub fn wxwz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.w, - w: self.z, - } - } - pub fn wxww(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.x, - z: self.w, - w: self.w, - } - } - pub fn wyxx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.x, - w: self.x, - } - } - pub fn wyxy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.x, - w: self.y, - } - } - pub fn wyxz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.x, - w: self.z, - } - } - pub fn wyxw(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.x, - w: self.w, - } - } - pub fn wyyx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.y, - w: self.x, - } - } - pub fn wyyy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.y, - w: self.y, - } - } - pub fn wyyz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.y, - w: self.z, - } - } - pub fn wyyw(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.y, - w: self.w, - } - } - pub fn wyzx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.z, - w: self.x, - } - } - pub fn wyzy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.z, - w: self.y, - } - } - pub fn wyzz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.z, - w: self.z, - } - } - pub fn wyzw(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.z, - w: self.w, - } - } - pub fn wywx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.w, - w: self.x, - } - } - pub fn wywy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.w, - w: self.y, - } - } - pub fn wywz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.w, - w: self.z, - } - } - pub fn wyww(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.y, - z: self.w, - w: self.w, - } - } - pub fn wzxx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.x, - w: self.x, - } - } - pub fn wzxy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.x, - w: self.y, - } - } - pub fn wzxz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.x, - w: self.z, - } - } - pub fn wzxw(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.x, - w: self.w, - } - } - pub fn wzyx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.y, - w: self.x, - } - } - pub fn wzyy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.y, - w: self.y, - } - } - pub fn wzyz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.y, - w: self.z, - } - } - pub fn wzyw(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.y, - w: self.w, - } - } - pub fn wzzx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.z, - w: self.x, - } - } - pub fn wzzy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.z, - w: self.y, - } - } - pub fn wzzz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.z, - w: self.z, - } - } - pub fn wzzw(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.z, - w: self.w, - } - } - pub fn wzwx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.w, - w: self.x, - } - } - pub fn wzwy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.w, - w: self.y, - } - } - pub fn wzwz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.w, - w: self.z, - } - } - pub fn wzww(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.z, - z: self.w, - w: self.w, - } - } - pub fn wwxx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.x, - w: self.x, - } - } - pub fn wwxy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.x, - w: self.y, - } - } - pub fn wwxz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.x, - w: self.z, - } - } - pub fn wwxw(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.x, - w: self.w, - } - } - pub fn wwyx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.y, - w: self.x, - } - } - pub fn wwyy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.y, - w: self.y, - } - } - pub fn wwyz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.y, - w: self.z, - } - } - pub fn wwyw(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.y, - w: self.w, - } - } - pub fn wwzx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.z, - w: self.x, - } - } - pub fn wwzy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.z, - w: self.y, - } - } - pub fn wwzz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.z, - w: self.z, - } - } - pub fn wwzw(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.z, - w: self.w, - } - } - pub fn wwwx(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.w, - w: self.x, - } - } - pub fn wwwy(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.w, - w: self.y, - } - } - pub fn wwwz(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.w, - w: self.z, - } - } - pub fn wwww(&self) -> Vec4 { - Vec4 { - x: self.w, - y: self.w, - z: self.w, - w: self.w, - } - } } impl Add for Vec4 { @@ -3138,7 +883,7 @@ impl InnerSpace for Vec2 { fn v_angle(&self, other: &Self) -> f32 { //debug!("{:?}", dot(self,other)/(self.length()*other.length())); - acos(dot(self, other) / (self.length() * other.length())) + acos(self.dot(other) / (self.length() * other.length())) } } @@ -3157,7 +902,7 @@ impl InnerSpace for Vec3 { } fn v_angle(&self, other: &Self) -> f32 { - acos(dot(self, other) / (self.length() * other.length())) + acos(self.dot(other) / (self.length() * other.length())) } } @@ -3177,30 +922,99 @@ impl InnerSpace for Vec4 { } fn v_angle(&self, other: &Self) -> f32 { - acos(dot(self, other) / (self.length() * other.length())) + acos(self.dot(other) / (self.length() * other.length())) } } -// ################################################## -// # VECTOR FUNCTIONS # -// ################################################## - -pub fn dot(v1: &T, v2: &T) -> f32 { - v1.dot(v2) +macro_rules! generate_swizzles2 { + ($VecType:ident, $($name:ident => ($a:ident, $b:ident)),* $(,)?) => { + impl $VecType { + $( + pub fn $name(&self) -> Self { + Self { + x: self.$a, + y: self.$b, + } + } + )* + } + }; } -pub fn cross(v1: Vec3, v2: Vec3) -> Vec3 { - Vec3 { - x: v1.y * v2.z - v1.z * v2.y, - y: v1.z * v2.x - v1.x * v2.z, - z: v1.x * v2.y - v2.y * v1.x, - } +macro_rules! generate_swizzles3 { + ($VecType:ident, $($name:ident => ($a:ident, $b:ident, $c:ident)),* $(,)?) => { + impl $VecType { + $( + pub fn $name(&self) -> Self { + Self { + x: self.$a, + y: self.$b, + z: self.$c + } + } + )* + } + }; } -pub fn v_dist(v1: &T, v2: &T) -> f32 { - v1.dist(v2) +macro_rules! generate_swizzles4 { + ($VecType:ident, $($name:ident => ($a:ident, $b:ident, $c:ident, $d:ident)),* $(,)?) => { + impl $VecType { + $( + pub fn $name(&self) -> Self { + Self { + x: self.$a, + y: self.$b, + z: self.$c, + w: self.$d + } + } + )* + } + }; } -pub fn v_angle(v1: &T, v2: &T) -> f32 { - v1.v_angle(v2) -} + +generate_swizzles2!(Vec2, + xx => (x, x), xy => (x, y), + yx => (y, x), yy => (y, y) +); + +generate_swizzles3!(Vec3, + xxx => (x, x, x), xxy => (x, x, y), xxz => (x, x, z), + xyx => (x, y, x), xyy => (x, y, y), xyz => (x, y, z), + xzx => (x, z, x), xzy => (x, z, y), xzz => (x, z, z), + yxx => (y, x, x), yxy => (y, x, y), yxz => (y, x, z), + yyx => (y, y, x), yyy => (y, y, y), yyz => (y, y, z), + yzx => (y, z, x), yzy => (y, z, y), yzz => (y, z, z), + zxx => (z, x, x), zxy => (z, x, y), zxz => (z, x, z), + zyx => (z, y, x), zyy => (z, y, y), zyz => (z, y, z), + zzx => (z, z, x), zzy => (z, z, y), zzz => (z, z, z) +); + +generate_swizzles4!(Vec4, + xxxx => (x, x, x, x), xxxy => (x, x, x, y), xxxz => (x, x, x, z), xxxw => (x, x, x, w), + xxyx => (x, x, y, x), xxyy => (x, x, y, y), xxyz => (x, x, y, z), xxyw => (x, x, y, w), + xxzx => (x, x, z, x), xxzy => (x, x, z, y), xxzz => (x, x, z, z), xxzw => (x, x, z, w), + xxwx => (x, x, w, x), xxwy => (x, x, w, y), xxwz => (x, x, w, z), xxww => (x, x, w, w), + xyxx => (x, y, x, x), xyxy => (x, y, x, y), xyxz => (x, y, x, z), xyxw => (x, y, x, w), + xyyx => (x, y, y, x), xyyy => (x, y, y, y), xyyz => (x, y, y, z), xyyw => (x, y, y, w), + xyzx => (x, y, z, x), xyzy => (x, y, z, y), xyzz => (x, y, z, z), xyzw => (x, y, z, w), + xywx => (x, y, w, x), xywy => (x, y, w, y), xywz => (x, y, w, z), xyww => (x, y, w, w), + xzxx => (x, z, x, x), xzxy => (x, z, x, y), xzxz => (x, z, x, z), xzxw => (x, z, x, w), + xzyx => (x, z, y, x), xzyy => (x, z, y, y), xzyz => (x, z, y, z), xzyw => (x, z, y, w), + xzzx => (x, z, z, x), xzzy => (x, z, z, y), xzzz => (x, z, z, z), xzzw => (x, z, z, w), + xzwx => (x, z, w, x), xzwy => (x, z, w, y), xzwz => (x, z, w, z), xzww => (x, z, w, w), + xwxx => (x, w, x, x), xwxy => (x, w, x, y), xwxz => (x, w, x, z), xwxw => (x, w, x, w), + xwyx => (x, w, y, x), xwyy => (x, w, y, y), xwyz => (x, w, y, z), xwyw => (x, w, y, w), + xwzx => (x, w, z, x), xwzy => (x, w, z, y), xwzz => (x, w, z, z), xwzw => (x, w, z, w), + xwwx => (x, w, w, x), xwwy => (x, w, w, y), xwwz => (x, w, w, z), xwww => (x, w, w, w), + yxxx => (y, x, x, x), yxxy => (y, x, x, y), yxxz => (y, x, x, z), yxxw => (y, x, x, w), + yxyx => (y, x, y, x), yxyy => (y, x, y, y), yxyz => (y, x, y, z), yxyw => (y, x, y, w), + yxzx => (y, x, z, x), yxzy => (y, x, z, y), yxzz => (y, x, z, z), yxzw => (y, x, z, w), + yxwx => (y, x, w, x), yxwy => (y, x, w, y), yxwz => (y, x, w, z), yxww => (y, x, w, w), + yyxx => (y, y, x, x), yyxy => (y, y, x, y), yyxz => (y, y, x, z), yyxw => (y, y, x, w), + yyyx => (y, y, y, x), yyyy => (y, y, y, y), yyyz => (y, y, y, z), yyyw => (y, y, y, w), + yyzx => (y, y, z, x), yyzy => (y, y, z, y), yyzz => (y, y, z, z), yyzw => (y, y, z, w), + yywx => (y, y, w, x), yywy => (y, y, w, y), yywz => (y, y, w, z), yyww => (y, y, w, w) +); \ No newline at end of file