Skip to content

Commit 0ab7587

Browse files
committed
new method augment to obey DRY principle
1 parent 0516f52 commit 0ab7587

File tree

1 file changed

+28
-44
lines changed

1 file changed

+28
-44
lines changed

src/state.cpp

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ class impl {
275275
void establish_orthogonal( Index a, Index b );
276276
void establish_copunctual( Index a, Index b, Index c );
277277

278+
void augment();
279+
278280
[[nodiscard]] std::pair<Eigen::VectorXd, SparseMatrix<double> >
279281
a_Maker( const ArrayXi & maps_ ) const;
280282

@@ -537,14 +539,14 @@ void impl::findAdjacenciesRecentSegment(const Quantiles::Snapping &snap)
537539
{
538540
for ( int i=0; i<m_segm.length()-1; i++)
539541
{
540-
bool are_adjacent = false;
541-
542542
// pre-check (culling) via axis-aligned bounding boxes
543543
if ( !m_segm.at(i)->bounding_box().overlaps(
544544
m_segm.last()->bounding_box()) ) {
545545
continue;
546546
}
547547

548+
bool are_adjacent = false;
549+
548550
if ( m_segm.last()->touchedBy( m_segm.at(i)->ux(),
549551
snap.quantile_stdNormDistr(),
550552
snap.quantile_chi2_1dof()) ) {
@@ -961,6 +963,20 @@ bool impl::are_identical( const Index a, const Index b)
961963
}
962964

963965

966+
// augment state with new, unevaluated constraint
967+
void impl::augment()
968+
{
969+
// append an empty column
970+
Rel.conservativeResize(Rel.rows(), Rel.cols()+1);
971+
972+
m_status.conservativeResize(m_status.size()+1);
973+
m_status(last) = Attribute::Unevaluated;
974+
975+
m_enforced.conservativeResize(m_enforced.size()+1);
976+
m_enforced(last) = false;
977+
}
978+
979+
964980
void impl::establish_parallel( const Index a,
965981
const Index b)
966982
{
@@ -975,77 +991,51 @@ void impl::establish_parallel( const Index a,
975991
m_qConstraint.append( QConstraint::QParallel::create() );
976992
m_constr.append( std::make_shared<Parallel>() );
977993

978-
Rel.conservativeResize( Rel.rows(), Rel.cols()+1); // append a column
994+
augment();
979995
Rel.set( a, last );
980996
Rel.set( b, last );
981-
982-
m_status.conservativeResize(m_status.size()+1);
983-
m_status(last) = Attribute::Unevaluated;
984-
985-
m_enforced.conservativeResize(m_enforced.size()+1);
986-
m_enforced(last) = false;
987997
}
988998

999+
9891000
void impl::establish_vertical( const Index a)
9901001
{
9911002
m_qConstraint.append( QConstraint::QAligned::create());
9921003
m_constr.append( std::make_shared<Vertical>() );
9931004

994-
Rel.conservativeResize( Rel.rows(), Rel.cols()+1); // append a column
1005+
augment();
9951006
Rel.set( a, last );
996-
997-
m_status.conservativeResize(m_status.size()+1);
998-
m_status(last) = Attribute::Unevaluated;
999-
1000-
m_enforced.conservativeResize(m_enforced.size()+1);
1001-
m_enforced(last) = false;
10021007
}
10031008

1009+
10041010
void impl::establish_horizontal( const Index a)
10051011
{
10061012
m_qConstraint.append( QConstraint::QAligned::create());
10071013
m_constr.append( std::make_shared<Horizontal>() );
10081014

1009-
Rel.conservativeResize( Rel.rows(), Rel.cols()+1); // append a column
1015+
augment();
10101016
Rel.set( a, last );
1011-
1012-
m_status.conservativeResize(m_status.size()+1);
1013-
m_status(last) = Attribute::Unevaluated;
1014-
1015-
m_enforced.conservativeResize(m_enforced.size()+1);
1016-
m_enforced(last) = false;
10171017
}
10181018

1019+
10191020
void impl::establish_diagonal( const Index a)
10201021
{
10211022
m_qConstraint.append( QConstraint::QAligned::create());
10221023
m_constr.append( std::make_shared<Diagonal>() );
10231024

1024-
Rel.conservativeResize( Rel.rows(), Rel.cols()+1); // append a column
1025+
augment();
10251026
Rel.set( a, last );
1026-
1027-
m_status.conservativeResize(m_status.size()+1);
1028-
m_status(last) = Attribute::Unevaluated;
1029-
1030-
m_enforced.conservativeResize(m_enforced.size()+1);
1031-
m_enforced(last) = false;
10321027
}
10331028

1029+
10341030
void impl::establish_orthogonal( const Index a,
10351031
const Index b)
10361032
{
10371033
m_qConstraint.append( QConstraint::QOrthogonal::create());
10381034
m_constr.append( std::make_shared<Orthogonal>() );
10391035

1040-
Rel.conservativeResize( Rel.rows(), Rel.cols()+1); // append a column
1036+
augment();
10411037
Rel.set( a, last );
10421038
Rel.set( b, last );
1043-
1044-
m_status.conservativeResize(m_status.size()+1);
1045-
m_status(last) = Attribute::Unevaluated;
1046-
1047-
m_enforced.conservativeResize(m_enforced.size()+1);
1048-
m_enforced(last) = false;
10491039
}
10501040

10511041

@@ -1056,16 +1046,10 @@ void impl::establish_copunctual( const Index a,
10561046
m_qConstraint.append( QConstraint::QCopunctual::create() );
10571047
m_constr.append( std::make_shared<Copunctual>() );
10581048

1059-
Rel.conservativeResize( Rel.rows(), Rel.cols()+1) ; // append a column
1049+
augment();
10601050
Rel.set( a, last );
10611051
Rel.set( b, last );
10621052
Rel.set( c, last );
1063-
1064-
m_status.conservativeResize(m_status.size()+1);
1065-
m_status(last) = Attribute::Unevaluated;
1066-
1067-
m_enforced.conservativeResize(m_enforced.size()+1);
1068-
m_enforced(last) = false;
10691053
}
10701054

10711055

0 commit comments

Comments
 (0)