Skip to content

Commit 600bf8f

Browse files
fredroyepernod
andauthored
[Defaulttype] RigidTypes: Fix various bugs in RigidCoord/RigidMass and add unit tests (#5988)
* fix potential compilation error (member is not callable...) * fix out of bounds access for rigid2 * add extensive unit tests for rigidtypes (coord, deriv..) * fix rigidcoord2 neg operator (would be in-compilable, orientation is a scalar) * add stream tests for rigidmass, exposing bug * fix rigidmass stream bug * add rigid coord tests on operator+ and +=, exposing bug * fix bug about inconsistency between operator+ and += The fix was changing orientation *= a.getOrientation() (right-multiply) to orientation = a.getOrientation() * orientation (left-multiply), matching the order used in operator+. * fix volume computation for rigidmass2d and add test --------- Co-authored-by: erik pernod <erik.pernod@gmail.com>
1 parent d99cc74 commit 600bf8f

6 files changed

Lines changed: 1295 additions & 7 deletions

File tree

Sofa/framework/DefaultType/src/sofa/defaulttype/RigidCoord.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class RigidCoord<3,real>
157157
constexpr void operator +=(const RigidCoord<3, real>& a)
158158
{
159159
center += a.getCenter();
160-
orientation *= a.getOrientation();
160+
orientation = a.getOrientation() * orientation;
161161
}
162162

163163
template<typename real2>
@@ -252,7 +252,7 @@ class RigidCoord<3,real>
252252
{
253253
RigidCoord r;
254254
r.center = c.center + center;
255-
r.orientation = c.orientation();
255+
r.orientation = c.orientation;
256256
return r;
257257
}
258258

@@ -512,7 +512,7 @@ class RigidCoord<2,real>
512512

513513
constexpr RigidCoord<2, real> operator-() const
514514
{
515-
return RigidCoord<2, real>(-this->center, this->orientation.inverse());
515+
return RigidCoord<2, real>(-this->center, -this->orientation);
516516
}
517517

518518

@@ -602,7 +602,7 @@ class RigidCoord<2,real>
602602
{
603603
RigidCoord r;
604604
r.center = c.center + center;
605-
r.orientation = c.orientation();
605+
r.orientation = c.orientation;
606606
return r;
607607
}
608608

@@ -691,7 +691,7 @@ class RigidCoord<2,real>
691691
m[11] = 0;
692692
m[12] = (float)center[0];
693693
m[13] = (float)center[1];
694-
m[14] = (float)center[2];
694+
m[14] = 0;
695695
m[15] = 1;
696696
}
697697

Sofa/framework/DefaultType/src/sofa/defaulttype/RigidMass.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class RigidMass<3, real>
9898
in>>m.mass;
9999
in>>m.volume;
100100
in>>m.inertiaMatrix;
101+
m.recalc();
101102
return in;
102103
}
103104
constexpr void operator *=(Real fact)
@@ -195,8 +196,8 @@ class RigidMass<2, real>
195196
RigidMass(Real m, Real xwidth, Real ywidth)
196197
{
197198
mass = m;
198-
volume = xwidth*xwidth + ywidth*ywidth;
199-
inertiaMatrix = volume/12;
199+
volume = xwidth * ywidth;
200+
inertiaMatrix = (xwidth*xwidth + ywidth*ywidth) / 12;
200201
recalc();
201202
}
202203

@@ -226,6 +227,7 @@ class RigidMass<2, real>
226227
in>>m.mass;
227228
in>>m.volume;
228229
in>>m.inertiaMatrix;
230+
m.recalc();
229231
return in;
230232
}
231233
constexpr void operator *=(Real fact)

Sofa/framework/DefaultType/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ set(HEADER_FILES
1010
set(SOURCE_FILES
1111
MapMapSparseMatrixEigenUtils_test.cpp
1212
QuaternionIntegration_test.cpp
13+
RigidCoord_test.cpp
1314
RigidDeriv_test.cpp
15+
RigidMass_test.cpp
1416
TypeInfoRepository_test.cpp
1517
TypeInfoRepository_tu1_test.cpp
1618
TypeInfo_test.cpp

0 commit comments

Comments
 (0)