Base: fix incorrect method names of Matrix class about diagonal and trace

This commit is contained in:
wmayer
2023-08-29 15:12:18 +02:00
committed by wwmayer
parent 939984bf2c
commit 4f6ab508d7
5 changed files with 36 additions and 21 deletions

View File

@@ -107,14 +107,18 @@ public:
inline Vector3d getRow(unsigned short usNdx) const;
/// Get vector of column
inline Vector3d getCol(unsigned short usNdx) const;
/// Get vector of trace
inline Vector3d trace() const;
/// Get vector of diagonal
inline Vector3d diagonal() const;
/// Get trace of the 3x3 matrix
inline double trace3() const;
/// Get trace of the 4x4 matrix
inline double trace() const;
/// Set row to vector
inline void setRow(unsigned short usNdx, const Vector3d&);
/// Set column to vector
inline void setCol(unsigned short usNdx, const Vector3d&);
/// Set trace to vector
inline void setTrace(const Vector3d&);
/// Set diagonal to vector
inline void setDiagonal(const Vector3d&);
/// Compute the determinant of the matrix
double determinant() const;
/// Compute the determinant of the 3x3 sub-matrix
@@ -423,11 +427,21 @@ inline Vector3d Matrix4D::getCol(unsigned short usNdx) const
return Vector3d(dMtrx4D[0][usNdx], dMtrx4D[1][usNdx], dMtrx4D[2][usNdx]);
}
inline Vector3d Matrix4D::trace() const
inline Vector3d Matrix4D::diagonal() const
{
return Vector3d(dMtrx4D[0][0], dMtrx4D[1][1], dMtrx4D[2][2]);
}
inline double Matrix4D::trace3() const
{
return dMtrx4D[0][0] + dMtrx4D[1][1] + dMtrx4D[2][2];
}
inline double Matrix4D::trace() const
{
return dMtrx4D[0][0] + dMtrx4D[1][1] + dMtrx4D[2][2] + dMtrx4D[3][3];
}
inline void Matrix4D::setRow(unsigned short usNdx, const Vector3d& vec)
{
dMtrx4D[usNdx][0] = vec.x;
@@ -442,7 +456,7 @@ inline void Matrix4D::setCol(unsigned short usNdx, const Vector3d& vec)
dMtrx4D[2][usNdx] = vec.z;
}
inline void Matrix4D::setTrace(const Vector3d& vec)
inline void Matrix4D::setDiagonal(const Vector3d& vec)
{
dMtrx4D[0][0] = vec.x;
dMtrx4D[1][1] = vec.y;

View File

@@ -185,16 +185,16 @@ index : int
vector : Base.Vector</UserDocu>
</Documentation>
</Methode>
<Methode Name="trace" Const="true">
<Methode Name="diagonal" Const="true">
<Documentation>
<UserDocu>trace() -> Base.Vector
<UserDocu>diagonal() -> Base.Vector
Return the diagonal of the 3x3 leading principal submatrix as vector.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setTrace">
<Methode Name="setDiagonal">
<Documentation>
<UserDocu>setTrace(vector) -> None
<UserDocu>setDiagonal(vector) -> None
Set the diagonal of the 3x3 leading principal submatrix.

View File

@@ -487,17 +487,17 @@ PyObject* MatrixPy::setRow(PyObject * args)
Py_Return;
}
PyObject* MatrixPy::trace(PyObject * args)
PyObject* MatrixPy::diagonal(PyObject * args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
Matrix4D* mat = getMatrixPtr();
Base::Vector3d v = mat->trace();
Base::Vector3d v = mat->diagonal();
return Py::new_reference_to(Py::Vector(v));
}
PyObject* MatrixPy::setTrace(PyObject * args)
PyObject* MatrixPy::setDiagonal(PyObject * args)
{
PyObject* o{};
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &o))
@@ -505,7 +505,7 @@ PyObject* MatrixPy::setTrace(PyObject * args)
Base::Vector3d v = Py::Vector(o, false).toVector();
Matrix4D* mat = getMatrixPtr();
mat->setTrace(v);
mat->setDiagonal(v);
Py_Return;
}

View File

@@ -638,9 +638,9 @@ class MatrixTestCase(unittest.TestCase):
self.mat.setCol(0, FreeCAD.Vector(1, 0, 0))
self.mat.setRow(0, FreeCAD.Vector(1, 0, 0))
def testTrace(self):
def testDiagonal(self):
self.mat.scale(2.0, 2.0, 2.0)
self.assertEqual(self.mat.trace(), FreeCAD.Vector(2.0, 2.0, 2.0))
self.assertEqual(self.mat.diagonal(), FreeCAD.Vector(2.0, 2.0, 2.0))
def testNumberProtocol(self):
with self.assertRaises(NotImplementedError):

View File

@@ -1,7 +1,8 @@
#include "gtest/gtest.h"
#include <Base/Matrix.h>
#include <Base/Rotation.h>
// NOLINTBEGIN(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
// NOLINTBEGIN(cppcoreguidelines-*,readability-magic-numbers)
// clang-format off
TEST(Matrix, TestShearing)
{
@@ -87,12 +88,12 @@ TEST(Matrix, TestNonUniformScaleLeftTwo)
EXPECT_EQ(mat.hasScale(), Base::ScaleType::Uniform);
}
TEST(Matrix, TestTrace)
TEST(Matrix, TestDiagonal)
{
Base::Matrix4D mat;
mat.scale(2.0, 2.0, 2.0);
Base::Vector3d trace = mat.trace();
EXPECT_EQ(trace.x + trace.y + trace.z, 6.0);
Base::Vector3d diag = mat.diagonal();
EXPECT_EQ(diag.x + diag.y + diag.z, 6.0);
}
TEST(Matrix, TestColRow)
@@ -264,4 +265,4 @@ TEST(Matrix, TestSubAssign)
EXPECT_EQ(mat1, mat4);
}
// clang-format on
// NOLINTEND(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
// NOLINTEND(cppcoreguidelines-*,readability-magic-numbers)