diff --git a/test/algorithms/Jamfile.v2 b/test/algorithms/Jamfile.v2 index 7058f6753..3e37dcaf0 100644 --- a/test/algorithms/Jamfile.v2 +++ b/test/algorithms/Jamfile.v2 @@ -19,6 +19,7 @@ test-suite boost-geometry-algorithms [ run convex_hull.cpp ] [ run correct.cpp ] [ run convert.cpp ] + [ run covered_by.cpp ] [ run difference.cpp ] [ run disjoint.cpp ] [ run distance.cpp ] diff --git a/test/algorithms/algorithms_tests.sln b/test/algorithms/algorithms_tests.sln index 6880312aa..124ad8af0 100644 --- a/test/algorithms/algorithms_tests.sln +++ b/test/algorithms/algorithms_tests.sln @@ -56,6 +56,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "comparable_distance", "comp EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "convert", "convert.vcproj", "{FABF1AA7-F695-49F8-92F6-AB6C4B0C088A}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "covered_by", "covered_by.vcproj", "{5ABF0B56-F9F1-4D93-B15A-E3972F45D97B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -174,6 +176,10 @@ Global {FABF1AA7-F695-49F8-92F6-AB6C4B0C088A}.Debug|Win32.Build.0 = Debug|Win32 {FABF1AA7-F695-49F8-92F6-AB6C4B0C088A}.Release|Win32.ActiveCfg = Release|Win32 {FABF1AA7-F695-49F8-92F6-AB6C4B0C088A}.Release|Win32.Build.0 = Release|Win32 + {5ABF0B56-F9F1-4D93-B15A-E3972F45D97B}.Debug|Win32.ActiveCfg = Debug|Win32 + {5ABF0B56-F9F1-4D93-B15A-E3972F45D97B}.Debug|Win32.Build.0 = Debug|Win32 + {5ABF0B56-F9F1-4D93-B15A-E3972F45D97B}.Release|Win32.ActiveCfg = Release|Win32 + {5ABF0B56-F9F1-4D93-B15A-E3972F45D97B}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/algorithms/covered_by.cpp b/test/algorithms/covered_by.cpp new file mode 100644 index 000000000..a6cb7aef1 --- /dev/null +++ b/test/algorithms/covered_by.cpp @@ -0,0 +1,149 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands. +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include + + +#include +#include + + +template +void test_all() +{ + /* + // trivial case + test_ring

("POINT(1 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", true, false); + + // on border/corner + test_ring

("POINT(0 0)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", false, true); + test_ring

("POINT(0 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", false, true); + + // aligned to segment/vertex + test_ring

("POINT(1 1)", "POLYGON((0 0,0 3,3 3,3 1,2 1,2 0,0 0))", true, false); + test_ring

("POINT(1 1)", "POLYGON((0 0,0 3,4 3,3 1,2 2,2 0,0 0))", true, false); + + // same polygon, but point on border + test_ring

("POINT(3 3)", "POLYGON((0 0,0 3,3 3,3 1,2 1,2 0,0 0))", false, true); + test_ring

("POINT(3 3)", "POLYGON((0 0,0 3,4 3,3 1,2 2,2 0,0 0))", false, true); + + // holes + test_geometry >("POINT(2 2)", + "POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,3 1,3 3,1 3,1 1))", false); + + */ + + typedef bg::model::box

