From 462976fc05a44725823781612714429ac660d091 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Thu, 10 Nov 2022 22:31:13 +0100 Subject: [PATCH] Convenience isotropic versions for Box::enlarge(d) --- src/db/db/gsiDeclDbBox.cc | 32 +++++++++++++++++++++++++++++--- testdata/ruby/dbBoxTest.rb | 12 ++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/db/db/gsiDeclDbBox.cc b/src/db/db/gsiDeclDbBox.cc index f71a54d0e..dfacc8f3c 100644 --- a/src/db/db/gsiDeclDbBox.cc +++ b/src/db/db/gsiDeclDbBox.cc @@ -96,11 +96,21 @@ struct box_defs return box->enlarge (vector_type (x, y)); } + static C &enlarge1 (C *box, coord_type s) + { + return box->enlarge (vector_type (s, s)); + } + static C enlarged (const C *box, coord_type x, coord_type y) { return box->enlarged (vector_type (x, y)); } + static C enlarged1 (const C *box, coord_type s) + { + return box->enlarged (vector_type (s, s)); + } + static C &move (C *box, coord_type x, coord_type y) { return box->move (vector_type (x, y)); @@ -371,7 +381,7 @@ struct box_defs "This is a convenience method which takes two values instead of a Point object.\n" "This method has been introduced in version 0.23.\n" "\n" - "@return The enlarged box.\n" + "@return The moved box.\n" ) + method ("move", &C::move, gsi::arg ("distance"), "@brief Moves the box by a certain distance\n" @@ -400,20 +410,36 @@ struct box_defs "@brief Enlarges the box by a certain amount.\n" "\n" "\n" - "This is a convenience method which takes two values instead of a Point object.\n" + "This is a convenience method which takes two values instead of a Vector object.\n" "This method has been introduced in version 0.23.\n" "\n" "@return A reference to this box.\n" ) + + method_ext ("enlarge", &box_defs::enlarge1, gsi::arg ("d"), + "@brief Enlarges the box by a certain amount on all sides.\n" + "\n" + "This is a convenience method which takes one values instead of two values. It will apply the given enlargement in both directions.\n" + "This method has been introduced in version 0.28.\n" + "\n" + "@return A reference to this box.\n" + ) + method_ext ("enlarged", &box_defs::enlarged, gsi::arg ("dx"), gsi::arg ("dy"), "@brief Enlarges the box by a certain amount.\n" "\n" "\n" - "This is a convenience method which takes two values instead of a Point object.\n" + "This is a convenience method which takes two values instead of a Vector object.\n" "This method has been introduced in version 0.23.\n" "\n" "@return The enlarged box.\n" ) + + method_ext ("enlarged", &box_defs::enlarged1, gsi::arg ("d"), + "@brief Enlarges the box by a certain amount on all sides.\n" + "\n" + "This is a convenience method which takes one values instead of two values. It will apply the given enlargement in both directions.\n" + "This method has been introduced in version 0.28.\n" + "\n" + "@return The enlarged box.\n" + ) + method ("enlarge", &C::enlarge, gsi::arg ("enlargement"), "@brief Enlarges the box by a certain amount.\n" "\n" diff --git a/testdata/ruby/dbBoxTest.rb b/testdata/ruby/dbBoxTest.rb index 05dd03daa..39d3d2f01 100644 --- a/testdata/ruby/dbBoxTest.rb +++ b/testdata/ruby/dbBoxTest.rb @@ -73,6 +73,12 @@ class DBBox_TestClass < TestBase a.enlarge( RBA::DPoint::new(1, -1) ) assert_equal( a.to_s, "(-11,22;12,24)" ) + aa = a.dup + a.enlarge( 2.0 ) + assert_equal( a.to_s, "(-13,20;14,26)" ) + a.enlarge( -2.0 ) + assert_equal( aa.enlarged( 2.0 ).to_s, "(-13,20;14,26)" ) + aa = a.dup a.enlarge( -1, 1 ) assert_equal( a.to_s, "(-10,21;11,25)" ) @@ -283,6 +289,12 @@ class DBBox_TestClass < TestBase a.move( RBA::Point::new(1, 1) ).move( RBA::Point::new(-2, 2) ) assert_equal( a.to_s, "(-10,21;11,25)" ) + aa = a.dup + a.enlarge( 2 ) + assert_equal( a.to_s, "(-12,19;13,27)" ) + a.enlarge( -2 ) + assert_equal( aa.enlarged( 2 ).to_s, "(-12,19;13,27)" ) + a.enlarge( RBA::Point::new(1, -1) ) assert_equal( a.to_s, "(-11,22;12,24)" )