Skip to content

Commit 32cdcef

Browse files
Merge pull request #2103 from KLayout/bugfix/issue-2102
Fixing issue #2102 (internal error on R extraction)
2 parents 3c4f800 + b89ff76 commit 32cdcef

5 files changed

Lines changed: 113 additions & 101 deletions

File tree

src/db/db/dbPLCConvexDecomposition.cc

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,6 @@ ConvexDecomposition::decompose (const db::Polygon &poly, const ConvexDecompositi
429429
decompose (poly, parameters, db::CplxTrans (dbu));
430430
}
431431

432-
void
433-
ConvexDecomposition::decompose (const db::Polygon &poly, const std::vector<db::Point> &vertexes, const ConvexDecompositionParameters &parameters, double dbu)
434-
{
435-
decompose (poly, vertexes, parameters, db::CplxTrans (dbu));
436-
}
437-
438432
void
439433
ConvexDecomposition::decompose (const db::Polygon &poly, const ConvexDecompositionParameters &parameters, const db::CplxTrans &trans)
440434
{
@@ -444,15 +438,6 @@ ConvexDecomposition::decompose (const db::Polygon &poly, const ConvexDecompositi
444438
hertel_mehlhorn_decomposition (tri, parameters);
445439
}
446440

447-
void
448-
ConvexDecomposition::decompose (const db::Polygon &poly, const std::vector<db::Point> &vertexes, const ConvexDecompositionParameters &parameters, const db::CplxTrans &trans)
449-
{
450-
Triangulation tri (mp_graph);
451-
tri.triangulate (poly, vertexes, parameters.tri_param, trans);
452-
453-
hertel_mehlhorn_decomposition (tri, parameters);
454-
}
455-
456441
void
457442
ConvexDecomposition::decompose (const db::DPolygon &poly, const ConvexDecompositionParameters &parameters, const db::DCplxTrans &trans)
458443
{
@@ -462,15 +447,6 @@ ConvexDecomposition::decompose (const db::DPolygon &poly, const ConvexDecomposit
462447
hertel_mehlhorn_decomposition (tri, parameters);
463448
}
464449

465-
void
466-
ConvexDecomposition::decompose (const db::DPolygon &poly, const std::vector<db::DPoint> &vertexes, const ConvexDecompositionParameters &parameters, const db::DCplxTrans &trans)
467-
{
468-
Triangulation tri (mp_graph);
469-
tri.triangulate (poly, vertexes, parameters.tri_param, trans);
470-
471-
hertel_mehlhorn_decomposition (tri, parameters);
472-
}
473-
474450
void
475451
ConvexDecomposition::decompose (const db::Region &region, const ConvexDecompositionParameters &parameters, double dbu)
476452
{

src/db/db/dbPLCConvexDecomposition.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,12 @@ class DB_PUBLIC ConvexDecomposition
118118
// more versions
119119
void decompose (const db::Region &region, const ConvexDecompositionParameters &parameters, const db::CplxTrans &trans = db::CplxTrans ());
120120
void decompose (const db::Polygon &poly, const ConvexDecompositionParameters &parameters, double dbu = 1.0);
121-
void decompose (const db::Polygon &poly, const std::vector<db::Point> &vertexes, const ConvexDecompositionParameters &parameters, double dbu = 1.0);
122121
void decompose (const db::Polygon &poly, const ConvexDecompositionParameters &parameters, const db::CplxTrans &trans = db::CplxTrans ());
123-
void decompose (const db::Polygon &poly, const std::vector<db::Point> &vertexes, const ConvexDecompositionParameters &parameters, const db::CplxTrans &trans = db::CplxTrans ());
124122

125123
/**
126124
* @brief Decomposes a floating-point polygon
127125
*/
128126
void decompose (const db::DPolygon &poly, const ConvexDecompositionParameters &parameters, const db::DCplxTrans &trans = db::DCplxTrans ());
129-
void decompose (const db::DPolygon &poly, const std::vector<db::DPoint> &vertexes, const ConvexDecompositionParameters &parameters, const db::DCplxTrans &trans = db::DCplxTrans ());
130127

131128
private:
132129
Graph *mp_graph;

src/db/unit_tests/dbPLCConvexDecompositionTests.cc

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -110,49 +110,6 @@ TEST(basic)
110110
db::compare_layouts (_this, *ly, tl::testdata () + "/algo/hm_decomposition_au4.gds");
111111
}
112112

113-
TEST(internal_vertex)
114-
{
115-
db::plc::Graph plc;
116-
TestableConvexDecomposition decomp (&plc);
117-
118-
db::Point contour[] = {
119-
db::Point (0, 0),
120-
db::Point (0, 100),
121-
db::Point (1000, 100),
122-
db::Point (1000, 0)
123-
};
124-
125-
std::vector<db::Point> vertexes;
126-
vertexes.push_back (db::Point (0, 50)); // on edge
127-
vertexes.push_back (db::Point (200, 70));
128-
vertexes.push_back (db::Point (0, 0)); // on vertex
129-
130-
db::Polygon poly;
131-
poly.assign_hull (contour + 0, contour + sizeof (contour) / sizeof (contour[0]));
132-
133-
double dbu = 0.001;
134-
135-
db::plc::ConvexDecompositionParameters param;
136-
decomp.decompose (poly, vertexes, param, dbu);
137-
138-
EXPECT_EQ (plc.begin () == plc.end (), false);
139-
if (plc.begin () == plc.end ()) {
140-
return;
141-
}
142-
143-
auto p = plc.begin ();
144-
EXPECT_EQ (p->polygon ().to_string (), "(0,0;0,0.05;0,0.1;1,0.1;1,0)");
145-
146-
std::vector<std::string> ip;
147-
for (size_t i = 0; i < p->internal_vertexes (); ++i) {
148-
ip.push_back (p->internal_vertex (i)->to_string () + "#" + tl::join (p->internal_vertex (i)->ids ().begin (), p->internal_vertex (i)->ids ().end (), ","));
149-
}
150-
std::sort (ip.begin (), ip.end ());
151-
EXPECT_EQ (tl::join (ip, "/"), "(0, 0)#2/(0, 0.05)#0/(0.2, 0.07)#1");
152-
153-
EXPECT_EQ (++p == plc.end (), true);
154-
}
155-
156113
TEST(problematic_polygon)
157114
{
158115
db::Point contour[] = {

src/pex/pex/pexSquareCountingRExtractor.cc

Lines changed: 81 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,9 @@ const double infinite_squares = 1e10;
3535
namespace
3636
{
3737

38-
class PolygonPortInteractionReceiver
39-
: public db::box_scanner_receiver2<const db::Polygon, size_t, const db::Polygon, size_t>
38+
class PortInteractionReceiverBase
4039
{
4140
public:
42-
void add (const db::Polygon *obj1, const size_t &index1, const db::Polygon *obj2, const size_t &index2)
43-
{
44-
if (db::interact_pp (*obj1, *obj2)) {
45-
m_interactions[index1].insert (index2);
46-
}
47-
}
48-
4941
const std::set<size_t> &interactions (size_t index) const
5042
{
5143
static std::set<size_t> empty;
@@ -57,10 +49,42 @@ class PolygonPortInteractionReceiver
5749
}
5850
}
5951

52+
protected:
53+
void insert (size_t index1, size_t index2)
54+
{
55+
m_interactions[index1].insert (index2);
56+
}
57+
6058
private:
6159
std::map<size_t, std::set<size_t> > m_interactions;
6260
};
6361

62+
class PolygonPortInteractionReceiver
63+
: public db::box_scanner_receiver2<const db::Polygon, size_t, const db::Polygon, size_t>,
64+
public PortInteractionReceiverBase
65+
{
66+
public:
67+
void add (const db::Polygon *obj1, const size_t &index1, const db::Polygon *obj2, const size_t &index2)
68+
{
69+
if (db::interact_pp (*obj1, *obj2)) {
70+
insert (index1, index2);
71+
}
72+
}
73+
};
74+
75+
class VertexPortInteractionReceiver
76+
: public db::box_scanner_receiver2<const db::Polygon, size_t, const db::Point, size_t>,
77+
public PortInteractionReceiverBase
78+
{
79+
public:
80+
void add (const db::Polygon *obj1, const size_t &index1, const db::Point *obj2, const size_t &index2)
81+
{
82+
if (obj1->box ().contains (*obj2) && db::inside_poly (obj1->begin_edge (), *obj2) >= 0) {
83+
insert (index1, index2);
84+
}
85+
}
86+
};
87+
6488
struct JoinEdgeSets
6589
{
6690
void operator() (std::set<db::Edge> &a, const std::set<db::Edge> &b) const
@@ -188,30 +212,60 @@ SquareCountingRExtractor::extract (const db::Polygon &polygon, const std::vector
188212
db::plc::Graph plc;
189213

190214
db::plc::ConvexDecomposition decomp (&plc);
191-
decomp.decompose (polygon, vertex_ports, m_decomp_param, trans);
215+
decomp.decompose (polygon, m_decomp_param, trans);
192216

193-
// Set up a scanner to detect interactions between polygon ports
194-
// and decomposed polygons
195-
196-
db::box_scanner2<const db::Polygon, size_t, const db::Polygon, size_t> scanner;
217+
// create a heap for the scanners
197218

198219
std::vector<std::pair<db::Polygon, const db::plc::Polygon *> > decomp_polygons;
199220
for (auto p = plc.begin (); p != plc.end (); ++p) {
200221
decomp_polygons.push_back (std::make_pair (db::Polygon (), p.operator-> ()));
201222
decomp_polygons.back ().first = inv_trans * p->polygon ();
202223
}
203224

204-
for (auto i = decomp_polygons.begin (); i != decomp_polygons.end (); ++i) {
205-
scanner.insert1 (&i->first, i - decomp_polygons.begin ());
206-
}
225+
// Set up a scanner to detect interactions between polygon ports
226+
// and decomposed polygons
227+
228+
PolygonPortInteractionReceiver interactions_pp;
229+
230+
if (! decomp_polygons.empty () && ! polygon_ports.empty ()) {
231+
232+
db::box_scanner2<const db::Polygon, size_t, const db::Polygon, size_t> scanner;
233+
234+
for (auto i = decomp_polygons.begin (); i != decomp_polygons.end (); ++i) {
235+
scanner.insert1 (&i->first, i - decomp_polygons.begin ());
236+
}
237+
238+
for (auto i = polygon_ports.begin (); i != polygon_ports.end (); ++i) {
239+
scanner.insert2 (i.operator-> (), i - polygon_ports.begin ());
240+
}
241+
242+
db::box_convert<db::Polygon> bc;
243+
scanner.process (interactions_pp, 1, bc, bc);
207244

208-
for (auto i = polygon_ports.begin (); i != polygon_ports.end (); ++i) {
209-
scanner.insert2 (i.operator-> (), i - polygon_ports.begin ());
210245
}
211246

212-
PolygonPortInteractionReceiver interactions;
213-
db::box_convert<db::Polygon> bc;
214-
scanner.process (interactions, 1, bc, bc);
247+
// Set up a scanner to detect interactions between vertex ports
248+
// and decomposed polygons
249+
250+
VertexPortInteractionReceiver interactions_vp;
251+
252+
if (! decomp_polygons.empty () && ! vertex_ports.empty ()) {
253+
254+
db::box_scanner2<const db::Polygon, size_t, const db::Point, size_t> scanner;
255+
256+
for (auto i = decomp_polygons.begin (); i != decomp_polygons.end (); ++i) {
257+
scanner.insert1 (&i->first, i - decomp_polygons.begin ());
258+
}
259+
260+
for (auto i = vertex_ports.begin (); i != vertex_ports.end (); ++i) {
261+
scanner.insert2 (i.operator-> (), i - vertex_ports.begin ());
262+
}
263+
264+
db::box_convert<db::Polygon> bc1;
265+
db::box_convert<db::Point> bc2;
266+
scanner.process (interactions_vp, 1, bc1, bc2);
267+
268+
}
215269

216270
// Generate the internal ports: those are defined by edges connecting two polygons
217271

@@ -253,8 +307,8 @@ SquareCountingRExtractor::extract (const db::Polygon &polygon, const std::vector
253307
ports.clear ();
254308

255309
const db::Polygon &db_poly = p->first;
256-
const db::plc::Polygon *plc_poly = p->second;
257-
const std::set<size_t> &pp_indexes = interactions.interactions (p - decomp_polygons.begin ());
310+
const std::set<size_t> &pp_indexes = interactions_pp.interactions (p - decomp_polygons.begin ());
311+
const std::set<size_t> &vp_indexes = interactions_vp.interactions (p - decomp_polygons.begin ());
258312
const std::vector<size_t> &ip_indexes = internal_port_indexes [p - decomp_polygons.begin ()];
259313

260314
// set up the ports:
@@ -266,16 +320,12 @@ SquareCountingRExtractor::extract (const db::Polygon &polygon, const std::vector
266320
}
267321

268322
// 2. vertex ports
269-
for (size_t i = 0; i < plc_poly->internal_vertexes (); ++i) {
270-
auto v = plc_poly->internal_vertex (i);
271-
db::Point loc = inv_trans * *v;
272-
for (auto pi = v->ids ().begin (); pi != v->ids ().end (); ++pi) {
273-
ports.push_back (std::make_pair (PortDefinition (pex::RNode::VertexPort, loc, *pi), (pex::RNode *) 0));
274-
}
323+
for (auto i = vp_indexes.begin (); i != vp_indexes.end (); ++i) {
324+
db::Point loc = vertex_ports [*i];
325+
ports.push_back (std::make_pair (PortDefinition (pex::RNode::VertexPort, db::Box (loc, loc), (unsigned int) *i), (pex::RNode *) 0));
275326
}
276327

277328
// 3. polygon ports
278-
// (NOTE: here we only take the center of the bounding box)
279329
for (auto i = pp_indexes.begin (); i != pp_indexes.end (); ++i) {
280330
db::Box loc = polygon_ports [*i].box ();
281331
ports.push_back (std::make_pair (PortDefinition (pex::RNode::PolygonPort, loc, (unsigned int) *i), (pex::RNode *) 0));

src/pex/unit_tests/pexSquareCountingRExtractorTests.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,35 @@ TEST(extraction_meander)
213213
"R V0(0.3,0;0.3,0) V1(4.3,1;4.3,1) 10.0543767445" // that is pretty much the length of the center line / width :)
214214
)
215215
}
216+
217+
TEST(issue_2102)
218+
{
219+
db::Point contour[] = {
220+
db::Point (-85, -610),
221+
db::Point (-85, 610),
222+
db::Point (85, 610),
223+
db::Point (85, 440),
224+
db::Point (65, 440),
225+
db::Point (65, -610)
226+
};
227+
228+
db::Polygon poly;
229+
poly.assign_hull (contour + 0, contour + sizeof (contour) / sizeof (contour[0]));
230+
231+
double dbu = 0.001;
232+
233+
pex::RNetwork rn;
234+
pex::SquareCountingRExtractor rex (dbu);
235+
236+
std::vector<db::Point> vertex_ports;
237+
vertex_ports.push_back (db::Point (0, 525));
238+
vertex_ports.push_back (db::Point (-85, -610));
239+
240+
std::vector<db::Polygon> polygon_ports;
241+
242+
rex.extract (poly, vertex_ports, polygon_ports, rn);
243+
244+
EXPECT_EQ (network2s (rn),
245+
"R V0(0,0.525;0,0.525) V1(-0.085,-0.61;-0.085,-0.61) 7.89600487195" // was crashing before
246+
)
247+
}

0 commit comments

Comments
 (0)