box_type; + + test_geometry("POINT(1 1)", "BOX(0 0,2 2)", true); + test_geometry("POINT(0 0)", "BOX(0 0,2 2)", true); + test_geometry("POINT(2 2)", "BOX(0 0,2 2)", true); + test_geometry("POINT(0 1)", "BOX(0 0,2 2)", true); + test_geometry("POINT(1 0)", "BOX(0 0,2 2)", true); + test_geometry("POINT(3 3)", "BOX(0 0,2 2)", false); + + test_geometry("BOX(1 1,2 2)", "BOX(0 0,3 3)", true); + test_geometry("BOX(0 0,3 3)", "BOX(1 1,2 2)", false); + test_geometry("BOX(0 0,2 2)", "BOX(0 0,3 3)", true); + test_geometry("BOX(1 1,3 3)", "BOX(0 0,3 3)", true); + test_geometry("BOX(1 2,3 3)", "BOX(0 0,3 3)", true); + test_geometry("BOX(1 1,4 3)", "BOX(0 0,3 3)", false); + + + /* + test_within_code("POINT(1 1)", "BOX(0 0,2 2)", 1); + test_within_code("POINT(1 0)", "BOX(0 0,2 2)", 0); + test_within_code("POINT(0 1)", "BOX(0 0,2 2)", 0); + test_within_code("POINT(0 3)", "BOX(0 0,2 2)", -1); + test_within_code("POINT(3 3)", "BOX(0 0,2 2)", -1); + + test_within_code("BOX(1 1,2 2)", "BOX(0 0,3 3)", 1); + test_within_code("BOX(0 1,2 2)", "BOX(0 0,3 3)", 0); + test_within_code("BOX(1 0,2 2)", "BOX(0 0,3 3)", 0); + test_within_code("BOX(1 1,2 3)", "BOX(0 0,3 3)", 0); + test_within_code("BOX(1 1,3 2)", "BOX(0 0,3 3)", 0); + test_within_code("BOX(1 1,3 4)", "BOX(0 0,3 3)", -1); + */ +} + + +void test_3d() +{ + typedef boost::geometry::model::point point_type; + typedef boost::geometry::model::box box_type; + box_type box(point_type(0, 0, 0), point_type(4, 4, 4)); + BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 2, 2), box), true); + BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 4, 2), box), true); + BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 2, 4), box), true); + BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 2, 5), box), false); +} + +template +void test_mixed_of() +{ + typedef boost::geometry::model::polygon polygon_type1; + typedef boost::geometry::model::polygon polygon_type2; + typedef boost::geometry::model::box box_type1; + typedef boost::geometry::model::box box_type2; + + polygon_type1 poly1, poly2; + boost::geometry::read_wkt("POLYGON((0 0,0 5,5 5,5 0,0 0))", poly1); + boost::geometry::read_wkt("POLYGON((0 0,0 5,5 5,5 0,0 0))", poly2); + + box_type1 box1(P1(1, 1), P1(4, 4)); + box_type2 box2(P2(0, 0), P2(5, 5)); + P1 p1(3, 3); + P2 p2(3, 3); + + BOOST_CHECK_EQUAL(bg::covered_by(p1, poly2), true); + BOOST_CHECK_EQUAL(bg::covered_by(p2, poly1), true); + BOOST_CHECK_EQUAL(bg::covered_by(p2, box1), true); + BOOST_CHECK_EQUAL(bg::covered_by(p1, box2), true); + BOOST_CHECK_EQUAL(bg::covered_by(box1, box2), true); + BOOST_CHECK_EQUAL(bg::covered_by(box2, box1), false); +} + + +void test_mixed() +{ + // Mixing point types and coordinate types + test_mixed_of + < + boost::geometry::model::d2::point_xy, + boost::geometry::model::point + >(); + test_mixed_of + < + boost::geometry::model::d2::point_xy, + boost::geometry::model::point + >(); + test_mixed_of + < + boost::geometry::model::d2::point_xy, + boost::geometry::model::d2::point_xy + >(); +} + + +int test_main( int , char* [] ) +{ + test_all >(); + test_all >(); + + //test_spherical > >(); + + test_mixed(); + test_3d(); + + +#if defined(HAVE_TTMATH) + test_all >(); + //test_spherical > >(); +#endif + + return 0; +} diff --git a/test/algorithms/covered_by.vcproj b/test/algorithms/covered_by.vcproj new file mode 100644 index 000000000..13f41e930 --- /dev/null +++ b/test/algorithms/covered_by.vcproj @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/algorithms/overlay/self_intersection_points.vcproj b/test/algorithms/overlay/self_intersection_points.vcproj index 450ea2270..a4cdb8049 100644 --- a/test/algorithms/overlay/self_intersection_points.vcproj +++ b/test/algorithms/overlay/self_intersection_points.vcproj @@ -46,6 +46,7 @@ ExceptionHandling="2" RuntimeLibrary="1" UsePrecompiledHeader="0" + DebugInformationFormat="1" /> + +#include +#include +#include +#include +#include + +#include + + +template +void test_geometry(std::string const& wkt1, + std::string const& wkt2, bool expected) +{ + Geometry1 geometry1; + Geometry2 geometry2; + + bg::read_wkt(wkt1, geometry1); + bg::read_wkt(wkt2, geometry2); + + bool detected = bg::covered_by(geometry1, geometry2); + + BOOST_CHECK_MESSAGE(detected == expected, + "covered_by: " << wkt1 + << " in " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected); +} + +/* + +template +void test_ordered_ring(std::string const& wkt_point, + std::string const& wkt_geometry, bool expected) +{ + typedef bg::model::ring ring_type; + ring_type ring; + Point point; + + bg::read_wkt(wkt_geometry, ring); + if (! Clockwise) + { + std::reverse(boost::begin(ring), boost::end(ring)); + } + if (! Closed) + { + ring.resize(ring.size() - 1); + } + + bg::read_wkt(wkt_point, point); + + bool detected = bg::covered_by(point, ring); + + BOOST_CHECK_MESSAGE(detected == expected, + "covered_by: " << wkt_point + << " in " << wkt_geometry + << " -> Expected: " << expected + << " detected: " << detected + << " clockwise: " << int(Clockwise) + << " closed: " << int(Closed) + ); + + // other strategy (note that this one cannot detect OnBorder + // (without modifications) + + bg::strategy::covered_by::franklin franklin; + detected = bg::covered_by(point, ring, franklin); + if (! on_border) + { + BOOST_CHECK_MESSAGE(detected == expected, + "covered_by: " << wkt_point + << " in " << wkt_geometry + << " -> Expected: " << expected + << " detected: " << detected + << " clockwise: " << int(Clockwise) + << " closed: " << int(Closed) + ); + } + + + bg::strategy::covered_by::crossings_multiply cm; + detected = bg::covered_by(point, ring, cm); + if (! on_border) + { + BOOST_CHECK_MESSAGE(detected == expected, + "covered_by: " << wkt_point + << " in " << wkt_geometry + << " -> Expected: " << expected + << " detected: " << detected + << " clockwise: " << int(Clockwise) + << " closed: " << int(Closed) + ); + } +} + +template +void test_ring(std::string const& wkt_point, + std::string const& wkt_geometry, + bool expected) +{ + test_ordered_ring(wkt_point, wkt_geometry, expected); + test_ordered_ring(wkt_point, wkt_geometry, expected); + test_ordered_ring(wkt_point, wkt_geometry, expected); + test_ordered_ring(wkt_point, wkt_geometry, expected); + test_geometry >(wkt_point, wkt_geometry, expected); +} +*/ + +#endif diff --git a/test/algorithms/test_within.hpp b/test/algorithms/test_within.hpp index a65d2ab82..d2c517009 100644 --- a/test/algorithms/test_within.hpp +++ b/test/algorithms/test_within.hpp @@ -21,6 +21,10 @@ #include +#include +#include +#include + template void test_geometry(std::string const& wkt1, @@ -41,24 +45,6 @@ void test_geometry(std::string const& wkt1, << " detected: " << detected); } -template -void test_within_code(std::string const& wkt1, - std::string const& wkt2, int expected) -{ - Geometry1 geometry1; - Geometry2 geometry2; - - bg::read_wkt(wkt1, geometry1); - bg::read_wkt(wkt2, geometry2); - - int detected = bg::detail::within_code(geometry1, geometry2); - - BOOST_CHECK_MESSAGE(detected == expected, - "within_code: " << wkt1 - << " in " << wkt2 - << " -> Expected: " << expected - << " detected: " << detected); -} template diff --git a/test/algorithms/within.cpp b/test/algorithms/within.cpp index e67cd7a57..85c6f13b6 100644 --- a/test/algorithms/within.cpp +++ b/test/algorithms/within.cpp @@ -37,10 +37,15 @@ void test_all() typedef bg::model::box

box_type; test_geometry("POINT(1 1)", "BOX(0 0,2 2)", true); + test_geometry("POINT(0 0)", "BOX(0 0,2 2)", false); + test_geometry("POINT(2 2)", "BOX(0 0,2 2)", false); + test_geometry("POINT(0 1)", "BOX(0 0,2 2)", false); + test_geometry("POINT(1 0)", "BOX(0 0,2 2)", false); test_geometry("BOX(1 1,2 2)", "BOX(0 0,3 3)", true); test_geometry("BOX(0 0,3 3)", "BOX(1 1,2 2)", false); + /* test_within_code("POINT(1 1)", "BOX(0 0,2 2)", 1); test_within_code("POINT(1 0)", "BOX(0 0,2 2)", 0); test_within_code("POINT(0 1)", "BOX(0 0,2 2)", 0); @@ -53,15 +58,7 @@ void test_all() test_within_code("BOX(1 1,2 3)", "BOX(0 0,3 3)", 0); test_within_code("BOX(1 1,3 2)", "BOX(0 0,3 3)", 0); test_within_code("BOX(1 1,3 4)", "BOX(0 0,3 3)", -1); - - - // Mixed point types - test_geometry - < - bg::model::d2::point_xy, - bg::model::polygon

- >("POINT(1 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", true); - + */ // Real-life problem (solved now), point is in the middle, 409623 is also a coordinate // on the border, has been wrong in the past (2009) @@ -119,46 +116,119 @@ void test_spherical() BOOST_CHECK_EQUAL(bg::within(Point(7, 52.5), triangle), true); BOOST_CHECK_EQUAL(bg::within(Point(8.0, 51.5), triangle), false); BOOST_CHECK_EQUAL(bg::within(Point(6.0, 51.0), triangle), false); + + // Test spherical boxes + // See also http://www.gcmap.com/mapui?P=1E45N-19E45N-19E55N-1E55N-1E45N,10E55.1N,10E45.1N + bg::model::box box; + bg::read_wkt("POLYGON((1 45,19 55))", box); + BOOST_CHECK_EQUAL(bg::within(Point(10, 55.1), box), true); + BOOST_CHECK_EQUAL(bg::within(Point(10, 55.2), box), true); + BOOST_CHECK_EQUAL(bg::within(Point(10, 55.3), box), true); + BOOST_CHECK_EQUAL(bg::within(Point(10, 55.4), box), false); + + BOOST_CHECK_EQUAL(bg::within(Point(10, 45.1), box), false); + BOOST_CHECK_EQUAL(bg::within(Point(10, 45.2), box), false); + BOOST_CHECK_EQUAL(bg::within(Point(10, 45.3), box), false); + BOOST_CHECK_EQUAL(bg::within(Point(10, 45.4), box), true); + + // Crossing the dateline (Near Tuvalu) + // http://www.gcmap.com/mapui?P=178E10S-178W10S-178W6S-178E6S-178E10S,180W5.999S,180E9.999S + // http://en.wikipedia.org/wiki/Tuvalu + + bg::model::box tuvalu(Point(178, -10), Point(-178, -6)); + BOOST_CHECK_EQUAL(bg::within(Point(180, -8), tuvalu), true); + BOOST_CHECK_EQUAL(bg::within(Point(-180, -8), tuvalu), true); + BOOST_CHECK_EQUAL(bg::within(Point(180, -5.999), tuvalu), false); + BOOST_CHECK_EQUAL(bg::within(Point(180, -10.001), tuvalu), true); } -void test_mixed() +void test_3d() { - typedef boost::geometry::model::d2::point_xy point_type1; - typedef boost::geometry::model::point point_type2; + typedef boost::geometry::model::point point_type; + typedef boost::geometry::model::box box_type; + box_type box(point_type(0, 0, 0), point_type(4, 4, 4)); + BOOST_CHECK_EQUAL(bg::within(point_type(2, 2, 2), box), true); + BOOST_CHECK_EQUAL(bg::within(point_type(2, 4, 2), box), false); + BOOST_CHECK_EQUAL(bg::within(point_type(2, 2, 4), box), false); + BOOST_CHECK_EQUAL(bg::within(point_type(2, 2, 5), box), false); +} - typedef boost::geometry::model::polygon polygon_type1; - typedef boost::geometry::model::polygon polygon_type2; - typedef boost::geometry::model::box box_type1; - typedef boost::geometry::model::box box_type2; +template +void test_mixed_of() +{ + typedef boost::geometry::model::polygon polygon_type1; + typedef boost::geometry::model::polygon polygon_type2; + typedef boost::geometry::model::box box_type1; + typedef boost::geometry::model::box box_type2; - polygon_type1 poly1; + polygon_type1 poly1, poly2; boost::geometry::read_wkt("POLYGON((0 0,0 5,5 5,5 0,0 0))", poly1); - polygon_type2 poly2; boost::geometry::read_wkt("POLYGON((0 0,0 5,5 5,5 0,0 0))", poly2); - - box_type1 box1(point_type1(1, 1), point_type1(4, 4)); - box_type2 box2(point_type2(0, 0), point_type2(5, 5)); - point_type1 p1(3, 3); - point_type2 p2(3, 3); + box_type1 box1(P1(1, 1), P1(4, 4)); + box_type2 box2(P2(0, 0), P2(5, 5)); + P1 p1(3, 3); + P2 p2(3, 3); BOOST_CHECK_EQUAL(bg::within(p1, poly2), true); BOOST_CHECK_EQUAL(bg::within(p2, poly1), true); BOOST_CHECK_EQUAL(bg::within(p2, box1), true); BOOST_CHECK_EQUAL(bg::within(p1, box2), true); BOOST_CHECK_EQUAL(bg::within(box1, box2), true); + BOOST_CHECK_EQUAL(bg::within(box2, box1), false); +} + + +void test_mixed() +{ + // Mixing point types and coordinate types + test_mixed_of + < + boost::geometry::model::d2::point_xy, + boost::geometry::model::point + >(); + test_mixed_of + < + boost::geometry::model::d2::point_xy, + boost::geometry::model::point + >(); + test_mixed_of + < + boost::geometry::model::d2::point_xy, + boost::geometry::model::d2::point_xy + >(); +} + +void test_strategy() +{ + // Test by explicitly specifying a strategy + typedef bg::model::d2::point_xy point_type; + typedef bg::model::box box_type; + point_type p(3, 3); + box_type b(point_type(0, 0), point_type(5, 5)); + + bool r = bg::within(p, b, + bg::strategy::within::point_in_box()); + + r = bg::within(b, b, + bg::strategy::within::box_in_box()); + + r = bg::within(p, b, + bg::strategy::within::point_in_box_by_side()); } int test_main( int , char* [] ) { - test_mixed(); - test_all >(); test_all >(); test_spherical > >(); + test_mixed(); + test_3d(); + test_strategy(); + #if defined(HAVE_TTMATH) test_all >(); diff --git a/test/multi/algorithms/Jamfile.v2 b/test/multi/algorithms/Jamfile.v2 index 9087b7ac3..c6ea0e06c 100644 --- a/test/multi/algorithms/Jamfile.v2 +++ b/test/multi/algorithms/Jamfile.v2 @@ -14,6 +14,7 @@ test-suite boost-geometry-multi-algorithms [ run multi_centroid.cpp ] [ run multi_convex_hull.cpp ] [ run multi_correct.cpp ] + [ run multi_covered_by.cpp ] [ run multi_difference.cpp ] [ run multi_envelope.cpp ] [ run multi_equals.cpp ] diff --git a/test/multi/algorithms/multi_covered_by.cpp b/test/multi/algorithms/multi_covered_by.cpp new file mode 100644 index 000000000..5d937f4eb --- /dev/null +++ b/test/multi/algorithms/multi_covered_by.cpp @@ -0,0 +1,58 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands. +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include + +#include + +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#include + + +template +void test_all() +{ + typedef bg::model::multi_polygon > mp; + + // test multi-with-one-polygon (trivial case) + test_geometry("POINT(1 1)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", true); + test_geometry("POINT(3 3)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", false); + test_geometry("POINT(0 1)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", true); + test_geometry("POINT(4 4)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", false); + + // test if it is in one of them + std::string multi("MULTIPOLYGON(" + "((0 0,0 2,2 2,2 0,0 0))" + "((3 3,3 6,6 6,6 3,3 3))" + ")"); + test_geometry("POINT(4 4)", multi, true); + test_geometry("POINT(1 1)", multi, true); + test_geometry("POINT(0 1)", multi, true); +} + +int test_main( int , char* [] ) +{ + //test_all >(); + test_all >(); + +#if defined(HAVE_TTMATH) + test_all >(); +#endif + + return 0; +} diff --git a/test/multi/algorithms/multi_covered_by.vcproj b/test/multi/algorithms/multi_covered_by.vcproj new file mode 100644 index 000000000..87a62a938 --- /dev/null +++ b/test/multi/algorithms/multi_covered_by.vcproj @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/multi/algorithms/multi_within.cpp b/test/multi/algorithms/multi_within.cpp index a3815b686..9c4f64ef6 100644 --- a/test/multi/algorithms/multi_within.cpp +++ b/test/multi/algorithms/multi_within.cpp @@ -29,16 +29,20 @@ void test_all() { typedef bg::model::multi_polygon > mp; - // trivial cases + // test multi-with-one-polygon (trivial case) test_geometry("POINT(1 1)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", true); test_geometry("POINT(3 3)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", false); + test_geometry("POINT(0 1)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", false); + test_geometry("POINT(4 4)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", false); // test if it is in one of them - test_geometry("POINT(4 4)", "MULTIPOLYGON(" + std::string multi("MULTIPOLYGON(" "((0 0,0 2,2 2,2 0,0 0))" "((3 3,3 6,6 6,6 3,3 3))" - ")", - true); + ")"); + test_geometry("POINT(4 4)", multi, true); + test_geometry("POINT(1 1)", multi, true); + test_geometry("POINT(0 1)", multi, false); } int test_main( int , char* [] ) diff --git a/test/multi/multi_tests.sln b/test/multi/multi_tests.sln index bc6b4ca80..5198c3151 100644 --- a/test/multi/multi_tests.sln +++ b/test/multi/multi_tests.sln @@ -42,6 +42,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "multi_difference", "algorit EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "multi_transform", "algorithms\multi_transform.vcproj", "{64985954-0A74-46F5-908F-865E905C3414}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "multi_covered_by", "algorithms\multi_covered_by.vcproj", "{680E56F0-229C-4377-BDC0-80EB9B59314B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -132,6 +134,10 @@ Global {64985954-0A74-46F5-908F-865E905C3414}.Debug|Win32.Build.0 = Debug|Win32 {64985954-0A74-46F5-908F-865E905C3414}.Release|Win32.ActiveCfg = Release|Win32 {64985954-0A74-46F5-908F-865E905C3414}.Release|Win32.Build.0 = Release|Win32 + {680E56F0-229C-4377-BDC0-80EB9B59314B}.Debug|Win32.ActiveCfg = Debug|Win32 + {680E56F0-229C-4377-BDC0-80EB9B59314B}.Debug|Win32.Build.0 = Debug|Win32 + {680E56F0-229C-4377-BDC0-80EB9B59314B}.Release|Win32.ActiveCfg = Release|Win32 + {680E56F0-229C-4377-BDC0-80EB9B59314B}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/strategies/within.cpp b/test/strategies/within.cpp index ef6b9179c..6e0cbe955 100644 --- a/test/strategies/within.cpp +++ b/test/strategies/within.cpp @@ -11,16 +11,21 @@ #include +#include #include #include #include #include +#include +#include +#include #include #include +#include #include #include @@ -36,7 +41,7 @@ void test_point_in_polygon(std::string const& case_id, Strategy const& strategy, std::string const& strategy_id, bool expected) { - BOOST_CONCEPT_ASSERT( (bg::concept::WithinStrategy) ); + BOOST_CONCEPT_ASSERT( (bg::concept::WithinStrategyPolygonal) ); bool detected = bg::within(point, polygon, strategy); BOOST_CHECK_MESSAGE(detected == expected, @@ -68,11 +73,63 @@ void test_geometry(std::string const& case_id, std::string const& wkt_point "cross.mult", boost::contains(deviations, "c") ? !expected : expected); } +template +void test_box_of(std::string const& wkt_point, std::string const& wkt_box, + bool expected_within, bool expected_covered_by) +{ + typedef bg::model::box box_type; + + Point point; + box_type box; + bg::read_wkt(wkt_point, point); + bg::read_wkt(wkt_box, box); + + bool detected_within = bg::within(point, box); + bool detected_covered_by = bg::covered_by(point, box); + BOOST_CHECK_EQUAL(detected_within, expected_within); + BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by); + + // Also test with the non-default agnostic side version + namespace wi = bg::strategy::within; + wi::point_in_box_by_side within_strategy; + wi::point_in_box_by_side covered_by_strategy; + + detected_within = bg::within(point, box, within_strategy); + detected_covered_by = bg::covered_by(point, box, covered_by_strategy); + BOOST_CHECK_EQUAL(detected_within, expected_within); + BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by); + + // We might exchange strategies between within/covered by. + // So the lines below might seem confusing, but are as intended + detected_within = bg::covered_by(point, box, within_strategy); + detected_covered_by = bg::within(point, box, covered_by_strategy); + BOOST_CHECK_EQUAL(detected_within, expected_within); + BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by); + + // Finally we call the strategies directly + detected_within = within_strategy.apply(point, box); + detected_covered_by = covered_by_strategy.apply(point, box); + BOOST_CHECK_EQUAL(detected_within, expected_within); + BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by); +} + +template +void test_box() +{ + test_box_of("POINT(1 1)", "BOX(0 0,2 2)", true, true); + test_box_of("POINT(0 0)", "BOX(0 0,2 2)", false, true); + test_box_of("POINT(2 2)", "BOX(0 0,2 2)", false, true); + test_box_of("POINT(0 1)", "BOX(0 0,2 2)", false, true); + test_box_of("POINT(1 0)", "BOX(0 0,2 2)", false, true); + test_box_of("POINT(3 3)", "BOX(0 0,2 2)", false, false); +} template void test_all() { + test_box(); + typedef bg::model::polygon polygon; std::string const box = "POLYGON((0 0,0 2,2 2,2 0,0 0))";