mirror of https://github.com/KLayout/klayout.git
WIP: tests for cluster in hierarchical network processor.
This commit is contained in:
parent
59d1aead59
commit
e918cc74b0
|
|
@ -132,6 +132,15 @@ local_cluster<T>::local_cluster ()
|
|||
// .. nothing yet ..
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void
|
||||
local_cluster<T>::clear ()
|
||||
{
|
||||
m_shapes.clear ();
|
||||
m_needs_update = false;
|
||||
m_bbox = box_type ();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void
|
||||
local_cluster<T>::add (const T &s, unsigned int la)
|
||||
|
|
@ -241,7 +250,7 @@ local_cluster<T>::interacts (const local_cluster<T> &other, const db::ICplxTrans
|
|||
{
|
||||
const_cast<local_cluster<T> *> (this)->ensure_sorted ();
|
||||
|
||||
if (! other.bbox ().overlaps (bbox ())) {
|
||||
if (! other.bbox ().touches (bbox ())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -253,7 +262,7 @@ local_cluster<T>::interacts (const local_cluster<T> &other, const db::ICplxTrans
|
|||
|
||||
bool any = false;
|
||||
for (typename std::map<unsigned int, tree_type>::const_iterator s = m_shapes.begin (); s != m_shapes.end (); ++s) {
|
||||
for (typename tree_type::overlapping_iterator i = s->second.begin_overlapping (common, bc); ! i.at_end (); ++i) {
|
||||
for (typename tree_type::touching_iterator i = s->second.begin_touching (common, bc); ! i.at_end (); ++i) {
|
||||
scanner.insert1 (i.operator-> (), s->first);
|
||||
any = true;
|
||||
}
|
||||
|
|
@ -264,13 +273,13 @@ local_cluster<T>::interacts (const local_cluster<T> &other, const db::ICplxTrans
|
|||
}
|
||||
|
||||
for (typename std::map<unsigned int, tree_type>::const_iterator s = other.m_shapes.begin (); s != other.m_shapes.end (); ++s) {
|
||||
for (typename tree_type::overlapping_iterator i = s->second.begin_overlapping (common.transformed (trans.inverted ()), bc); ! i.at_end (); ++i) {
|
||||
for (typename tree_type::touching_iterator i = s->second.begin_touching (common.transformed (trans.inverted ()), bc); ! i.at_end (); ++i) {
|
||||
scanner.insert2 (i.operator-> (), s->first);
|
||||
}
|
||||
}
|
||||
|
||||
interaction_receiver<T> rec (conn, trans);
|
||||
return ! scanner.process (rec, 0, bc, bc_t);
|
||||
return ! scanner.process (rec, 1 /*==touching*/, bc, bc_t);
|
||||
}
|
||||
|
||||
// explicit instantiations
|
||||
|
|
|
|||
|
|
@ -125,6 +125,11 @@ public:
|
|||
*/
|
||||
local_cluster ();
|
||||
|
||||
/**
|
||||
* @brief Clears the cluster
|
||||
*/
|
||||
void clear ();
|
||||
|
||||
/**
|
||||
* @brief Adds a shape with the given layer to the cluster
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -133,3 +133,97 @@ TEST(2_ShapeInteractionsRealPolygon)
|
|||
EXPECT_EQ (conn.interacts (ref1, 1, ref2, 2), false);
|
||||
EXPECT_EQ (conn.interacts (ref1, 1, ref1, 2, t2), false);
|
||||
}
|
||||
|
||||
TEST(10_LocalClusterBasic)
|
||||
{
|
||||
db::GenericRepository repo;
|
||||
|
||||
db::Polygon poly;
|
||||
tl::from_string ("(0,0;0,1000;1000,1000;1000,0)", poly);
|
||||
|
||||
db::local_cluster<db::PolygonRef> cluster;
|
||||
EXPECT_EQ (cluster.bbox ().to_string (), "()");
|
||||
EXPECT_EQ (cluster.id (), size_t (0));
|
||||
|
||||
cluster.add (db::PolygonRef (poly, repo), 0);
|
||||
EXPECT_EQ (cluster.bbox ().to_string (), "(0,0;1000,1000)");
|
||||
|
||||
db::local_cluster<db::PolygonRef> cluster2;
|
||||
cluster.add (db::PolygonRef (poly, repo).transformed (db::Trans (db::Vector (10, 20))), 1);
|
||||
|
||||
cluster.join_with (cluster2);
|
||||
EXPECT_EQ (cluster.bbox ().to_string (), "(0,0;1010,1020)");
|
||||
}
|
||||
|
||||
TEST(11_LocalClusterInteractBasic)
|
||||
{
|
||||
db::GenericRepository repo;
|
||||
|
||||
db::Connectivity conn;
|
||||
conn.connect (0);
|
||||
conn.connect (1);
|
||||
conn.connect (2);
|
||||
conn.connect (0, 1);
|
||||
conn.connect (0, 2);
|
||||
|
||||
db::Polygon poly;
|
||||
tl::from_string ("(0,0;0,1000;1000,1000;1000,0)", poly);
|
||||
|
||||
db::local_cluster<db::PolygonRef> cluster;
|
||||
db::local_cluster<db::PolygonRef> cluster2;
|
||||
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (), conn), false);
|
||||
|
||||
cluster.add (db::PolygonRef (poly, repo), 0);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (), conn), false);
|
||||
|
||||
cluster2.add (db::PolygonRef (poly, repo), 0);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (), conn), true);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (db::Trans (db::Vector (10, 20))), conn), true);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (db::Trans (db::Vector (0, 1000))), conn), true);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (db::Trans (db::Vector (0, 1001))), conn), false);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (db::Trans (db::Vector (0, 2000))), conn), false);
|
||||
|
||||
cluster.clear ();
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (), conn), false);
|
||||
}
|
||||
|
||||
TEST(11_LocalClusterInteractDifferentLayers)
|
||||
{
|
||||
db::GenericRepository repo;
|
||||
|
||||
db::Connectivity conn;
|
||||
conn.connect (0);
|
||||
conn.connect (1);
|
||||
conn.connect (2);
|
||||
conn.connect (0, 1);
|
||||
conn.connect (0, 2);
|
||||
|
||||
db::Polygon poly;
|
||||
tl::from_string ("(0,0;0,1000;1000,1000;1000,0)", poly);
|
||||
|
||||
db::local_cluster<db::PolygonRef> cluster;
|
||||
db::local_cluster<db::PolygonRef> cluster2;
|
||||
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (), conn), false);
|
||||
|
||||
cluster.add (db::PolygonRef (poly, repo), 0);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (), conn), false);
|
||||
|
||||
cluster2.add (db::PolygonRef (poly, repo), 1);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (), conn), true);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (db::Trans (db::Vector (10, 20))), conn), true);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (db::Trans (db::Vector (0, 1000))), conn), true);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (db::Trans (db::Vector (0, 1001))), conn), false);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (db::Trans (db::Vector (0, 2000))), conn), false);
|
||||
|
||||
cluster.clear ();
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (), conn), false);
|
||||
cluster.add (db::PolygonRef (poly, repo), 2);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (), conn), false); // not connected
|
||||
|
||||
cluster.clear ();
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (), conn), false);
|
||||
cluster.add (db::PolygonRef (poly, repo), 1);
|
||||
EXPECT_EQ (cluster.interacts (cluster2, db::ICplxTrans (), conn), true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue