- Added SetDiagonal method

- Bug fixed in RowsNumber and ColumnsNumber
This commit is contained in:
Paolo Cignoni 2004-10-18 12:16:57 +00:00
parent 7767e4a63b
commit 1422c15f6f
1 changed files with 18 additions and 7 deletions

View File

@ -55,7 +55,7 @@ namespace vcg
_rows = m; _rows = m;
_columns = n; _columns = n;
_data = new ScalarType[m*n]; _data = new ScalarType[m*n];
memset(_data, ScalarType(0.0), m*n*sizeof(ScalarType)); memset(_data, 0, m*n*sizeof(ScalarType));
}; };
/*! /*!
@ -100,7 +100,7 @@ namespace vcg
/*! /*!
* Number of columns * Number of columns
*/ */
inline unsigned int ColumnsNumber() inline unsigned int ColumnsNumber() const
{ {
return _columns; return _columns;
}; };
@ -109,7 +109,7 @@ namespace vcg
/*! /*!
* Number of rows * Number of rows
*/ */
inline unsigned int RowsNumber() inline unsigned int RowsNumber() const
{ {
return _rows; return _rows;
}; };
@ -231,7 +231,7 @@ namespace vcg
*/ */
inline TYPE* operator[](const unsigned int i) inline TYPE* operator[](const unsigned int i)
{ {
assert(i>=0 && i<_columns); assert(i>=0 && i<_rows);
return _data + i*_columns; return _data + i*_columns;
}; };
@ -242,7 +242,7 @@ namespace vcg
*/ */
inline const TYPE* operator[](const unsigned int i) const inline const TYPE* operator[](const unsigned int i) const
{ {
assert(i>=0 && i<_columns); assert(i>=0 && i<_rows);
return _data + i*_columns; return _data + i*_columns;
}; };
@ -419,7 +419,7 @@ namespace vcg
/*! /*!
* Negate all matrix elements * Negate all matrix elements
* \return ... * \return the modified matrix
*/ */
Matrix<TYPE> operator-() const Matrix<TYPE> operator-() const
{ {
@ -491,6 +491,17 @@ namespace vcg
_data[p] = v[j]; _data[p] = v[j];
}; };
/*!
* Set the diagonal elements <I>v<SUB>i,i</SUB></I> to v[i]
* \param v
*/
void SetDiagonal(TYPE *v)
{
assert(_rows == _columns);
for (unsigned int i=0, p=0; i<_rows; i++, p+=_rows)
_data[p+i] = v[i];
};
/*! /*!
* Resize the current matrix. * Resize the current matrix.
* \param m the number of matrix rows. * \param m the number of matrix rows.