From 6f66e04c8ed72cfa7720a49d32f21852cef7cca6 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 20 Dec 2017 22:55:15 +0100 Subject: [PATCH] Fixed #41 (Polygon#touches? method) --- src/db/db/gsiDeclDbPolygon.cc | 94 +++++++++++++++++++++++++++++++++- testdata/ruby/dbPolygonTest.rb | 61 ++++++++++++++++++++++ 2 files changed, 153 insertions(+), 2 deletions(-) diff --git a/src/db/db/gsiDeclDbPolygon.cc b/src/db/db/gsiDeclDbPolygon.cc index e892b0978..ded44d2c1 100644 --- a/src/db/db/gsiDeclDbPolygon.cc +++ b/src/db/db/gsiDeclDbPolygon.cc @@ -210,6 +210,26 @@ struct simple_polygon_defs return std_ext::hfunc (*p); } + static bool touches_box (const C *p, const db::box &box) + { + return db::interact (*p, box); + } + + static bool touches_edge (const C *p, const db::edge &edge) + { + return db::interact (*p, edge); + } + + static bool touches_poly (const C *p, const db::polygon &poly) + { + return db::interact (*p, poly); + } + + static bool touches_spoly (const C *p, const db::simple_polygon &spoly) + { + return db::interact (*p, spoly); + } + static gsi::Methods methods () { return @@ -485,7 +505,32 @@ struct simple_polygon_defs ) + method ("bbox", &C::box, "@brief Return the bounding box of the simple polygon" - ); + ) + + method_ext ("touches?", &touches_box, gsi::arg ("box"), + "@brief Returns true, if the polygon touches the given box.\n" + "The box and the polygon touch if they overlap or their contours share at least one point.\n" + "\n" + "This method was introduced in version 0.25.1.\n" + ) + + method_ext ("touches?", &touches_edge, gsi::arg ("edge"), + "@brief Returns true, if the polygon touches the given edge.\n" + "The box and the polygon touch if they overlap or the edge shares at least one point with the polygon's contour.\n" + "\n" + "This method was introduced in version 0.25.1.\n" + ) + + method_ext ("touches?", &touches_poly, gsi::arg ("polygon"), + "@brief Returns true, if the polygon touches the other polygon.\n" + "The polygons touch if they overlap or their contours share at least one point.\n" + "\n" + "This method was introduced in version 0.25.1.\n" + ) + + method_ext ("touches?", &touches_spoly, gsi::arg ("simple_polygon"), + "@brief Returns true, if the polygon touches the other polygon.\n" + "The polygons touch if they overlap or their contours share at least one point.\n" + "\n" + "This method was introduced in version 0.25.1.\n" + ) + ; } }; @@ -993,6 +1038,26 @@ struct polygon_defs return std_ext::hfunc (*p); } + static bool touches_box (const C *p, const db::box &box) + { + return db::interact (*p, box); + } + + static bool touches_edge (const C *p, const db::edge &edge) + { + return db::interact (*p, edge); + } + + static bool touches_poly (const C *p, const db::polygon &poly) + { + return db::interact (*p, poly); + } + + static bool touches_spoly (const C *p, const db::simple_polygon &spoly) + { + return db::interact (*p, spoly); + } + static gsi::Methods methods () { return @@ -1435,7 +1500,32 @@ struct polygon_defs method ("bbox", &C::box, "@brief Return the bounding box of the polygon\n" "The bounding box is the box enclosing all points of the polygon.\n" - ); + ) + + method_ext ("touches?", &touches_box, gsi::arg ("box"), + "@brief Returns true, if the polygon touches the given box.\n" + "The box and the polygon touch if they overlap or their contours share at least one point.\n" + "\n" + "This method was introduced in version 0.25.1.\n" + ) + + method_ext ("touches?", &touches_edge, gsi::arg ("edge"), + "@brief Returns true, if the polygon touches the given edge.\n" + "The box and the polygon touch if they overlap or the edge shares at least one point with the polygon's contour.\n" + "\n" + "This method was introduced in version 0.25.1.\n" + ) + + method_ext ("touches?", &touches_poly, gsi::arg ("polygon"), + "@brief Returns true, if the polygon touches the other polygon.\n" + "The polygons touch if they overlap or their contours share at least one point.\n" + "\n" + "This method was introduced in version 0.25.1.\n" + ) + + method_ext ("touches?", &touches_spoly, gsi::arg ("simple_polygon"), + "@brief Returns true, if the polygon touches the other polygon.\n" + "The polygons touch if they overlap or their contours share at least one point.\n" + "\n" + "This method was introduced in version 0.25.1.\n" + ) + ; } }; diff --git a/testdata/ruby/dbPolygonTest.rb b/testdata/ruby/dbPolygonTest.rb index 04d1c9e14..e36eb7347 100644 --- a/testdata/ruby/dbPolygonTest.rb +++ b/testdata/ruby/dbPolygonTest.rb @@ -659,6 +659,67 @@ class DBPolygon_TestClass < TestBase end + # touches predicate + def test_touches + + p1 = RBA::Polygon::new(RBA::Box::new(10, 20, 30, 40)) + assert_equal(p1.touches?(RBA::Polygon::new(RBA::Box::new(30, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::Polygon::new(RBA::Box::new(31, 20, 40, 50))), false) + assert_equal(p1.touches?(RBA::Polygon::new(RBA::Box::new(29, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::SimplePolygon::new(RBA::Box::new(30, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::SimplePolygon::new(RBA::Box::new(31, 20, 40, 50))), false) + assert_equal(p1.touches?(RBA::SimplePolygon::new(RBA::Box::new(29, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::Box::new(30, 20, 40, 50)), true) + assert_equal(p1.touches?(RBA::Box::new(31, 20, 40, 50)), false) + assert_equal(p1.touches?(RBA::Box::new(29, 20, 40, 50)), true) + assert_equal(p1.touches?(RBA::Edge::new(30, 20, 40, 50)), true) + assert_equal(p1.touches?(RBA::Edge::new(31, 20, 40, 50)), false) + assert_equal(p1.touches?(RBA::Edge::new(29, 20, 40, 50)), true) + + p1 = RBA::SimplePolygon::new(RBA::Box::new(10, 20, 30, 40)) + assert_equal(p1.touches?(RBA::Polygon::new(RBA::Box::new(30, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::Polygon::new(RBA::Box::new(31, 20, 40, 50))), false) + assert_equal(p1.touches?(RBA::Polygon::new(RBA::Box::new(29, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::SimplePolygon::new(RBA::Box::new(30, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::SimplePolygon::new(RBA::Box::new(31, 20, 40, 50))), false) + assert_equal(p1.touches?(RBA::SimplePolygon::new(RBA::Box::new(29, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::Box::new(30, 20, 40, 50)), true) + assert_equal(p1.touches?(RBA::Box::new(31, 20, 40, 50)), false) + assert_equal(p1.touches?(RBA::Box::new(29, 20, 40, 50)), true) + assert_equal(p1.touches?(RBA::Edge::new(30, 20, 40, 50)), true) + assert_equal(p1.touches?(RBA::Edge::new(31, 20, 40, 50)), false) + assert_equal(p1.touches?(RBA::Edge::new(29, 20, 40, 50)), true) + + p1 = RBA::DPolygon::new(RBA::DBox::new(10, 20, 30, 40)) + assert_equal(p1.touches?(RBA::DPolygon::new(RBA::DBox::new(30, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::DPolygon::new(RBA::DBox::new(31, 20, 40, 50))), false) + assert_equal(p1.touches?(RBA::DPolygon::new(RBA::DBox::new(29, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::DSimplePolygon::new(RBA::DBox::new(30, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::DSimplePolygon::new(RBA::DBox::new(31, 20, 40, 50))), false) + assert_equal(p1.touches?(RBA::DSimplePolygon::new(RBA::DBox::new(29, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::DBox::new(30, 20, 40, 50)), true) + assert_equal(p1.touches?(RBA::DBox::new(31, 20, 40, 50)), false) + assert_equal(p1.touches?(RBA::DBox::new(29, 20, 40, 50)), true) + assert_equal(p1.touches?(RBA::DEdge::new(30, 20, 40, 50)), true) + assert_equal(p1.touches?(RBA::DEdge::new(31, 20, 40, 50)), false) + assert_equal(p1.touches?(RBA::DEdge::new(29, 20, 40, 50)), true) + + p1 = RBA::DSimplePolygon::new(RBA::DBox::new(10, 20, 30, 40)) + assert_equal(p1.touches?(RBA::DPolygon::new(RBA::DBox::new(30, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::DPolygon::new(RBA::DBox::new(31, 20, 40, 50))), false) + assert_equal(p1.touches?(RBA::DPolygon::new(RBA::DBox::new(29, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::DSimplePolygon::new(RBA::DBox::new(30, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::DSimplePolygon::new(RBA::DBox::new(31, 20, 40, 50))), false) + assert_equal(p1.touches?(RBA::DSimplePolygon::new(RBA::DBox::new(29, 20, 40, 50))), true) + assert_equal(p1.touches?(RBA::DBox::new(30, 20, 40, 50)), true) + assert_equal(p1.touches?(RBA::DBox::new(31, 20, 40, 50)), false) + assert_equal(p1.touches?(RBA::DBox::new(29, 20, 40, 50)), true) + assert_equal(p1.touches?(RBA::DEdge::new(30, 20, 40, 50)), true) + assert_equal(p1.touches?(RBA::DEdge::new(31, 20, 40, 50)), false) + assert_equal(p1.touches?(RBA::DEdge::new(29, 20, 40, 50)), true) + + end + end load("test_epilogue.rb")