Skip to content

Commit 5dd6a40

Browse files
committed
Matrix - comment to explain copy in Matrix multiply/divide operators
1 parent 228e531 commit 5dd6a40

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Source/System/Matrix.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,15 @@ namespace RTE {
233233
/// @param rhs A Matrix reference as the right hand side operand.
234234
/// @return A reference to the resulting Vector.
235235
friend Vector operator*(const Vector& lhs, const Matrix& rhs) {
236+
// Multiplication might call Matrix::UpdateElements and therefore
237+
// needs to modify it.
238+
//
239+
// However, this function signature uses const ref for the matrix.
240+
//
241+
// Therefore, the only way to perform this as needed
242+
// without changing it to mut ref is by copying the matrix.
243+
//
244+
// TODO: see if we can unjank this?
236245
Matrix m(rhs);
237246
return m * lhs;
238247
}
@@ -248,6 +257,15 @@ namespace RTE {
248257
/// @param rhs A Matrix reference as the right hand side operand.
249258
/// @return A reference to the resulting Vector.
250259
friend Vector operator/(const Vector& lhs, const Matrix& rhs) {
260+
// Division might call Matrix::UpdateElements and therefore
261+
// needs to modify it.
262+
//
263+
// However, this function signature uses const ref for the matrix.
264+
//
265+
// Therefore, the only way to perform this as needed
266+
// without changing it to mut ref is by copying the matrix.
267+
//
268+
// TODO: see if we can unjank this?
251269
Matrix m(rhs);
252270
return m / lhs;
253271
}

0 commit comments

Comments
 (0)