diff --git a/src/db/db/gsiDeclDbPolygon.cc b/src/db/db/gsiDeclDbPolygon.cc index f4263f592..4ca38ba06 100644 --- a/src/db/db/gsiDeclDbPolygon.cc +++ b/src/db/db/gsiDeclDbPolygon.cc @@ -230,6 +230,13 @@ struct simple_polygon_defs return db::interact (*p, spoly); } + static std::vector split_poly (const C *p) + { + std::vector 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 split_spoly (const C *p) + { + std::vector 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." diff --git a/testdata/ruby/dbPolygonTest.rb b/testdata/ruby/dbPolygonTest.rb index db60d366a..8c9f7c627 100644 --- a/testdata/ruby/dbPolygonTest.rb +++ b/testdata/ruby/dbPolygonTest.rb @@ -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")