@@ -48,6 +48,30 @@ impl Vec3 {
48
48
z : 1.0 ,
49
49
}
50
50
}
51
+
52
+ /// Create a vector by taking the absolute value of each component in this vector
53
+ pub fn abs ( & self ) -> Self {
54
+ Self {
55
+ x : self . x . abs ( ) ,
56
+ y : self . y . abs ( ) ,
57
+ z : self . z . abs ( ) ,
58
+ }
59
+ }
60
+
61
+ /// Sum all of the components in this vector
62
+ pub fn component_sum ( & self ) -> f32 {
63
+ self . x + self . y + self . z
64
+ }
65
+
66
+ /// Find the maximum value out of all components in this vector
67
+ pub fn component_max ( & self ) -> f32 {
68
+ self . x . max ( self . y . max ( self . z ) )
69
+ }
70
+
71
+ /// Find the minimum value out of all components in this vector
72
+ pub fn component_min ( & self ) -> f32 {
73
+ self . x . min ( self . y . min ( self . z ) )
74
+ }
51
75
}
52
76
53
77
impl std:: ops:: Add for Vec3 {
@@ -81,6 +105,13 @@ impl std::ops::Mul<f32> for Vec3 {
81
105
Vec3 :: new ( self . x * other, self . y * other, self . z * other)
82
106
}
83
107
}
108
+ impl std:: ops:: Mul < Vec3 > for f32 {
109
+ type Output = Vec3 ;
110
+
111
+ fn mul ( self , other : Vec3 ) -> Vec3 {
112
+ Vec3 :: new ( self * other. x , self * other. y , self * other. z )
113
+ }
114
+ }
84
115
85
116
impl std:: ops:: Div for Vec3 {
86
117
type Output = Vec3 ;
@@ -89,3 +120,19 @@ impl std::ops::Div for Vec3 {
89
120
Vec3 :: new ( self . x / other. x , self . y / other. y , self . z / other. z )
90
121
}
91
122
}
123
+
124
+ impl std:: ops:: Div < f32 > for Vec3 {
125
+ type Output = Vec3 ;
126
+
127
+ fn div ( self , other : f32 ) -> Vec3 {
128
+ Vec3 :: new ( self . x / other, self . y / other, self . z / other)
129
+ }
130
+ }
131
+
132
+ impl std:: ops:: Div < Vec3 > for f32 {
133
+ type Output = Vec3 ;
134
+
135
+ fn div ( self , other : Vec3 ) -> Vec3 {
136
+ Vec3 :: new ( self / other. x , self / other. y , self / other. z )
137
+ }
138
+ }
0 commit comments