Convenience isotropic versions for Box::enlarge(d)

This commit is contained in:
Matthias Koefferlein 2022-11-10 22:31:13 +01:00
parent 67690b8ae8
commit 462976fc05
2 changed files with 41 additions and 3 deletions

View File

@ -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<C>::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<C>::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<C>::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"

View File

@ -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)" )