mirror of https://github.com/KLayout/klayout.git
238 lines
6.3 KiB
C++
238 lines
6.3 KiB
C++
|
|
|
||
|
|
|
||
|
|
/*
|
||
|
|
|
||
|
|
KLayout Layout Viewer
|
||
|
|
Copyright (C) 2006-2020 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 "tlString.h"
|
||
|
|
|
||
|
|
#include "dbRegionUtils.h"
|
||
|
|
|
||
|
|
namespace tl
|
||
|
|
{
|
||
|
|
|
||
|
|
template <class Iter>
|
||
|
|
std::string to_string (Iter b, Iter e)
|
||
|
|
{
|
||
|
|
std::string res;
|
||
|
|
for (Iter i = b; i != e; ++i) {
|
||
|
|
if (i != b) {
|
||
|
|
res += ",";
|
||
|
|
}
|
||
|
|
res += tl::to_string (*i);
|
||
|
|
}
|
||
|
|
return res;
|
||
|
|
}
|
||
|
|
|
||
|
|
template <class T>
|
||
|
|
std::string to_string (const std::vector<T> &v)
|
||
|
|
{
|
||
|
|
return to_string (v.begin (), v.end ());
|
||
|
|
}
|
||
|
|
|
||
|
|
template <class T>
|
||
|
|
std::string to_string (const std::list<T> &v)
|
||
|
|
{
|
||
|
|
return to_string (v.begin (), v.end ());
|
||
|
|
}
|
||
|
|
|
||
|
|
template <class T>
|
||
|
|
std::string to_string (const std::set<T> &v)
|
||
|
|
{
|
||
|
|
return to_string (v.begin (), v.end ());
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST(1_SimpleLShape)
|
||
|
|
{
|
||
|
|
std::set<db::EdgePair> ep;
|
||
|
|
std::set<db::Edge> ee1, ee2;
|
||
|
|
|
||
|
|
db::EdgeRelationFilter er (db::WidthRelation, 1001, db::Projection);
|
||
|
|
|
||
|
|
db::edge2edge_check_with_negative_output<std::set<db::EdgePair>, std::set<db::Edge> > e2e (er, ep, ee1, ee2, false, false, false);
|
||
|
|
|
||
|
|
db::Point pts[] = {
|
||
|
|
db::Point (0, 0),
|
||
|
|
db::Point (0, 2000),
|
||
|
|
db::Point (2000, 2000),
|
||
|
|
db::Point (2000, 1000),
|
||
|
|
db::Point (1000, 1000),
|
||
|
|
db::Point (1000, 0)
|
||
|
|
};
|
||
|
|
|
||
|
|
db::Polygon poly;
|
||
|
|
poly.assign_hull (pts, pts + sizeof (pts) / sizeof (pts[0]));
|
||
|
|
|
||
|
|
db::poly2poly_check_base<db::Polygon> poly_check (e2e);
|
||
|
|
|
||
|
|
do {
|
||
|
|
// single polygon check
|
||
|
|
poly_check.enter (poly, 0);
|
||
|
|
} while (e2e.prepare_next_pass ());
|
||
|
|
|
||
|
|
EXPECT_EQ (tl::to_string (ep), "(0,0;0,1000)/(1000,1000;1000,0),(1000,2000;2000,2000)/(2000,1000;1000,1000)");
|
||
|
|
EXPECT_EQ (tl::to_string (ee1), "");
|
||
|
|
EXPECT_EQ (tl::to_string (ee2), "");
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST(2_SimpleLWithBigPart)
|
||
|
|
{
|
||
|
|
std::set<db::EdgePair> ep;
|
||
|
|
std::set<db::Edge> ee1, ee2;
|
||
|
|
|
||
|
|
db::EdgeRelationFilter er (db::WidthRelation, 1001, db::Projection);
|
||
|
|
|
||
|
|
db::edge2edge_check_with_negative_output<std::set<db::EdgePair>, std::set<db::Edge> > e2e (er, ep, ee1, ee2, false, false, false);
|
||
|
|
|
||
|
|
db::Point pts[] = {
|
||
|
|
db::Point (0, 0),
|
||
|
|
db::Point (0, 2500),
|
||
|
|
db::Point (2000, 2500),
|
||
|
|
db::Point (2000, 1000),
|
||
|
|
db::Point (1000, 1000),
|
||
|
|
db::Point (1000, 0)
|
||
|
|
};
|
||
|
|
|
||
|
|
db::Polygon poly;
|
||
|
|
poly.assign_hull (pts, pts + sizeof (pts) / sizeof (pts[0]));
|
||
|
|
|
||
|
|
db::poly2poly_check_base<db::Polygon> poly_check (e2e);
|
||
|
|
|
||
|
|
do {
|
||
|
|
// single polygon check
|
||
|
|
poly_check.enter (poly, 0);
|
||
|
|
} while (e2e.prepare_next_pass ());
|
||
|
|
|
||
|
|
EXPECT_EQ (tl::to_string (ep), "(0,0;0,1000)/(1000,1000;1000,0)");
|
||
|
|
EXPECT_EQ (tl::to_string (ee1), "(0,1000;0,2500),(2000,1000;1000,1000),(0,2500;2000,2500),(2000,2500;2000,1000)");
|
||
|
|
EXPECT_EQ (tl::to_string (ee2), "");
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST(3_SimpleTWithBigPart)
|
||
|
|
{
|
||
|
|
std::set<db::EdgePair> ep;
|
||
|
|
std::set<db::Edge> ee1, ee2;
|
||
|
|
|
||
|
|
db::EdgeRelationFilter er (db::WidthRelation, 1001, db::Projection);
|
||
|
|
|
||
|
|
db::edge2edge_check_with_negative_output<std::set<db::EdgePair>, std::set<db::Edge> > e2e (er, ep, ee1, ee2, false, false, false);
|
||
|
|
|
||
|
|
db::Point pts[] = {
|
||
|
|
db::Point (0, 0),
|
||
|
|
db::Point (0, 3500),
|
||
|
|
db::Point (1000, 3500),
|
||
|
|
db::Point (1000, 2500),
|
||
|
|
db::Point (2000, 2500),
|
||
|
|
db::Point (2000, 1000),
|
||
|
|
db::Point (1000, 1000),
|
||
|
|
db::Point (1000, 0)
|
||
|
|
};
|
||
|
|
|
||
|
|
db::Polygon poly;
|
||
|
|
poly.assign_hull (pts, pts + sizeof (pts) / sizeof (pts[0]));
|
||
|
|
|
||
|
|
db::poly2poly_check_base<db::Polygon> poly_check (e2e);
|
||
|
|
|
||
|
|
do {
|
||
|
|
// single polygon check
|
||
|
|
poly_check.enter (poly, 0);
|
||
|
|
} while (e2e.prepare_next_pass ());
|
||
|
|
|
||
|
|
EXPECT_EQ (tl::to_string (ep), "(0,0;0,1000)/(1000,1000;1000,0),(0,2500;0,3500)/(1000,3500;1000,2500)");
|
||
|
|
EXPECT_EQ (tl::to_string (ee1), "(0,1000;0,2500),(2000,1000;1000,1000),(1000,2500;2000,2500),(2000,2500;2000,1000)");
|
||
|
|
EXPECT_EQ (tl::to_string (ee2), "");
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST(4_SimpleNotch)
|
||
|
|
{
|
||
|
|
std::set<db::EdgePair> ep;
|
||
|
|
std::set<db::Edge> ee1, ee2;
|
||
|
|
|
||
|
|
db::EdgeRelationFilter er (db::SpaceRelation, 1001, db::Projection);
|
||
|
|
|
||
|
|
db::edge2edge_check_with_negative_output<std::set<db::EdgePair>, std::set<db::Edge> > e2e (er, ep, ee1, ee2, false, false, false);
|
||
|
|
|
||
|
|
db::Point pts[] = {
|
||
|
|
db::Point (0, 0),
|
||
|
|
db::Point (0, 3000),
|
||
|
|
db::Point (2000, 3000),
|
||
|
|
db::Point (2000, 2000),
|
||
|
|
db::Point (1000, 2000),
|
||
|
|
db::Point (1000, 1000),
|
||
|
|
db::Point (2000, 1000),
|
||
|
|
db::Point (2000, 0)
|
||
|
|
};
|
||
|
|
|
||
|
|
db::Polygon poly;
|
||
|
|
poly.assign_hull (pts, pts + sizeof (pts) / sizeof (pts[0]));
|
||
|
|
|
||
|
|
db::poly2poly_check_base<db::Polygon> poly_check (e2e);
|
||
|
|
|
||
|
|
do {
|
||
|
|
// single polygon check
|
||
|
|
poly_check.enter (poly, 0);
|
||
|
|
} while (e2e.prepare_next_pass ());
|
||
|
|
|
||
|
|
EXPECT_EQ (tl::to_string (ep), "(2000,2000;1000,2000)/(1000,1000;2000,1000)");
|
||
|
|
EXPECT_EQ (tl::to_string (ee1), "(0,0;0,3000),(2000,0;0,0),(2000,1000;2000,0),(0,3000;2000,3000),(2000,3000;2000,2000)");
|
||
|
|
EXPECT_EQ (tl::to_string (ee2), "");
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST(5_LShapeNotch)
|
||
|
|
{
|
||
|
|
std::set<db::EdgePair> ep;
|
||
|
|
std::set<db::Edge> ee1, ee2;
|
||
|
|
|
||
|
|
db::EdgeRelationFilter er (db::SpaceRelation, 1001, db::Projection);
|
||
|
|
|
||
|
|
db::edge2edge_check_with_negative_output<std::set<db::EdgePair>, std::set<db::Edge> > e2e (er, ep, ee1, ee2, false, false, false);
|
||
|
|
|
||
|
|
db::Point pts[] = {
|
||
|
|
db::Point (0, 0),
|
||
|
|
db::Point (0, 3000),
|
||
|
|
db::Point (2000, 3000),
|
||
|
|
db::Point (2000, 1500),
|
||
|
|
db::Point (1500, 1500),
|
||
|
|
db::Point (1500, 2500),
|
||
|
|
db::Point (500, 2500),
|
||
|
|
db::Point (500, 500),
|
||
|
|
db::Point (2000, 500),
|
||
|
|
db::Point (2000, 0)
|
||
|
|
};
|
||
|
|
|
||
|
|
db::Polygon poly;
|
||
|
|
poly.assign_hull (pts, pts + sizeof (pts) / sizeof (pts[0]));
|
||
|
|
|
||
|
|
db::poly2poly_check_base<db::Polygon> poly_check (e2e);
|
||
|
|
|
||
|
|
do {
|
||
|
|
// single polygon check
|
||
|
|
poly_check.enter (poly, 0);
|
||
|
|
} while (e2e.prepare_next_pass ());
|
||
|
|
|
||
|
|
EXPECT_EQ (tl::to_string (ep), "(0,0;0,3000),(2000,0;0,0),(2000,500;2000,0),(0,3000;2000,3000),(2000,3000;2000,1500)");
|
||
|
|
EXPECT_EQ (tl::to_string (ee1), "");
|
||
|
|
EXPECT_EQ (tl::to_string (ee2), "");
|
||
|
|
}
|