Skip to content

Commit

Permalink
added operator for vec * scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeMyst committed Jun 20, 2020
1 parent fc97067 commit 0ebe133
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion source/cosmomyst/math/vector.d
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ struct vec(ulong n) if (n >= 1) {
return res;
}

/++
+ returns the mul of this * scalar
+/
@nogc vec!n opBinary(string s) (const float scalar) const if (s == "*") {
vec!n res;
for (int i = 0; i < n; i++) {
res[i] = this[i] * scalar;
}
return res;
}

/++
+ returns the sub of 2 vectors.
+/
Expand All @@ -114,7 +125,7 @@ struct vec(ulong n) if (n >= 1) {
}

/++
+ returns the div of 2 vectors.
+ returns the div of this / scalar.
+/
@nogc vec!n opBinary(string s) (in float scalar) const if (s == "/") {
vec!n res;
Expand Down Expand Up @@ -200,3 +211,8 @@ unittest {
auto t2 = vec3(3f, 7f, 2f);
assert(t1 - t2 == vec3(2f, -5f, 5f));
}

unittest {
auto t1 = vec3(1f, 2f, 3f);
assert(t1 * 2 == vec3(2f, 4f, 6f));
}

0 comments on commit 0ebe133

Please sign in to comment.