Skip to content

Commit

Permalink
added some opOpAssign ops for matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeMyst committed Jun 20, 2020
1 parent 8654765 commit d8f6694
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions source/cosmomyst/math/matrix.d
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ struct mat(ulong n) if (n >= 2) {
return res;
}

/++
+ returns this matrix * scalar
+/
@nogc void opOpAssign(string s) (const float scalar) pure nothrow if (s == "*") {
auto res = this * scalar;
this.v = res.v;
}

/++
+ returns this matrix * vector
+/
Expand Down Expand Up @@ -101,6 +109,14 @@ struct mat(ulong n) if (n >= 2) {
return res;
}

/++
+ returns this matrix * matrix
+/
@nogc void opOpAssign (string s) (const mat!n other) pure nothrow if (s == "*") {
auto res = this * other;
this.v = res.v;
}

/++
+ returns sum or sub of two matrices
+/
Expand Down Expand Up @@ -272,6 +288,8 @@ unittest {
auto m1 = mat2(1f, 2f, 3f, 4f);
auto m2 = mat2(5f, 6f, 7f, 8f);
assert(m1 * m2 == mat2(19f, 22f, 43f, 50f));
m1 *= m2;
assert(m1 == mat2(19f, 22f, 43f, 50f));
}

unittest {
Expand Down

0 comments on commit d8f6694

Please sign in to comment.