FEATURE: added RBA::Polygon#split, RBA::Polygon#split, RBA::DSimplePolygon#split, RBA::DSimplePolygon#split

This commit is contained in:
Matthias Koefferlein 2018-04-20 22:26:57 +02:00
parent 5fbbccd9e2
commit e710b28a6d
2 changed files with 70 additions and 0 deletions

View File

@ -230,6 +230,13 @@ struct simple_polygon_defs
return db::interact (*p, spoly);
}
static std::vector<C> split_poly (const C *p)
{
std::vector<C> parts;
db::split_polygon (*p, parts);
return parts;
}
static gsi::Methods methods ()
{
return
@ -495,6 +502,19 @@ struct simple_polygon_defs
"\n"
"This method was introduced in version 0.25.\n"
) +
method_ext ("split", &split_poly,
"@brief Splits the polygon into two or more parts\n"
"This method will break the polygon into parts. The exact breaking algorithm is unspecified, the "
"result are smaller polygons of roughly equal number of points and 'less concave' nature. "
"Usually the returned polygon set consists of two polygons, but there can be more. "
"The merged region of the resulting polygons equals the original polygon with the exception of "
"small snapping effects at new vertexes.\n"
"\n"
"The intended use for this method is a iteratively split polygons until the satisfy some "
"maximum number of points limit.\n"
"\n"
"This method has been introduced in version 0.25.3."
) +
method_ext ("area", &area,
"@brief The area of the polygon\n"
"The area is correct only if the polygon is not self-overlapping and the polygon is oriented clockwise."
@ -1058,6 +1078,13 @@ struct polygon_defs
return db::interact (*p, spoly);
}
static std::vector<C> split_spoly (const C *p)
{
std::vector<C> parts;
db::split_polygon (*p, parts);
return parts;
}
static gsi::Methods methods ()
{
return
@ -1486,6 +1513,19 @@ struct polygon_defs
"\n"
"This method was introduced in version 0.25.\n"
) +
method_ext ("split", &split_spoly,
"@brief Splits the polygon into two or more parts\n"
"This method will break the polygon into parts. The exact breaking algorithm is unspecified, the "
"result are smaller polygons of roughly equal number of points and 'less concave' nature. "
"Usually the returned polygon set consists of two polygons, but there can be more. "
"The merged region of the resulting polygons equals the original polygon with the exception of "
"small snapping effects at new vertexes.\n"
"\n"
"The intended use for this method is a iteratively split polygons until the satisfy some "
"maximum number of points limit.\n"
"\n"
"This method has been introduced in version 0.25.3."
) +
method_ext ("area", &area,
"@brief The area of the polygon\n"
"The area is correct only if the polygon is not self-overlapping and the polygon is oriented clockwise."

View File

@ -731,6 +731,36 @@ class DBPolygon_TestClass < TestBase
end
def test_splitPolygon
pts = []
pts << RBA::Point::new(0, 0)
pts << RBA::Point::new(0, 1000)
pts << RBA::Point::new(100, 1000)
pts << RBA::Point::new(100, 100)
pts << RBA::Point::new(1000, 100)
pts << RBA::Point::new(1000, 0)
split = RBA::Polygon::new(pts).split
assert_equal(split.collect { |p| p.to_s }.join(";"), "(0,0;0,100;1000,100;1000,0);(0,100;0,1000;100,1000;100,100)")
split = RBA::SimplePolygon::new(pts).split
assert_equal(split.collect { |p| p.to_s }.join(";"), "(0,0;0,100;1000,100;1000,0);(0,100;0,1000;100,1000;100,100)")
pts = []
pts << RBA::DPoint::new(0, 0)
pts << RBA::DPoint::new(0, 1000)
pts << RBA::DPoint::new(100, 1000)
pts << RBA::DPoint::new(100, 100)
pts << RBA::DPoint::new(1000, 100)
pts << RBA::DPoint::new(1000, 0)
split = RBA::DPolygon::new(pts).split
assert_equal(split.collect { |p| p.to_s }.join(";"), "(0,0;0,100;1000,100;1000,0);(0,100;0,1000;100,1000;100,100)")
split = RBA::DSimplePolygon::new(pts).split
assert_equal(split.collect { |p| p.to_s }.join(";"), "(0,0;0,100;1000,100;1000,0);(0,100;0,1000;100,1000;100,100)")
end
end
load("test_epilogue.rb")