2018-12-01 09:38:16 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
KLayout Layout Viewer
|
|
|
|
|
Copyright (C) 2006-2018 Matthias Koefferlein
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "tlUnitTest.h"
|
|
|
|
|
#include "dbHierNetworkProcessor.h"
|
|
|
|
|
#include "dbTestSupport.h"
|
|
|
|
|
#include "dbShapeRepository.h"
|
|
|
|
|
#include "dbPolygon.h"
|
|
|
|
|
#include "dbPath.h"
|
|
|
|
|
#include "dbText.h"
|
|
|
|
|
|
|
|
|
|
static std::string l2s (db::Connectivity::layer_iterator b, db::Connectivity::layer_iterator e)
|
|
|
|
|
{
|
|
|
|
|
std::string s;
|
|
|
|
|
for (db::Connectivity::layer_iterator i = b; i != e; ++i) {
|
|
|
|
|
if (! s.empty ()) {
|
|
|
|
|
s += ",";
|
|
|
|
|
}
|
|
|
|
|
s += tl::to_string (*i);
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(1_Connectivity)
|
|
|
|
|
{
|
|
|
|
|
db::Connectivity conn;
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ (l2s (conn.begin_layers (), conn.end_layers ()), "");
|
|
|
|
|
|
|
|
|
|
conn.connect (0);
|
|
|
|
|
EXPECT_EQ (l2s (conn.begin_layers (), conn.end_layers ()), "0");
|
|
|
|
|
EXPECT_EQ (l2s (conn.begin_connected (0), conn.end_connected (0)), "0");
|
|
|
|
|
EXPECT_EQ (l2s (conn.begin_connected (1), conn.end_connected (1)), "");
|
|
|
|
|
|
|
|
|
|
conn.connect (0, 1);
|
|
|
|
|
EXPECT_EQ (l2s (conn.begin_layers (), conn.end_layers ()), "0,1");
|
|
|
|
|
EXPECT_EQ (l2s (conn.begin_connected (0), conn.end_connected (0)), "0,1");
|
|
|
|
|
EXPECT_EQ (l2s (conn.begin_connected (1), conn.end_connected (1)), "0");
|
|
|
|
|
|
|
|
|
|
conn.connect (1);
|
|
|
|
|
EXPECT_EQ (l2s (conn.begin_connected (1), conn.end_connected (1)), "0,1");
|
|
|
|
|
|
|
|
|
|
conn.connect (0, 2);
|
|
|
|
|
conn.connect (2);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ (l2s (conn.begin_connected (0), conn.end_connected (0)), "0,1,2");
|
|
|
|
|
EXPECT_EQ (l2s (conn.begin_connected (1), conn.end_connected (1)), "0,1");
|
|
|
|
|
EXPECT_EQ (l2s (conn.begin_connected (2), conn.end_connected (2)), "0,2");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(2_ShapeInteractions)
|
|
|
|
|
{
|
|
|
|
|
db::Connectivity conn;
|
|
|
|
|
|
|
|
|
|
conn.connect (0);
|
|
|
|
|
conn.connect (1);
|
|
|
|
|
conn.connect (0, 1);
|
|
|
|
|
|
|
|
|
|
db::Polygon poly;
|
|
|
|
|
tl::from_string ("(0,0;0,1000;1000,1000;1000,0)", poly);
|
|
|
|
|
db::GenericRepository repo;
|
|
|
|
|
db::PolygonRef ref1 (poly, repo);
|
2018-12-02 01:30:56 +01:00
|
|
|
db::ICplxTrans t2 (db::Trans (db::Vector (0, 10)));
|
|
|
|
|
db::PolygonRef ref2 (poly.transformed (t2), repo);
|
|
|
|
|
db::ICplxTrans t3 (db::Trans (db::Vector (0, 2000)));
|
|
|
|
|
db::PolygonRef ref3 (poly.transformed (t3), repo);
|
2018-12-01 09:38:16 +01:00
|
|
|
|
|
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref2, 0), true);
|
2018-12-02 01:30:56 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref1, 0, t2), true); // t2*ref1 == ref2
|
2018-12-01 09:38:16 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref2, 1), true);
|
2018-12-02 01:30:56 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref1, 1, t2), true);
|
2018-12-01 09:38:16 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 1, ref2, 0), true);
|
2018-12-02 01:30:56 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 1, ref1, 0, t2), true);
|
2018-12-01 09:38:16 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref3, 0), false);
|
2018-12-02 01:30:56 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref1, 0, t3), false); // t3*ref1 == ref3
|
2018-12-01 09:38:16 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref3, 1), false);
|
2018-12-02 01:30:56 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref1, 1, t3), false);
|
2018-12-01 09:38:16 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 1, ref2, 2), false);
|
2018-12-02 01:30:56 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 1, ref1, 2, t2), false);
|
2018-12-01 09:38:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(2_ShapeInteractionsRealPolygon)
|
|
|
|
|
{
|
|
|
|
|
db::Connectivity conn;
|
|
|
|
|
|
|
|
|
|
conn.connect (0);
|
|
|
|
|
conn.connect (1);
|
|
|
|
|
conn.connect (0, 1);
|
|
|
|
|
|
|
|
|
|
db::Polygon poly;
|
|
|
|
|
tl::from_string ("(0,0;0,1000;500,1000;500,1500;1000,1500;1000,0)", poly);
|
|
|
|
|
db::GenericRepository repo;
|
|
|
|
|
db::PolygonRef ref1 (poly, repo);
|
2018-12-02 01:30:56 +01:00
|
|
|
db::ICplxTrans t2 (db::Trans (db::Vector (0, 10)));
|
|
|
|
|
db::PolygonRef ref2 (poly.transformed (t2), repo);
|
|
|
|
|
db::ICplxTrans t3 (db::Trans (db::Vector (0, 2000)));
|
|
|
|
|
db::PolygonRef ref3 (poly.transformed (t3), repo);
|
|
|
|
|
db::ICplxTrans t4 (db::Trans (db::Vector (0, 1500)));
|
|
|
|
|
db::PolygonRef ref4 (poly.transformed (t4), repo);
|
2018-12-01 09:38:16 +01:00
|
|
|
|
|
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref2, 0), true);
|
2018-12-02 01:30:56 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref1, 0, t2), true); // t2*ref1 == ref2
|
2018-12-01 09:38:16 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref2, 1), true);
|
2018-12-02 01:30:56 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref1, 1, t2), true);
|
2018-12-01 09:38:16 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 1, ref2, 0), true);
|
2018-12-02 01:30:56 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 1, ref1, 0, t2), true);
|
2018-12-01 09:38:16 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref3, 0), false);
|
2018-12-02 01:30:56 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref1, 0, t3), false);
|
2018-12-01 09:38:16 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref4, 0), true);
|
2018-12-02 01:30:56 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref1, 0, t4), true);
|
2018-12-01 09:38:16 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref3, 1), false);
|
2018-12-02 01:30:56 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 0, ref1, 1, t3), false);
|
2018-12-01 09:38:16 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 1, ref2, 2), false);
|
2018-12-02 01:30:56 +01:00
|
|
|
EXPECT_EQ (conn.interacts (ref1, 1, ref1, 2, t2), false);
|
2018-12-01 09:38:16 +01:00
|
|
|
}
|