mirror of https://github.com/KLayout/klayout.git
Square and rectangle convenience ctor for GSI Box and DBox
This commit is contained in:
parent
719cd28f76
commit
d7263eac74
|
|
@ -59,6 +59,16 @@ struct box_defs
|
|||
return new C ();
|
||||
}
|
||||
|
||||
static C *new_sq (coord_type s)
|
||||
{
|
||||
return new C (-s / 2, -s / 2, s / 2, s / 2);
|
||||
}
|
||||
|
||||
static C *new_wh (coord_type w, coord_type h)
|
||||
{
|
||||
return new C (-w / 2, -h / 2, w / 2, h / 2);
|
||||
}
|
||||
|
||||
static C *new_lbrt (coord_type l, coord_type b, coord_type r, coord_type t)
|
||||
{
|
||||
return new C (l, b, r, t);
|
||||
|
|
@ -121,6 +131,20 @@ struct box_defs
|
|||
"box is also an empty box. The width, height, p1 and p2 attributes of an empty box are undefined. "
|
||||
"Use \\empty? to get a value indicating whether the box is empty.\n"
|
||||
) +
|
||||
constructor ("new", &new_sq,
|
||||
"@brief Creates a square with the given dimensions centered around the origin\n"
|
||||
"\n"
|
||||
"Note that for integer-unit boxes, the dimension has to be an even number to avoid rounding.\n"
|
||||
"\n"
|
||||
"This convenience constructor has been introduced in version 0.28."
|
||||
) +
|
||||
constructor ("new", &new_wh,
|
||||
"@brief Creates a rectangle with given width and height, centered around the origin\n"
|
||||
"\n"
|
||||
"Note that for integer-unit boxes, the dimensions have to be an even number to avoid rounding.\n"
|
||||
"\n"
|
||||
"This convenience constructor has been introduced in version 0.28."
|
||||
) +
|
||||
constructor ("new", &new_lbrt, gsi::arg ("left"), gsi::arg ("bottom"), gsi::arg ("right"), gsi::arg ("top"),
|
||||
"@brief Creates a box with four coordinates\n"
|
||||
"\n"
|
||||
|
|
|
|||
|
|
@ -29,6 +29,15 @@ class DBBox_TestClass < TestBase
|
|||
# DBox basics
|
||||
def test_1_DBox
|
||||
|
||||
a = RBA::DBox::new( 20 )
|
||||
assert_equal( a.to_s, "(-10,-10;10,10)" )
|
||||
|
||||
a = RBA::DBox::new( 21 )
|
||||
assert_equal( a.to_s, "(-10.5,-10.5;10.5,10.5)" )
|
||||
|
||||
a = RBA::DBox::new( 20, 40 )
|
||||
assert_equal( a.to_s, "(-10,-20;10,20)" )
|
||||
|
||||
a = RBA::DBox::new( -10, 21, 11, 17 )
|
||||
assert_equal( a.to_s, "(-10,17;11,21)" )
|
||||
assert_equal( RBA::DBox::from_s(a.to_s).to_s, a.to_s )
|
||||
|
|
@ -233,6 +242,15 @@ class DBBox_TestClass < TestBase
|
|||
# Box basics
|
||||
def test_1_Box
|
||||
|
||||
a = RBA::Box::new( 20 )
|
||||
assert_equal( a.to_s, "(-10,-10;10,10)" )
|
||||
|
||||
a = RBA::Box::new( 21 )
|
||||
assert_equal( a.to_s, "(-10,-10;10,10)" )
|
||||
|
||||
a = RBA::Box::new( 20, 40 )
|
||||
assert_equal( a.to_s, "(-10,-20;10,20)" )
|
||||
|
||||
a = RBA::Box::new( -10, 21, 11, 17 )
|
||||
assert_equal( a.to_s, "(-10,17;11,21)" )
|
||||
assert_equal( RBA::Box::from_s(a.to_s).to_s, a.to_s )
|
||||
|
|
|
|||
Loading…
Reference in New Issue