mirror of https://github.com/KLayout/klayout.git
Debugging, Tests
This commit is contained in:
parent
9cd29c9de7
commit
1379d30502
|
|
@ -419,6 +419,7 @@ ConvexDecomposition::hertel_mehlhorn_decomposition (Triangulation &tris, const C
|
|||
for (auto i = iv->begin (); i != iv->end (); ++i) {
|
||||
poly->add_internal_vertex (*i);
|
||||
}
|
||||
++iv;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,14 +29,6 @@
|
|||
namespace pex
|
||||
{
|
||||
|
||||
SquareCountingRExtractor::SquareCountingRExtractor (double dbu)
|
||||
{
|
||||
m_dbu = dbu;
|
||||
|
||||
m_decomp_param.split_edges = true;
|
||||
m_decomp_param.with_segments = false;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
|
|
@ -66,37 +58,6 @@ private:
|
|||
std::map<size_t, std::set<size_t> > m_interactions;
|
||||
};
|
||||
|
||||
struct PortDefinition
|
||||
{
|
||||
PortDefinition ()
|
||||
: type (pex::RNode::Internal), port_index (0)
|
||||
{ }
|
||||
|
||||
PortDefinition (pex::RNode::node_type _type, const db::Point &_location, unsigned int _port_index)
|
||||
: type (_type), location (_location), port_index (_port_index)
|
||||
{ }
|
||||
|
||||
bool operator< (const PortDefinition &other) const
|
||||
{
|
||||
if (type != other.type) {
|
||||
return type < other.type;
|
||||
}
|
||||
if (port_index != other.port_index) {
|
||||
return port_index < other.port_index;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator== (const PortDefinition &other) const
|
||||
{
|
||||
return type == other.type && port_index == other.port_index;
|
||||
}
|
||||
|
||||
pex::RNode::node_type type;
|
||||
db::Point location;
|
||||
unsigned int port_index;
|
||||
};
|
||||
|
||||
struct JoinEdgeSets
|
||||
{
|
||||
void operator() (std::set<db::Edge> &a, const std::set<db::Edge> &b) const
|
||||
|
|
@ -107,6 +68,14 @@ struct JoinEdgeSets
|
|||
|
||||
}
|
||||
|
||||
SquareCountingRExtractor::SquareCountingRExtractor (double dbu)
|
||||
{
|
||||
m_dbu = dbu;
|
||||
|
||||
m_decomp_param.split_edges = true;
|
||||
m_decomp_param.with_segments = false;
|
||||
}
|
||||
|
||||
static
|
||||
double yatx (const db::Edge &e, int x)
|
||||
{
|
||||
|
|
@ -141,8 +110,8 @@ double calculate_squares (db::Coord x1, db::Coord x2, const std::set<db::Edge> &
|
|||
}
|
||||
}
|
||||
|
||||
static
|
||||
void rextract_square_counting (const db::Polygon &db_poly, const std::vector<std::pair<PortDefinition, pex::RNode *> > &ports, pex::RNetwork &rnetwork, double /*dbu*/)
|
||||
void
|
||||
SquareCountingRExtractor::do_extract (const db::Polygon &db_poly, const std::vector<std::pair<PortDefinition, pex::RNode *> > &ports, pex::RNetwork &rnetwork)
|
||||
{
|
||||
// "trans" will orient the polygon to be flat rather than tall
|
||||
db::Trans trans;
|
||||
|
|
@ -189,7 +158,7 @@ void rextract_square_counting (const db::Polygon &db_poly, const std::vector<std
|
|||
|
||||
auto em = edges.find (c);
|
||||
while (em != edges.end () && em->first.first < cc) {
|
||||
r += calculate_squares (em->first.first, std::min (cc, em->first.second), em->second);
|
||||
r += calculate_squares (std::max (c, em->first.first), std::min (cc, em->first.second), em->second);
|
||||
++em;
|
||||
}
|
||||
|
||||
|
|
@ -320,7 +289,7 @@ SquareCountingRExtractor::extract (const db::Polygon &polygon, const std::vector
|
|||
p->second = n4p->second;
|
||||
}
|
||||
|
||||
rextract_square_counting (db_poly, ports, rnetwork, dbu ());
|
||||
do_extract (db_poly, ports, rnetwork);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,43 @@ public:
|
|||
|
||||
virtual void extract (const db::Polygon &polygon, const std::vector<db::Point> &vertex_ports, const std::vector<db::Polygon> &polygon_ports, RNetwork &rnetwork);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief A helper structure defining a port
|
||||
*/
|
||||
struct PortDefinition
|
||||
{
|
||||
PortDefinition ()
|
||||
: type (pex::RNode::Internal), port_index (0)
|
||||
{ }
|
||||
|
||||
PortDefinition (pex::RNode::node_type _type, const db::Point &_location, unsigned int _port_index)
|
||||
: type (_type), location (_location), port_index (_port_index)
|
||||
{ }
|
||||
|
||||
bool operator< (const PortDefinition &other) const
|
||||
{
|
||||
if (type != other.type) {
|
||||
return type < other.type;
|
||||
}
|
||||
if (port_index != other.port_index) {
|
||||
return port_index < other.port_index;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator== (const PortDefinition &other) const
|
||||
{
|
||||
return type == other.type && port_index == other.port_index;
|
||||
}
|
||||
|
||||
pex::RNode::node_type type;
|
||||
db::Point location;
|
||||
unsigned int port_index;
|
||||
};
|
||||
|
||||
void do_extract (const db::Polygon &db_poly, const std::vector<std::pair<PortDefinition, pex::RNode *> > &ports, pex::RNetwork &rnetwork);
|
||||
|
||||
private:
|
||||
db::plc::ConvexDecompositionParameters m_decomp_param;
|
||||
double m_dbu;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,87 @@
|
|||
#include "pexSquareCountingRExtractor.h"
|
||||
#include "tlUnitTest.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
class TestableSquareCountingRExtractor
|
||||
: public pex::SquareCountingRExtractor
|
||||
{
|
||||
public:
|
||||
TestableSquareCountingRExtractor ()
|
||||
: pex::SquareCountingRExtractor (0.001)
|
||||
{ }
|
||||
|
||||
using pex::SquareCountingRExtractor::PortDefinition;
|
||||
using pex::SquareCountingRExtractor::do_extract;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
TEST(basic)
|
||||
{
|
||||
db::Point contour[] = {
|
||||
db::Point (0, 0),
|
||||
db::Point (0, 100),
|
||||
db::Point (1000, 1000),
|
||||
db::Point (2100, 1000),
|
||||
db::Point (2100, 0)
|
||||
};
|
||||
|
||||
db::Polygon poly;
|
||||
poly.assign_hull (contour + 0, contour + sizeof (contour) / sizeof (contour[0]));
|
||||
TestableSquareCountingRExtractor rex;
|
||||
pex::RNetwork rn;
|
||||
|
||||
TestableSquareCountingRExtractor::PortDefinition pd1 (pex::RNode::Internal, db::Point (-50, 50), 0);
|
||||
TestableSquareCountingRExtractor::PortDefinition pd2 (pex::RNode::Internal, db::Point (1000, 100), 1);
|
||||
TestableSquareCountingRExtractor::PortDefinition pd3 (pex::RNode::Internal, db::Point (1000, 500), 2);
|
||||
TestableSquareCountingRExtractor::PortDefinition pd4 (pex::RNode::Internal, db::Point (2000, 500), 3);
|
||||
|
||||
std::vector<TestableSquareCountingRExtractor::PortDefinition> pds;
|
||||
pds.push_back (TestableSquareCountingRExtractor::PortDefinition (pex::RNode::Internal, db::Point (0, 50), 0));
|
||||
pds.push_back (TestableSquareCountingRExtractor::PortDefinition (pex::RNode::Internal, db::Point (1000, 100), 1));
|
||||
pds.push_back (TestableSquareCountingRExtractor::PortDefinition (pex::RNode::Internal, db::Point (1000, 500), 2));
|
||||
pds.push_back (TestableSquareCountingRExtractor::PortDefinition (pex::RNode::Internal, db::Point (2000, 500), 3));
|
||||
|
||||
std::vector<std::pair<TestableSquareCountingRExtractor::PortDefinition, pex::RNode *> > ports;
|
||||
for (auto pd = pds.begin (); pd != pds.end (); ++pd) {
|
||||
ports.push_back (std::make_pair (*pd, rn.create_node (pd->type, pd->port_index)));
|
||||
}
|
||||
|
||||
rex.do_extract (poly, ports, rn);
|
||||
|
||||
EXPECT_EQ (rn.to_string (),
|
||||
"R $0 $1 0.390865\n" // w ramp w=100 to 1000 over x=0 to 1000 (squares = (x2-x1)/(w2-w1)*log(w2/w1) by integration)
|
||||
"R $1 $2 0\n" // transition from y=50 to y=500 parallel to current direction
|
||||
"R $2 $3 1" // 1 square between x=1000 and 2000 (w=1000)
|
||||
);
|
||||
|
||||
// After rotation
|
||||
|
||||
rn.clear ();
|
||||
|
||||
db::Trans r90 (db::Trans::r90);
|
||||
|
||||
poly.transform (r90);
|
||||
|
||||
ports.clear ();
|
||||
for (auto pd = pds.begin (); pd != pds.end (); ++pd) {
|
||||
ports.push_back (std::make_pair (*pd, rn.create_node (pd->type, pd->port_index)));
|
||||
ports.back ().first.location.transform (r90);
|
||||
}
|
||||
|
||||
rex.do_extract (poly, ports, rn);
|
||||
|
||||
// Same network, but opposite order. $1 and $2 are shorted, hence can be swapped.
|
||||
EXPECT_EQ (rn.to_string (),
|
||||
"R $3 $1 1\n"
|
||||
"R $1 $2 0\n"
|
||||
"R $2 $0 0.390865"
|
||||
);
|
||||
}
|
||||
|
||||
TEST(extraction)
|
||||
{
|
||||
db::Point contour[] = {
|
||||
db::Point (0, 0),
|
||||
|
|
@ -46,15 +126,17 @@ TEST(basic)
|
|||
pex::SquareCountingRExtractor rex (dbu);
|
||||
|
||||
std::vector<db::Point> vertex_ports;
|
||||
vertex_ports.push_back (db::Point (0, 50));
|
||||
vertex_ports.push_back (db::Point (1650, 50));
|
||||
vertex_ports.push_back (db::Point (0, 50)); // V0
|
||||
vertex_ports.push_back (db::Point (1650, 50)); // V1
|
||||
|
||||
std::vector<db::Polygon> polygon_ports;
|
||||
polygon_ports.push_back (db::Polygon (db::Box (1000, 900, 1100, 1000)));
|
||||
polygon_ports.push_back (db::Polygon (db::Box (1000, 900, 1100, 1000))); // P0
|
||||
|
||||
rex.extract (poly, vertex_ports, polygon_ports, rn);
|
||||
|
||||
EXPECT_EQ (rn.to_string (),
|
||||
""
|
||||
"R V0 $0 0.0952381\n"
|
||||
"R $0 V1 0.166667\n"
|
||||
"R P0 $0 0.117647"
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue