Skip to content

Commit

Permalink
Put the boolean test on wether the constraint is still active or not …
Browse files Browse the repository at this point in the history
…inside a method
  • Loading branch information
bakpaul committed Dec 11, 2024
1 parent 1cf6a57 commit b11ee8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public :
void draw(const core::visual::VisualParams* vparams) override;

private:
/// Check if the constraint is still active regarding the current time and the continueAfterEnd data
bool isConstraintActive() const;

/// to know if we found the key times
bool m_finished;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void LinearVelocityProjectiveConstraint<TDataTypes>::projectResponse(const core:
m_finished = findKeyTimes();
}

if ((!m_finished || d_continueAfterEnd.getValue()) && (m_nextT != m_prevT))
if (isConstraintActive())
{
helper::WriteAccessor<DataVecDeriv> res = resData;
VecDeriv& dx = res.wref();
Expand All @@ -177,7 +177,7 @@ void LinearVelocityProjectiveConstraint<TDataTypes>::projectVelocity(const core:
m_finished = findKeyTimes();
}

if ((! m_finished || d_continueAfterEnd.getValue()) && (m_nextT != m_prevT))
if (isConstraintActive())
{
helper::WriteAccessor<DataVecDeriv> dx = vData;
Real cT = (Real) this->getContext()->getTime();
Expand Down Expand Up @@ -241,7 +241,7 @@ void LinearVelocityProjectiveConstraint<TDataTypes>::projectPosition(const core:
m_finished = findKeyTimes();
}

if((!m_finished || d_continueAfterEnd.getValue()) && (m_nextT != m_prevT))
if(isConstraintActive())
{
const Real cT = (Real) this->getContext()->getTime();
const Real dTsimu = (Real) this->getContext()->getDt();
Expand Down Expand Up @@ -280,6 +280,12 @@ void LinearVelocityProjectiveConstraint<TDataTypes>::projectPosition(const core:
}
}

template <class DataTypes>
bool LinearVelocityProjectiveConstraint<DataTypes>::isConstraintActive() const
{
return (!m_finished || d_continueAfterEnd.getValue()) && (m_nextT != m_prevT);
}

template <class DataTypes>
bool LinearVelocityProjectiveConstraint<DataTypes>::findKeyTimes()
{
Expand Down Expand Up @@ -333,7 +339,7 @@ void LinearVelocityProjectiveConstraint<DataTypes>::applyConstraint(const core::
{
SOFA_UNUSED(mparams);

if((!m_finished || d_continueAfterEnd.getValue()) && (m_nextT != m_prevT))
if(isConstraintActive())
{
const int o = matrix->getGlobalOffset(this->mstate.get());
if (o >= 0)
Expand All @@ -357,7 +363,7 @@ template <class DataTypes>
void LinearVelocityProjectiveConstraint<DataTypes>::applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix)
{
SOFA_UNUSED(mparams);
if((!m_finished || d_continueAfterEnd.getValue()) && (m_nextT != m_prevT))
if(isConstraintActive())
{
if (const core::behavior::MultiMatrixAccessor::MatrixRef r =
matrix->getMatrix(this->mstate.get()))
Expand Down Expand Up @@ -387,7 +393,7 @@ void LinearVelocityProjectiveConstraint<DataTypes>::projectMatrix( sofa::lineara
{
static const unsigned blockSize = DataTypes::deriv_total_size;

if((!m_finished || d_continueAfterEnd.getValue()) && (m_nextT != m_prevT))
if(isConstraintActive())
{
const SetIndexArray & indices = this->d_indices.getValue();
for (SetIndexArray::const_iterator it = indices.begin(); it != indices.end(); ++it)
Expand All @@ -405,7 +411,7 @@ void LinearVelocityProjectiveConstraint<DataTypes>::applyConstraint(
sofa::core::behavior::ZeroDirichletCondition* matrix)
{
static constexpr unsigned int N = Deriv::size();
if((!m_finished || d_continueAfterEnd.getValue()) && (m_nextT != m_prevT))
if(isConstraintActive())
{
const SetIndexArray& indices = this->d_indices.getValue();

Expand Down

0 comments on commit b11ee8c

Please sign in to comment.