mirror of https://github.com/KLayout/klayout.git
Further optimization/refactoring
This commit is contained in:
parent
06afaf8692
commit
d0172d57f3
|
|
@ -43,6 +43,11 @@ db::Trans OrientationReducer::reduce (const db::Trans &trans) const
|
|||
return db::Trans (trans.fp_trans ());
|
||||
}
|
||||
|
||||
bool OrientationReducer::equals (const TransformationReducer *other) const
|
||||
{
|
||||
return dynamic_cast<const OrientationReducer *> (other) != 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
|
||||
db::ICplxTrans OrthogonalTransformationReducer::reduce (const db::ICplxTrans &trans) const
|
||||
|
|
@ -63,6 +68,11 @@ db::Trans OrthogonalTransformationReducer::reduce (const db::Trans &) const
|
|||
return db::Trans ();
|
||||
}
|
||||
|
||||
bool OrthogonalTransformationReducer::equals (const TransformationReducer *other) const
|
||||
{
|
||||
return dynamic_cast<const OrthogonalTransformationReducer *> (other) != 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
|
||||
db::ICplxTrans MagnificationReducer::reduce (const db::ICplxTrans &trans) const
|
||||
|
|
@ -75,6 +85,11 @@ db::Trans MagnificationReducer::reduce (const db::Trans &) const
|
|||
return db::Trans ();
|
||||
}
|
||||
|
||||
bool MagnificationReducer::equals (const TransformationReducer *other) const
|
||||
{
|
||||
return dynamic_cast<const MagnificationReducer *> (other) != 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
|
||||
db::ICplxTrans XYAnisotropyAndMagnificationReducer::reduce (const db::ICplxTrans &trans) const
|
||||
|
|
@ -91,6 +106,11 @@ db::Trans XYAnisotropyAndMagnificationReducer::reduce (const db::Trans &trans) c
|
|||
return db::Trans (trans.angle () % 2, false, db::Vector ());
|
||||
}
|
||||
|
||||
bool XYAnisotropyAndMagnificationReducer::equals (const TransformationReducer *other) const
|
||||
{
|
||||
return dynamic_cast<const XYAnisotropyAndMagnificationReducer *> (other) != 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
|
||||
db::ICplxTrans MagnificationAndOrientationReducer::reduce (const db::ICplxTrans &trans) const
|
||||
|
|
@ -105,6 +125,11 @@ db::Trans MagnificationAndOrientationReducer::reduce (const db::Trans &trans) co
|
|||
return db::Trans (trans.fp_trans ());
|
||||
}
|
||||
|
||||
bool MagnificationAndOrientationReducer::equals (const TransformationReducer *other) const
|
||||
{
|
||||
return dynamic_cast<const MagnificationAndOrientationReducer *> (other) != 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
|
||||
GridReducer::GridReducer (db::Coord grid)
|
||||
|
|
@ -130,6 +155,12 @@ db::Trans GridReducer::reduce (const db::Trans &trans) const
|
|||
return res;
|
||||
}
|
||||
|
||||
bool GridReducer::equals (const TransformationReducer *other) const
|
||||
{
|
||||
const GridReducer *red = dynamic_cast<const GridReducer *> (other);
|
||||
return red != 0 && red->m_grid == m_grid;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
|
||||
ScaleAndGridReducer::ScaleAndGridReducer (db::Coord grid, db::Coord mult, db::Coord div)
|
||||
|
|
@ -174,6 +205,12 @@ db::Trans ScaleAndGridReducer::reduce (const db::Trans &trans) const
|
|||
return res;
|
||||
}
|
||||
|
||||
bool ScaleAndGridReducer::equals (const TransformationReducer *other) const
|
||||
{
|
||||
const ScaleAndGridReducer *red = dynamic_cast<const ScaleAndGridReducer *> (other);
|
||||
return red != 0 && red->m_grid == m_grid && red->m_mult == m_mult;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
|
||||
VariantsCollectorBase::VariantsCollectorBase ()
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ public:
|
|||
virtual db::ICplxTrans reduce_trans (const db::ICplxTrans &trans) const { return reduce (trans); }
|
||||
virtual db::Trans reduce (const db::Trans &trans) const = 0;
|
||||
virtual db::ICplxTrans reduce (const db::ICplxTrans &trans) const = 0;
|
||||
virtual bool equals (const TransformationReducer *other) const = 0;
|
||||
virtual bool is_translation_invariant () const { return true; }
|
||||
};
|
||||
|
||||
|
|
@ -67,6 +68,7 @@ struct DB_PUBLIC OrientationReducer
|
|||
{
|
||||
db::ICplxTrans reduce (const db::ICplxTrans &trans) const;
|
||||
db::Trans reduce (const db::Trans &trans) const;
|
||||
virtual bool equals (const TransformationReducer *other) const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -77,6 +79,7 @@ struct DB_PUBLIC OrthogonalTransformationReducer
|
|||
{
|
||||
db::ICplxTrans reduce (const db::ICplxTrans &trans) const;
|
||||
db::Trans reduce (const db::Trans &trans) const;
|
||||
virtual bool equals (const TransformationReducer *other) const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -89,6 +92,7 @@ struct DB_PUBLIC MagnificationReducer
|
|||
{
|
||||
db::ICplxTrans reduce (const db::ICplxTrans &trans) const;
|
||||
db::Trans reduce (const db::Trans &) const;
|
||||
virtual bool equals (const TransformationReducer *other) const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -101,6 +105,7 @@ struct DB_PUBLIC XYAnisotropyAndMagnificationReducer
|
|||
{
|
||||
db::ICplxTrans reduce (const db::ICplxTrans &trans) const;
|
||||
db::Trans reduce (const db::Trans &trans) const;
|
||||
virtual bool equals (const TransformationReducer *other) const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -113,6 +118,7 @@ struct DB_PUBLIC MagnificationAndOrientationReducer
|
|||
{
|
||||
db::ICplxTrans reduce (const db::ICplxTrans &trans) const;
|
||||
db::Trans reduce (const db::Trans &trans) const;
|
||||
virtual bool equals (const TransformationReducer *other) const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -127,6 +133,7 @@ struct DB_PUBLIC GridReducer
|
|||
|
||||
db::ICplxTrans reduce (const db::ICplxTrans &trans) const;
|
||||
db::Trans reduce (const db::Trans &trans) const;
|
||||
virtual bool equals (const TransformationReducer *other) const;
|
||||
|
||||
bool is_translation_invariant () const { return false; }
|
||||
|
||||
|
|
@ -150,6 +157,7 @@ struct DB_PUBLIC ScaleAndGridReducer
|
|||
virtual db::Trans reduce_trans (const db::Trans &trans) const;
|
||||
virtual db::ICplxTrans reduce (const db::ICplxTrans &trans) const;
|
||||
virtual db::Trans reduce (const db::Trans &trans) const;
|
||||
virtual bool equals (const TransformationReducer *other) const;
|
||||
|
||||
bool is_translation_invariant () const { return false; }
|
||||
|
||||
|
|
|
|||
|
|
@ -236,7 +236,16 @@ void
|
|||
CompoundTransformationReducer::add (const db::TransformationReducer *reducer)
|
||||
{
|
||||
if (reducer) {
|
||||
|
||||
// do not add the same reducer twice
|
||||
for (auto v = m_vars.begin (); v != m_vars.end (); ++v) {
|
||||
if (reducer->equals (*v)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_vars.push_back (reducer);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -431,6 +431,9 @@ public:
|
|||
virtual db::ICplxTrans reduce (const db::ICplxTrans &trans) const;
|
||||
virtual bool is_translation_invariant () const;
|
||||
|
||||
// NOTE: equality does not really matter here as we use it only on leaf reducers
|
||||
virtual bool equals (const TransformationReducer *other) const { return false; }
|
||||
|
||||
private:
|
||||
std::vector<const db::TransformationReducer *> m_vars;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue