Some convenience features: transformations in EdgeNeighborhood, added Matrix transformation support for edge pairs.

This commit is contained in:
Matthias Koefferlein
2024-11-01 17:34:46 +01:00
parent 2629700566
commit dd0949867f
7 changed files with 140 additions and 20 deletions
+54
View File
@@ -56,8 +56,31 @@ class MyVisitor < RBA::EdgeNeighborhoodVisitor
end
class MyVisitor2 < RBA::EdgeNeighborhoodVisitor
def initialize
self.result_type = RBA::CompoundRegionOperationNode::ResultType::EdgePairs
end
def on_edge(layout, cell, edge, neighborhood)
neighborhood.each do |n|
polygons = n[1]
polygons.each do |inp, poly|
poly.each do |p|
bbox = p.bbox
t = self.to_original_trans(edge)
ep = RBA::EdgePair::new(edge, t * RBA::Edge::new(bbox.p1, RBA::Point::new(bbox.right, bbox.bottom)))
output(ep)
end
end
end
end
end
class DBEdgeNeighborhood_TestClass < TestBase
# basic events
def test_1
ly = RBA::Layout::new
@@ -108,6 +131,37 @@ class DBEdgeNeighborhood_TestClass < TestBase
end
# edge pair output, to_original_trans
def test_2
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 = MyVisitor2::new
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(res.to_s, "(-100,1000;-100,0)/(0,1000;0,0);(0,0;0,1000)/(-100,0;-100,1000)")
end
end
load("test_epilogue.rb")
+4
View File
@@ -253,6 +253,7 @@ class DBMatrix_TestClass < TestBase
assert_equal((m * RBA::Polygon::new(RBA::Box::new(-5, -10, 10, 20))).to_s, "(5,-25;-10,-18;5,43;20,35)")
assert_equal((m * RBA::SimplePolygon::new(RBA::Box::new(-5, -10, 10, 20))).to_s, "(5,-25;-10,-18;5,43;20,35)")
assert_equal((m * RBA::Edge::new(RBA::Point::new(-5, -10), RBA::Point::new(10, 20))).to_s, "(-10,-18;20,35)")
assert_equal((m * RBA::EdgePair::new(RBA::Edge::new(RBA::Point::new(0, -10), RBA::Point::new(15, 20)), RBA::Edge::new(RBA::Point::new(-5, -10), RBA::Point::new(10, 20)))).to_s, "(-5,-20;25,33)/(-10,-18;20,35)")
assert_equal(RBA::Region::new(RBA::Box::new(-5, -10, 10, 20)).transformed(m).to_s, "(5,-25;-10,-18;5,43;20,35)")
r = RBA::Region::new(RBA::Box::new(-5, -10, 10, 20))
r.transform(m)
@@ -273,6 +274,7 @@ class DBMatrix_TestClass < TestBase
assert_equal((m * RBA::DPolygon::new(RBA::DBox::new(-5, -10, 10, 20))).to_s, "(5,-25;-10,-17.5;5,42.5;20,35)")
assert_equal((m * RBA::DSimplePolygon::new(RBA::DBox::new(-5, -10, 10, 20))).to_s, "(5,-25;-10,-17.5;5,42.5;20,35)")
assert_equal((m * RBA::DEdge::new(RBA::DPoint::new(-5, -10), RBA::DPoint::new(10, 20))).to_s, "(-10,-17.5;20,35)")
assert_equal((m * RBA::DEdgePair::new(RBA::DEdge::new(RBA::DPoint::new(0, -10), RBA::DPoint::new(15, 20)), RBA::DEdge::new(RBA::DPoint::new(-5, -10), RBA::DPoint::new(10, 20)))).to_s, "(-5,-20;25,32.5)/(-10,-17.5;20,35)")
m = RBA::IMatrix3d::new(1.0, 0.5, 1.0, -0.5, 2.0, 0.0, 0.0, 0.0, 1.0)
assert_equal((m * RBA::Point::new(10, 20)).to_s, "21,35")
@@ -281,6 +283,7 @@ class DBMatrix_TestClass < TestBase
assert_equal((m * RBA::Polygon::new(RBA::Box::new(-5, -10, 10, 20))).to_s, "(6,-25;-9,-18;6,43;21,35)")
assert_equal((m * RBA::SimplePolygon::new(RBA::Box::new(-5, -10, 10, 20))).to_s, "(6,-25;-9,-18;6,43;21,35)")
assert_equal((m * RBA::Edge::new(RBA::Point::new(-5, -10), RBA::Point::new(10, 20))).to_s, "(-9,-18;21,35)")
assert_equal((m * RBA::EdgePair::new(RBA::Edge::new(RBA::Point::new(0, -10), RBA::Point::new(15, 20)), RBA::Edge::new(RBA::Point::new(-5, -10), RBA::Point::new(10, 20)))).to_s, "(-4,-20;26,33)/(-9,-18;21,35)")
assert_equal(RBA::Region::new(RBA::Box::new(-5, -10, 10, 20)).transformed(m).to_s, "(6,-25;-9,-18;6,43;21,35)")
r = RBA::Region::new(RBA::Box::new(-5, -10, 10, 20))
r.transform(m)
@@ -301,6 +304,7 @@ class DBMatrix_TestClass < TestBase
assert_equal((m * RBA::DPolygon::new(RBA::DBox::new(-5, -10, 10, 20))).to_s, "(6,-25;-9,-17.5;6,42.5;21,35)")
assert_equal((m * RBA::DSimplePolygon::new(RBA::DBox::new(-5, -10, 10, 20))).to_s, "(6,-25;-9,-17.5;6,42.5;21,35)")
assert_equal((m * RBA::DEdge::new(RBA::DPoint::new(-5, -10), RBA::DPoint::new(10, 20))).to_s, "(-9,-17.5;21,35)")
assert_equal((m * RBA::DEdgePair::new(RBA::DEdge::new(RBA::DPoint::new(0, -10), RBA::DPoint::new(15, 20)), RBA::DEdge::new(RBA::DPoint::new(-5, -10), RBA::DPoint::new(10, 20)))).to_s, "(-4,-20;26,32.5)/(-9,-17.5;21,35)")
end