From 262970056651da4f18df6f130c8a7b22db4d2bfe Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Thu, 31 Oct 2024 23:43:27 +0100 Subject: [PATCH] RBA tests, reproducible order of edge events, all edges are reported - even those which do not have neighbors. --- src/db/db/dbEdgeNeighborhood.cc | 26 ++++-- src/rba/unit_tests/rbaTests.cc | 1 + testdata/algo/edge_neighborhood_au2.gds | Bin 4038 -> 4230 bytes testdata/algo/edge_neighborhood_au3.gds | Bin 2566 -> 2822 bytes testdata/algo/edge_neighborhood_au5.gds | Bin 2438 -> 2630 bytes testdata/ruby/dbEdgeNeighborhood.rb | 114 ++++++++++++++++++++++++ 6 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 testdata/ruby/dbEdgeNeighborhood.rb diff --git a/src/db/db/dbEdgeNeighborhood.cc b/src/db/db/dbEdgeNeighborhood.cc index e4c9fbe20..f1318adb6 100644 --- a/src/db/db/dbEdgeNeighborhood.cc +++ b/src/db/db/dbEdgeNeighborhood.cc @@ -117,7 +117,7 @@ EdgeNeighborhoodCompoundOperationNode::EdgeNeighborhoodCompoundOperationNode (co db::Coord EdgeNeighborhoodCompoundOperationNode::computed_dist () const { - return std::max (std::max (m_bext, m_eext), std::max (m_din, m_dout)); + return std::max (std::max (m_bext, m_eext), std::max (m_din, m_dout)) + 1; } std::string @@ -140,25 +140,41 @@ public: // .. nothing yet .. } - void add (const db::Edge *o1, const unsigned int & /*p1*/, const db::Polygon *o2, const unsigned int &p2) + void add (const db::Edge *o1, const unsigned int &p1, const db::Polygon *o2, const unsigned int &p2) { - m_edge_neighbors[o1][p2].push_back (o2); + m_edge_neighbors[p1][p2].push_back (o2); + enter_edge (o1, p1); + } + + void finish1 (const db::Edge *o1, const unsigned int &p1) + { + m_edge_neighbors[p1]; + enter_edge (o1, p1); } void finalize (bool) { for (auto en = m_edge_neighbors.begin (); en != m_edge_neighbors.end (); ++en) { - commit_edge (*en->first, en->second); + commit_edge (m_edges[en->first], en->second); } } private: - std::map > > m_edge_neighbors; + std::map > > m_edge_neighbors; + std::vector m_edges; db::EdgeNeighborhoodVisitor *mp_visitor; const db::Layout *mp_layout; const db::Cell *mp_cell; db::Coord m_bext, m_eext, m_din, m_dout; + void enter_edge (const db::Edge *o1, const unsigned int &p1) + { + while (size_t (p1) >= m_edges.size ()) { + m_edges.push_back (db::Edge ()); + } + m_edges[p1] = *o1; + } + void commit_edge (const db::Edge &edge, const std::map > &neighbors) const { if (edge.is_degenerate ()) { diff --git a/src/rba/unit_tests/rbaTests.cc b/src/rba/unit_tests/rbaTests.cc index c34b71bda..d12563a2f 100644 --- a/src/rba/unit_tests/rbaTests.cc +++ b/src/rba/unit_tests/rbaTests.cc @@ -101,6 +101,7 @@ RUBYTEST (dbEdgePairsTest, "dbEdgePairsTest.rb") RUBYTEST (dbEdgePairTest, "dbEdgePairTest.rb") RUBYTEST (dbEdgesTest, "dbEdgesTest.rb") RUBYTEST (dbEdgeTest, "dbEdgeTest.rb") +RUBYTEST (dbEdgeNeighborhood, "dbEdgeNeighborhood.rb") RUBYTEST (dbGlyphs, "dbGlyphs.rb") RUBYTEST (dbHierNetworkProcessorTests, "dbHierNetworkProcessorTests.rb") RUBYTEST (dbInstanceTest, "dbInstanceTest.rb") diff --git a/testdata/algo/edge_neighborhood_au2.gds b/testdata/algo/edge_neighborhood_au2.gds index 209b56eb017151973a5399418b6c28802bcb28a5..a3be46111b7ffd8780c1bfe61d8ea5cac22f2b9f 100644 GIT binary patch delta 359 zcmX>m-=?U+SLBqt^FHElDi4p@TVSWKo z3X%dT1xmeQ*P1K>H2Dh9)JdF9lXo!kOiti5nH<6aw26J+_>}+|p?t{z delta 251 zcmZouJSMNiz{bGD6u}_F$i)7Ffr~+&L5x9{K@^!iQAu48LvUl%E|$q5tPPVb7zHLj zVKbO4!X_}8gOO+Q2UeEJCTt0lMOYmsPhqp0EX3n9IfQ$k#Q*;{J}@vazkty44*&n( z3}s-DcbNQ&Q)}`R4xmDAph6zI$w6EWlZCjPChq_m_JGS|@)RIngac?8d&A@_KzSif zr^#1<>Vr6(7K`vRPM*T)Fu4M#R)Lp=O}K-Bfx~oiAEWH#}B3!*KFBMzKk3B9lc} z9n>z$Lv({^d58c1FDf8tkm(Tl$-mfUO|D?%nf!p=WbzbthsirYY}PMoa7O?g1JVw1 b42%Xl4(!OuyV&9;OK`4WV`pGsVPOCO%w1>6 delta 119 zcmZn@YZFmoU}IonieQjoWMY58z{McXAjY82V1Ue?sH854A-FMW7t7=jc8AF#taX#O zG4f4*!0~0W2$##`8|*ccr*Jq-u3+SuoWNnSScHvnatPO&$qlRyZ0rmSEG!HFNu?Sp diff --git a/testdata/algo/edge_neighborhood_au5.gds b/testdata/algo/edge_neighborhood_au5.gds index fda0698d3b97e42a8101a9b4788d462703311068..7d1ce189c3d994c550885770f7a845cef5e1ba2c 100644 GIT binary patch delta 198 zcmZn@J|?2Xz{bGD6u}_F$i)7Ffr~+&L7YLAK^U1mQAu48LvUl%F4oB+><*Jf*aEn2 zeE9$Wi^u=}H$F_xV_TxZz`%atKM;Uu1~3rrfYC5<5Ixz7{g#?=2Sf<2OE8^J1*g!VE|GoJadk-T3R8L0} delta 89 zcmX>m(k86Lz{bGD6u}_F$i)7Ffr~+&L5#tKK@XWdQAu48LvUl%F4oB*Yyp#(a0pD^ V!ZvTR5S!EFDeMO}U*RZX1OTAq6G#96 diff --git a/testdata/ruby/dbEdgeNeighborhood.rb b/testdata/ruby/dbEdgeNeighborhood.rb new file mode 100644 index 000000000..5624fc3a8 --- /dev/null +++ b/testdata/ruby/dbEdgeNeighborhood.rb @@ -0,0 +1,114 @@ +# encoding: UTF-8 + +# KLayout Layout Viewer +# Copyright (C) 2006-2024 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 + +if !$:.member?(File::dirname($0)) + $:.push(File::dirname($0)) +end + +load("test_prologue.rb") + +class MyVisitor < RBA::EdgeNeighborhoodVisitor + + def initialize + @log = "" + end + + def log + @log + end + + def begin_polygon(layout, cell, polygon) + output(polygon) + @log += "Polygon: #{polygon}\n" + end + + def end_polygon + @log += "/Polygon\n" + end + + def on_edge(layout, cell, edge, neighborhood) + @log += "edge = #{edge}\n" + neighborhood.each do |n| + x1, x2 = n[0] + polygons = n[1] + polygons.each do |inp, poly| + poly_str = poly.collect { |p| p.to_s }.join("/") + @log += " #{x1},#{x2} -> #{inp}: #{poly_str}\n" + end + end + end + +end + +class DBEdgeNeighborhood_TestClass < TestBase + + def test_1 + + ly = RBA::Layout::new + + l1 = ly.layer(1, 0) + cell = ly.create_cell("TOP") + + cell.shapes(l1).insert(RBA::Box::new(0, 0, 1000, 1000)) + cell.shapes(l1).insert(RBA::Box::new(-1100, 0, -100, 1000)) + + prim = RBA::Region::new(cell.begin_shapes_rec(l1)) + + visitor = MyVisitor::new + + visitor.result_type = RBA::CompoundRegionOperationNode::ResultType::Region + assert_equal(visitor.result_type, RBA::CompoundRegionOperationNode::ResultType::Region) + + bext = 0 + eext = 0 + din = 10 + dout = 100 + + children = [ + RBA::CompoundRegionOperationNode::new_foreign + ] + + node = RBA::CompoundRegionOperationNode::new_edge_neighborhood(children, visitor, bext, eext, din, dout) + res = prim.complex_op(node) + + assert_equal(visitor.log, + "Polygon: (0,0;0,1000;1000,1000;1000,0)\n" + + "edge = (0,0;0,1000)\n" + + " 0.0,1000.0 -> 0: (0,100;0,101;1000,101;1000,100)\n" + + "edge = (0,1000;1000,1000)\n" + + "edge = (1000,1000;1000,0)\n" + + "edge = (1000,0;0,0)\n" + + "/Polygon\n" + + "Polygon: (-1100,0;-1100,1000;-100,1000;-100,0)\n" + + "edge = (-1100,0;-1100,1000)\n" + + "edge = (-1100,1000;-100,1000)\n" + + "edge = (-100,1000;-100,0)\n" + + " 0.0,1000.0 -> 0: (0,100;0,101;1000,101;1000,100)\n" + + "edge = (-100,0;-1100,0)\n" + + "/Polygon\n" + ) + + assert_equal(res.to_s, "(-1100,0;-1100,1000;-100,1000;-100,0);(0,0;0,1000;1000,1000;1000,0)") + + end + +end + +load("test_epilogue.rb") +