size/sized versions with Vector/DVector

Adds variants to size/sized which take a vector instead
of dx, dy and where the mode parameter is optional. So far
anisotropic sizing had to come with a mode argument.
This commit is contained in:
Matthias Koefferlein 2022-02-07 20:59:09 +01:00
parent de98a30f38
commit e2c6e7aedc
4 changed files with 92 additions and 61 deletions

View File

@ -965,9 +965,9 @@ struct polygon_defs
poly->size (d, d, mode);
}
static void size_d (C *poly, coord_type d)
static void size_dvm (C *poly, const db::Vector &dv, unsigned int mode)
{
poly->size (d, d, 2);
poly->size (dv.x (), dv.y (), mode);
}
static C sized_xy (const C *poly, coord_type dx, coord_type dy, unsigned int mode)
@ -980,9 +980,9 @@ struct polygon_defs
return poly->sized (d, d, mode);
}
static C sized_d (const C *poly, coord_type d)
static C sized_dvm (const C *poly, const db::Vector &dv, unsigned int mode)
{
return poly->sized (d, d, 2);
return poly->sized (dv.x (), dv.y (), mode);
}
static bool inside (const C *poly, point_type pt)
@ -1272,7 +1272,19 @@ struct polygon_defs
"result = ep.simple_merge_p2p([ poly ], false, false, 1)\n"
"@/code\n"
) +
method_ext ("size", &size_dm, gsi::arg ("d"), gsi::arg ("mode"),
method_ext ("size", &size_dvm, gsi::arg ("dv"), gsi::arg ("mode", (unsigned int) 2),
"@brief Sizes the polygon (biasing)\n"
"\n"
"This method is equivalent to\n"
"@code\n"
"size(dv.x, dv.y, mode)\n"
"@/code\n"
"\n"
"See \\size for a detailed description.\n"
"\n"
"This version has been introduced in version 0.28.\n"
) +
method_ext ("size", &size_dm, gsi::arg ("d"), gsi::arg ("mode", (unsigned int) 2),
"@brief Sizes the polygon (biasing)\n"
"\n"
"Shifts the contour outwards (d>0) or inwards (d<0).\n"
@ -1294,7 +1306,19 @@ struct polygon_defs
"\n"
"This method has been introduced in version 0.23.\n"
) +
method_ext ("sized", &sized_dm, gsi::arg ("d"), gsi::arg ("mode"),
method_ext ("sized", &sized_dvm, gsi::arg ("dv"), gsi::arg ("mode", (unsigned int) 2),
"@brief Sizes the polygon (biasing) without modifying self\n"
"\n"
"This method is equivalent to\n"
"@code\n"
"sized(dv.x, dv.y, mode)\n"
"@/code\n"
"\n"
"See \\size and \\sized for a detailed description.\n"
"\n"
"This version has been introduced in version 0.28.\n"
) +
method_ext ("sized", &sized_dm, gsi::arg ("d"), gsi::arg ("mode", (unsigned int) 2),
"@brief Sizes the polygon (biasing) without modifying self\n"
"\n"
"Shifts the contour outwards (d>0) or inwards (d<0).\n"
@ -1305,28 +1329,6 @@ struct polygon_defs
"\n"
"See \\size and \\sized for a detailed description.\n"
) +
method_ext ("sized", &sized_d, gsi::arg ("d"),
"@brief Sizes the polygon (biasing)\n"
"\n"
"@brief Sizing (biasing) without modifying self\n"
"This method is equivalent to\n"
"@code\n"
"sized(d, d, 2)\n"
"@/code\n"
"\n"
"See \\size and \\sized for a detailed description.\n"
) +
method_ext ("size", &size_d, gsi::arg ("d"),
"@brief Sizes the polygon (biasing)\n"
"\n"
"Shifts the contour outwards (d>0) or inwards (d<0).\n"
"This method is equivalent to\n"
"@code\n"
"size(d, d, 2)\n"
"@/code\n"
"\n"
"See \\size for a detailed description.\n"
) +
method ("holes", &C::holes,
"@brief Returns the number of holes"
) +

View File

@ -471,17 +471,6 @@ static void break_polygons (db::Region *r, size_t max_vertex_count, double max_a
r->process (db::PolygonBreaker (max_vertex_count, max_area_ratio));
}
static db::Region &size_ext (db::Region *r, db::Coord d)
{
r->size (d);
return *r;
}
static db::Region sized_ext (db::Region *r, db::Coord d)
{
return r->sized (d);
}
static db::Region &merge_ext1 (db::Region *r, int min_wc)
{
r->merge (false, std::max (0, min_wc - 1));
@ -740,6 +729,19 @@ fill_region_multi (const db::Region *fr, db::Cell *cell, db::cell_index_type fil
db::fill_region_repeat (cell, *fr, fill_cell_index, fc_box, row_step, column_step, fill_margin, remaining_polygons, glue_box);
}
static db::Region
sized_dvm (const db::Region *region, const db::Vector &dv, unsigned int mode)
{
return region->sized (dv.x (), dv.y (), mode);
}
static db::Region &
size_dvm (db::Region *region, const db::Vector &dv, unsigned int mode)
{
region->size (dv.x (), dv.y (), mode);
return *region;
}
static db::Point default_origin;
// provided by gsiDeclDbPolygon.cc:
@ -1537,7 +1539,18 @@ Class<db::Region> decl_Region (decl_dbShapeCollection, "db", "Region",
"# r now is (50,-50;50,100;100,100;100,-50)\n"
"@/code\n"
) +
method ("size", (db::Region & (db::Region::*) (db::Coord, unsigned int)) &db::Region::size, gsi::arg ("d"), gsi::arg ("mode"),
method_ext ("size", &size_dvm, gsi::arg ("dv"), gsi::arg ("mode", (unsigned int) 2),
"@brief Anisotropic sizing (biasing)\n"
"\n"
"@return The region after the sizing has applied (self)\n"
"\n"
"This method is equivalent to \"size(dv.x, dv.y, mode)\".\n"
"\n"
"Merged semantics applies for this method (see \\merged_semantics= for a description of this concept)\n"
"\n"
"This variant has been introduced in version 0.28."
) +
method ("size", (db::Region & (db::Region::*) (db::Coord, unsigned int)) &db::Region::size, gsi::arg ("d"), gsi::arg ("mode", (unsigned int) 2),
"@brief Isotropic sizing (biasing)\n"
"\n"
"@return The region after the sizing has applied (self)\n"
@ -1546,39 +1559,34 @@ Class<db::Region> decl_Region (decl_dbShapeCollection, "db", "Region",
"\n"
"Merged semantics applies for this method (see \\merged_semantics= for a description of this concept)\n"
) +
method_ext ("size", size_ext, gsi::arg ("d"),
"@brief Isotropic sizing (biasing)\n"
"\n"
"@return The region after the sizing has applied (self)\n"
"\n"
"This method is equivalent to \"size(d, d, 2)\".\n"
"\n"
"Merged semantics applies for this method (see \\merged_semantics= for a description of this concept)\n"
) +
method ("sized", (db::Region (db::Region::*) (db::Coord, db::Coord, unsigned int) const) &db::Region::sized, gsi::arg ("dx"), gsi::arg ("dy"), gsi::arg ("mode"),
"@brief Returns the anisotropically sized region\n"
"\n"
"@return The sized region\n"
"\n"
"This method is returns the sized region (see \\size), but does not modify self.\n"
"This method returns the sized region (see \\size), but does not modify self.\n"
"\n"
"Merged semantics applies for this method (see \\merged_semantics= for a description of this concept)\n"
) +
method ("sized", (db::Region (db::Region::*) (db::Coord, unsigned int) const) &db::Region::sized, gsi::arg ("d"), gsi::arg ("mode"),
method_ext ("sized", &sized_dvm, gsi::arg ("dv"), gsi::arg ("mode", (unsigned int) 2),
"@brief Returns the (an)isotropically sized region\n"
"\n"
"@return The sized region\n"
"\n"
"This method is equivalent to \"sized(dv.x, dv.y, mode)\".\n"
"This method returns the sized region (see \\size), but does not modify self.\n"
"\n"
"Merged semantics applies for this method (see \\merged_semantics= for a description of this concept)\n"
"\n"
"This variant has been introduced in version 0.28."
) +
method ("sized", (db::Region (db::Region::*) (db::Coord, unsigned int) const) &db::Region::sized, gsi::arg ("d"), gsi::arg ("mode", (unsigned int) 2),
"@brief Returns the isotropically sized region\n"
"\n"
"@return The sized region\n"
"\n"
"This method is returns the sized region (see \\size), but does not modify self.\n"
"\n"
"Merged semantics applies for this method (see \\merged_semantics= for a description of this concept)\n"
) +
method_ext ("sized", sized_ext, gsi::arg ("d"),
"@brief Isotropic sizing (biasing)\n"
"\n"
"@return The region after the sizing has applied (self)\n"
"\n"
"This method is equivalent to \"sized(d, d, 2)\".\n"
"This method is equivalent to \"sized(d, d, mode)\".\n"
"This method returns the sized region (see \\size), but does not modify self.\n"
"\n"
"Merged semantics applies for this method (see \\merged_semantics= for a description of this concept)\n"
) +

View File

@ -277,8 +277,19 @@ class DBPolygon_TestClass < TestBase
a = RBA::Polygon::new( [ RBA::Point::new( 0, 1 ), RBA::Point::new( 1, 5 ), RBA::Point::new( 5, 5 ) ] )
assert_equal( a.to_s, "(0,1;1,5;5,5)" )
assert_equal( a.sized(2, 0, 2).to_s, "(-2,1;-1,5;7,5;2,1)" )
assert_equal( a.sized(RBA::Vector::new(2, 0), 2).to_s, "(-2,1;-1,5;7,5;2,1)" )
assert_equal( a.sized(RBA::Vector::new(2, 0)).to_s, "(-2,1;-1,5;7,5;2,1)" )
aa = a.dup
a.size(2, 0, 2);
assert_equal( a.to_s, "(-2,1;-1,5;7,5;2,1)" )
a = aa
aa = a.dup
a.size(RBA::Vector::new(2, 0), 2);
assert_equal( a.to_s, "(-2,1;-1,5;7,5;2,1)" )
a = aa
aa = a.dup
a.size(RBA::Vector::new(2, 0));
assert_equal( a.to_s, "(-2,1;-1,5;7,5;2,1)" )
a = RBA::Polygon::new
assert_equal( a.to_s, "()" )

View File

@ -318,6 +318,16 @@ class DBRegion_TestClass < TestBase
rr.size(10, 20, 2)
assert_equal(rr.to_s, "(-20,-40;-20,180;0,180;0,220;110,220;110,0;90,0;90,-40)")
assert_equal((r1 | r2).sized(RBA::Vector::new(10, 20)).to_s, "(-20,-40;-20,180;0,180;0,220;110,220;110,0;90,0;90,-40)")
rr = (r1 | r2).dup
rr.size(10, 20, 2)
assert_equal(rr.to_s, "(-20,-40;-20,180;0,180;0,220;110,220;110,0;90,0;90,-40)")
assert_equal((r1 | r2).sized(RBA::Vector::new(10, 20), 2).to_s, "(-20,-40;-20,180;0,180;0,220;110,220;110,0;90,0;90,-40)")
rr = (r1 | r2).dup
rr.size(10, 20, 2)
assert_equal(rr.to_s, "(-20,-40;-20,180;0,180;0,220;110,220;110,0;90,0;90,-40)")
r1.merged_semantics = false
assert_equal((r1 | r2).sized(10, 2).to_s, "(-20,-30;-20,170;0,170;0,210;110,210;110,10;90,10;90,-30)")