From 703a0ee85d740b28bb96b3ed4772baee7b13ce34 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 17 Jul 2017 21:05:38 +0200 Subject: [PATCH] Added "transformed" method to several shape primitives The new version will transform double-coordinate types to integer-coordinate types through a "VCplxTrans". --- src/db/gsiDeclDbBox.cc | 12 ++++++++++- src/db/gsiDeclDbEdge.cc | 10 ++++++++++ src/db/gsiDeclDbEdgePair.cc | 10 ++++++++++ src/db/gsiDeclDbEdges.cc | 7 +++++++ src/db/gsiDeclDbPath.cc | 10 ++++++++++ src/db/gsiDeclDbPolygon.cc | 30 ++++++++++++++++++++++++++++ src/db/gsiDeclDbText.cc | 10 ++++++++++ testdata/ruby/dbBoxTest.rb | 4 ++++ testdata/ruby/dbEdgePairTest.rb | 3 +++ testdata/ruby/dbEdgeTest.rb | 4 ++++ testdata/ruby/dbPathTest.rb | 5 +++++ testdata/ruby/dbPolygonTest.rb | 5 +++++ testdata/ruby/dbSimplePolygonTest.rb | 5 +++++ testdata/ruby/dbTextTest.rb | 5 +++++ 14 files changed, 119 insertions(+), 1 deletion(-) diff --git a/src/db/gsiDeclDbBox.cc b/src/db/gsiDeclDbBox.cc index b2d886139..844ea22df 100644 --- a/src/db/gsiDeclDbBox.cc +++ b/src/db/gsiDeclDbBox.cc @@ -488,7 +488,7 @@ Class decl_Box ("Box", "This method has been introduced in version 0.25." ) + method ("transformed", &db::Box::transformed, - "@brief Transform the box with the given complex transformation\n" + "@brief Transforms the box with the given complex transformation\n" "\n" "@args t\n" "\n" @@ -543,6 +543,16 @@ Class decl_DBox ("DBox", "\n" "This method has been introduced in version 0.25." ) + + method ("transformed", &db::DBox::transformed, + "@brief Transforms the box with the given complex transformation\n" + "\n" + "@args t\n" + "\n" + "@param t The magnifying transformation to apply\n" + "@return The transformed box (in this case an integer coordinate box)\n" + "\n" + "This method has been introduced in version 0.25.\n" + ) + box_defs::methods (), "@brief A box class with floating-point coordinates\n" "\n" diff --git a/src/db/gsiDeclDbEdge.cc b/src/db/gsiDeclDbEdge.cc index 36779b22f..288132a92 100644 --- a/src/db/gsiDeclDbEdge.cc +++ b/src/db/gsiDeclDbEdge.cc @@ -661,6 +661,16 @@ Class decl_DEdge ("DEdge", "\n" "This method has been introduced in version 0.25." ) + + method ("transformed", &db::DEdge::transformed, + "@brief Transforms the edge with the given complex transformation\n" + "\n" + "@args t\n" + "\n" + "@param t The magnifying transformation to apply\n" + "@return The transformed edge (in this case an integer coordinate edge)\n" + "\n" + "This method has been introduced in version 0.25.\n" + ) + edge_defs::methods (), "@brief An edge class\n" "\n" diff --git a/src/db/gsiDeclDbEdgePair.cc b/src/db/gsiDeclDbEdgePair.cc index 50a356f6a..75cd4058e 100644 --- a/src/db/gsiDeclDbEdgePair.cc +++ b/src/db/gsiDeclDbEdgePair.cc @@ -265,6 +265,16 @@ Class decl_DEdgePair ("DEdgePair", "\n" "This method has been introduced in version 0.25." ) + + method ("transformed", &db::DEdgePair::transformed, + "@brief Transforms the edge pair with the given complex transformation\n" + "\n" + "@args t\n" + "\n" + "@param t The magnifying transformation to apply\n" + "@return The transformed edge pair (in this case an integer coordinate edge pair)\n" + "\n" + "This method has been introduced in version 0.25.\n" + ) + edge_pair_defs::methods (), "@brief An edge pair (a pair of two edges)\n" "Edge pairs are objects representing two edges or parts of edges. They play a role mainly in the context " diff --git a/src/db/gsiDeclDbEdges.cc b/src/db/gsiDeclDbEdges.cc index c06f3cc15..bcee1b8a6 100644 --- a/src/db/gsiDeclDbEdges.cc +++ b/src/db/gsiDeclDbEdges.cc @@ -1425,6 +1425,13 @@ Class dec_Edges ("Edges", gsi::iterator ("each", &db::Edges::begin, "@brief Returns each edge of the region\n" ) + + gsi::iterator ("each_merged", &db::Edges::begin_merged, + "@brief Returns each edge of the region\n" + "\n" + "In contrast to \\each, this method delivers merged edges if merge semantics applies while \\each delivers the original edges only.\n" + "\n" + "This method has been introduced in version 0.25." + ) + method ("[]", &db::Edges::nth, "@brief Returns the nth edge of the edge collection\n" "@args n\n" diff --git a/src/db/gsiDeclDbPath.cc b/src/db/gsiDeclDbPath.cc index 06271aa08..81438d032 100644 --- a/src/db/gsiDeclDbPath.cc +++ b/src/db/gsiDeclDbPath.cc @@ -447,6 +447,16 @@ Class decl_DPath ("DPath", "\n" "This method has been introduced in version 0.25." ) + + method ("transformed", &db::DPath::transformed, + "@brief Transforms the polygon with the given complex transformation\n" + "\n" + "@args t\n" + "\n" + "@param t The magnifying transformation to apply\n" + "@return The transformed path (in this case an integer coordinate path)\n" + "\n" + "This method has been introduced in version 0.25.\n" + ) + path_defs::methods (), "@brief A path class\n" "\n" diff --git a/src/db/gsiDeclDbPolygon.cc b/src/db/gsiDeclDbPolygon.cc index 802c6cfbb..d91b4892b 100644 --- a/src/db/gsiDeclDbPolygon.cc +++ b/src/db/gsiDeclDbPolygon.cc @@ -659,6 +659,11 @@ static db::SimplePolygon dspolygon_to_spolygon (const db::DSimplePolygon *p, dou return db::SimplePolygon (*p * (1.0 / dbu), false); } +static db::SimplePolygon transformed_vplx_sp (const db::DSimplePolygon *p, const db::VCplxTrans &t) +{ + return p->transformed (t, false /*no compression*/); +} + Class decl_DSimplePolygon ("DSimplePolygon", constructor ("new|#from_ipoly", &dspolygon_from_ispolygon, gsi::arg ("polygon"), "@brief Creates a floating-point coordinate polygon from an integer coordinate polygon" @@ -685,6 +690,16 @@ Class decl_DSimplePolygon ("DSimplePolygon", "\n" "This method has been introduced in version 0.24.\n" ) + + method_ext ("transformed", &transformed_vplx_sp, + "@brief Transforms the polygon with the given complex transformation\n" + "\n" + "@args t\n" + "\n" + "@param t The magnifying transformation to apply\n" + "@return The transformed polygon (in this case an integer coordinate polygon)\n" + "\n" + "This method has been introduced in version 0.25.\n" + ) + simple_polygon_defs::methods (), "@brief A simple polygon class\n" "\n" @@ -1779,6 +1794,11 @@ static db::Polygon dpolygon_to_polygon (const db::DPolygon *p, double dbu) return db::Polygon (*p * (1.0 / dbu), false); } +static db::Polygon transformed_vcplx_dp (const db::DPolygon *p, const db::VCplxTrans &t) +{ + return p->transformed (t, false /*don't compress*/); +} + Class decl_DPolygon ("DPolygon", constructor ("new|#from_ipoly", &dpolygon_from_ipolygon, gsi::arg ("polygon"), "@brief Creates a floating-point coordinate polygon from an integer coordinate polygon\n" @@ -1805,6 +1825,16 @@ Class decl_DPolygon ("DPolygon", "\n" "This method has been introduced in version 0.24.\n" ) + + method_ext ("transformed", &transformed_vcplx_dp, + "@brief Transforms the polygon with the given complex transformation\n" + "\n" + "@args t\n" + "\n" + "@param t The magnifying transformation to apply\n" + "@return The transformed polygon (in this case an integer coordinate polygon)\n" + "\n" + "This method has been introduced in version 0.25.\n" + ) + polygon_defs::methods (), "@brief A polygon class\n" "\n" diff --git a/src/db/gsiDeclDbText.cc b/src/db/gsiDeclDbText.cc index 39403ce25..6ae15ad4d 100644 --- a/src/db/gsiDeclDbText.cc +++ b/src/db/gsiDeclDbText.cc @@ -446,6 +446,16 @@ Class decl_DText ("DText", "\n" "This method has been introduced in version 0.25." ) + + method ("transformed", &db::DText::transformed, + "@brief Transforms the text with the given complex transformation\n" + "\n" + "@args t\n" + "\n" + "@param t The magnifying transformation to apply\n" + "@return The transformed text (in this case an integer coordinate text)\n" + "\n" + "This method has been introduced in version 0.25.\n" + ) + text_defs::methods (), "@brief A text object\n" "\n" diff --git a/testdata/ruby/dbBoxTest.rb b/testdata/ruby/dbBoxTest.rb index 41b4fd39d..90035af56 100644 --- a/testdata/ruby/dbBoxTest.rb +++ b/testdata/ruby/dbBoxTest.rb @@ -124,7 +124,11 @@ class DBBox_TestClass < TestBase t = RBA::DTrans::new( RBA::DTrans::R90, RBA::DPoint::new( 5, 6 )) assert_equal( b.transformed(t).to_s, "(-17,7;6,23)" ) m = RBA::DCplxTrans::new( t, 1.5 ) + assert_equal( b.transformed(m).class.to_s, "RBA::DBox" ) assert_equal( b.transformed(m).to_s, "(-28,7.5;6.5,31.5)" ) + m = RBA::VCplxTrans::new( 1000.0 ) + assert_equal( b.transformed(m).class.to_s, "RBA::Box" ) + assert_equal( b.transformed(m).to_s, "(1000,-1000;17000,22000)" ) end diff --git a/testdata/ruby/dbEdgePairTest.rb b/testdata/ruby/dbEdgePairTest.rb index f68de4b7e..9eb929aeb 100644 --- a/testdata/ruby/dbEdgePairTest.rb +++ b/testdata/ruby/dbEdgePairTest.rb @@ -62,7 +62,10 @@ class DBEdgePair_TestClass < TestBase assert_equal(ep.normalized.to_s, "(10,20;0,0)/(-10,0;-10,30)") assert_equal(ep.transformed(RBA::DTrans::new(1)).to_s, "(0,0;-20,10)/(0,-10;-30,-10)") + assert_equal(ep.transformed(RBA::DCplxTrans::new(2.5)).class.to_s, "RBA::DEdgePair") assert_equal(ep.transformed(RBA::DCplxTrans::new(2.5)).to_s, "(0,0;25,50)/(-25,0;-25,75)") + assert_equal(ep.transformed(RBA::VCplxTrans::new(2.5)).class.to_s, "RBA::EdgePair") + assert_equal(ep.transformed(RBA::VCplxTrans::new(2.5)).to_s, "(0,0;25,50)/(-25,0;-25,75)") assert_equal(ep.polygon(0).to_s, "(-10,0;-10,30;0,0;10,20)") assert_equal(ep.polygon(0).class.to_s, "RBA::DPolygon") diff --git a/testdata/ruby/dbEdgeTest.rb b/testdata/ruby/dbEdgeTest.rb index aabf58a1d..a80fa7929 100644 --- a/testdata/ruby/dbEdgeTest.rb +++ b/testdata/ruby/dbEdgeTest.rb @@ -96,6 +96,10 @@ class DBEdge_TestClass < TestBase assert_equal( a.to_s, "(6,2;-2,2)" ) assert_equal( a.transformed(RBA::DCplxTrans::new(2.2)).to_s, "(13.2,4.4;-4.4,4.4)" ) + assert_equal( a.transformed(RBA::DCplxTrans::new(2.2)).class.to_s, "RBA::DEdge" ) + + assert_equal( a.transformed(RBA::VCplxTrans::new(22)).to_s, "(132,44;-44,44)" ) + assert_equal( a.transformed(RBA::VCplxTrans::new(22)).class.to_s, "RBA::Edge" ) assert_equal( RBA::DEdge::new( -1, -5, -1, -1 ).crossed_by?( a ), true ) assert_equal( RBA::DEdge::new( -1, -5, -1, -1 ).crossing_point( a ).to_s, "-1,2" ) diff --git a/testdata/ruby/dbPathTest.rb b/testdata/ruby/dbPathTest.rb index f7260dcc0..3c452d9b1 100644 --- a/testdata/ruby/dbPathTest.rb +++ b/testdata/ruby/dbPathTest.rb @@ -76,8 +76,13 @@ class DBPath_TestClass < TestBase assert_equal( b.to_s, "(1,1;3,2;2,5) w=2.5 bx=-0.5 ex=1.5 r=false" ) m = RBA::DCplxTrans::new( RBA::DTrans::new, 1.5 ) + assert_equal( a.transformed(m).class.to_s, "RBA::DPath") assert_equal( a.transformed(m).to_s, "(1.5,1.5;4.5,3;3,7.5) w=3.75 bx=-0.75 ex=2.25 r=false" ) + m = RBA::VCplxTrans::new(1000.0) + assert_equal( a.transformed(m).class.to_s, "RBA::Path") + assert_equal( a.transformed(m).to_s, "(1000,1000;3000,2000;2000,5000) w=2500 bx=-500 ex=1500 r=false" ) + a.points = [ RBA::DPoint::new( 0, 1 ), RBA::DPoint::new( 1, 1 ), RBA::DPoint::new( 1, 5 ) ] a.width = 2.0 a.bgn_ext = 1.0 diff --git a/testdata/ruby/dbPolygonTest.rb b/testdata/ruby/dbPolygonTest.rb index 5feed3f28..a6123d574 100644 --- a/testdata/ruby/dbPolygonTest.rb +++ b/testdata/ruby/dbPolygonTest.rb @@ -56,8 +56,13 @@ class DBPolygon_TestClass < TestBase assert_equal( b.to_s, "(6,-10;6,15;21,15;21,-10)" ) m = RBA::DCplxTrans::new( RBA::DTrans::new, 1.5 ) + assert_equal( a.transformed(m).class.to_s, "RBA::DPolygon" ) assert_equal( a.transformed(m).to_s, "(9,-15;9,22.5;31.5,22.5;31.5,-15)" ) + m = RBA::VCplxTrans::new( 1000.0 ) + assert_equal( a.transformed(m).class.to_s, "RBA::Polygon" ) + assert_equal( a.transformed(m).to_s, "(6000,-10000;6000,15000;21000,15000;21000,-10000)" ) + a.hull = [ RBA::DPoint::new( 0, 1 ), RBA::DPoint::new( 1, 1 ), RBA::DPoint::new( 1, 5 ) ] assert_equal( a.bbox.to_s, "(0,1;1,5)" ) diff --git a/testdata/ruby/dbSimplePolygonTest.rb b/testdata/ruby/dbSimplePolygonTest.rb index 2c588d1d6..3bb75e48a 100644 --- a/testdata/ruby/dbSimplePolygonTest.rb +++ b/testdata/ruby/dbSimplePolygonTest.rb @@ -65,6 +65,7 @@ class DBSimplePolygon_TestClass < TestBase assert_equal( b.to_s, "(6,-10;6,15;21,15;21,-10)" ) m = RBA::DCplxTrans::new( RBA::DTrans::new, 1.5 ) + assert_equal( a.transformed(m).class.to_s, "RBA::DSimplePolygon" ) assert_equal( a.transformed(m).to_s, "(9,-15;9,22.5;31.5,22.5;31.5,-15)" ) assert_equal( a.to_s, "(6,-10;6,15;21,15;21,-10)" ) @@ -72,6 +73,10 @@ class DBSimplePolygon_TestClass < TestBase b.transform(m) assert_equal( b.to_s, "(9,-15;9,22.5;31.5,22.5;31.5,-15)" ) + m = RBA::VCplxTrans::new( 1000.0 ) + assert_equal( a.transformed(m).class.to_s, "RBA::SimplePolygon" ) + assert_equal( a.transformed(m).to_s, "(6000,-10000;6000,15000;21000,15000;21000,-10000)" ) + a.points = [ RBA::DPoint::new( 0, 1 ), RBA::DPoint::new( 1, 1 ), RBA::DPoint::new( 1, 5 ) ] assert_equal( a.bbox.to_s, "(0,1;1,5)" ) diff --git a/testdata/ruby/dbTextTest.rb b/testdata/ruby/dbTextTest.rb index aeb77cef1..3cf3e1eef 100644 --- a/testdata/ruby/dbTextTest.rb +++ b/testdata/ruby/dbTextTest.rb @@ -68,8 +68,13 @@ class DBText_TestClass < TestBase assert_equal( b.to_s, "('hallo',m45 6,7)" ) m = RBA::DCplxTrans::new( RBA::DTrans::new, 1.5 ) + assert_equal( a.transformed(m).class.to_s, "RBA::DText" ) assert_equal( a.transformed(m).to_s, "('hallo',m45 9,10.5)" ) + m = RBA::VCplxTrans::new( 1000.0 ) + assert_equal( a.transformed(m).class.to_s, "RBA::Text" ) + assert_equal( a.transformed(m).to_s, "('hallo',m45 6000,7000)" ) + end # Text basics