From: Pasukhin Dmitry Date: Tue, 24 Jun 2025 11:38:31 +0000 (+0100) Subject: Foundation Classes - Matrix multiplied issue (#522) X-Git-Tag: V7_9_2~23 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=9cf1fb1d7c44ab856ba9d33e9d7d4915f81d542f;p=occt.git Foundation Classes - Matrix multiplied issue (#522) Refactor multiplication to avoid self-correlation issues by using a temporary copy. --- diff --git a/src/math/math_Matrix.cxx b/src/math/math_Matrix.cxx index b2a61e1667..b7fa5177ab 100644 --- a/src/math/math_Matrix.cxx +++ b/src/math/math_Matrix.cxx @@ -635,6 +635,14 @@ void math_Matrix::Multiply(const math_Matrix& Right) ColNumber() != Right.RowNumber(), "math_Matrix::Multiply() - input matrix has incompatible dimensions"); + // Create a temporary copy to avoid corrupting our own data during calculation + math_Matrix aTemp = *this; + if (this == &Right) + { + Multiply(aTemp, aTemp); + return; + } + Standard_Real Som; for (Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) { @@ -644,7 +652,7 @@ void math_Matrix::Multiply(const math_Matrix& Right) Standard_Integer I2 = Right.LowerRowIndex; for (Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) { - Som = Som + Array(I, J) * Right.Array(I2, J2); + Som += aTemp.Array(I, J) * Right.Array(I2, J2); I2++; } Array(I, J2) = Som;