Skip to content

Commit

Permalink
Corrections to copy assignment operators for Quaternion, and matrix c…
Browse files Browse the repository at this point in the history
…lasses
  • Loading branch information
optseb committed Nov 23, 2023
1 parent a16d3f7 commit cc424de
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion morph/Matrix33.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace morph {
//! User-declared copy assignment constructor
Matrix33<Flt>& operator= (Matrix33<Flt>& other)
{
std::swap (mat, other.mat);
std::copy (other.mat.begin(), other.mat.end(), mat.begin());
return *this;
}
//! Explicitly defaulted move constructor
Expand Down
8 changes: 4 additions & 4 deletions morph/Quaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ namespace morph {
//! User-declared copy assignment constructor
Quaternion<Flt>& operator= (Quaternion<Flt>& other)
{
std::swap (w, other.w);
std::swap (x, other.x);
std::swap (y, other.y);
std::swap (z, other.z);
w = other.w;
x = other.x;
y = other.y;
z = other.z;
return *this;
}
//! Explicitly defaulted move constructor
Expand Down
2 changes: 1 addition & 1 deletion morph/TransformMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace morph {
//! User-declared copy assignment constructor
TransformMatrix<Flt>& operator= (TransformMatrix<Flt>& other)
{
std::swap (mat, other.mat);
std::copy (other.mat.begin(), other.mat.end(), mat.begin());
return *this;
}
//! Explicitly defaulted move constructor
Expand Down
8 changes: 7 additions & 1 deletion tests/testTransformMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ int main()
++rtn;
}
}

tm2 = static_cast<morph::TransformMatrix<float>>(tm1);
std::cout << "After second assignment:\n" << tm2 << std::endl;
for (unsigned int i = 0; i<16; ++i) {
if (tm2.mat[i] != (float)i) {
++rtn;
}
}
// Test multiplication
morph::TransformMatrix<float> mult1;
setMatrixSequence (mult1);
Expand Down

0 comments on commit cc424de

Please sign in to comment.