diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-10-31 14:41:14 +0000 |
---|---|---|
committer | <> | 2014-12-12 16:07:56 +0000 |
commit | ed232fdd34968697a68783b3195b1da4226915b5 (patch) | |
tree | 7a7053ceb8874b28ec4b868d4c49b500008a102e /libs/geometry/test/strategies | |
parent | 1c3648bf5b7d17fcd4fe9bc95802b16fd9eee304 (diff) | |
download | boost-tarball-ed232fdd34968697a68783b3195b1da4226915b5.tar.gz |
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_57_0.tar.bz2.boost_1_57_0
Diffstat (limited to 'libs/geometry/test/strategies')
-rw-r--r-- | libs/geometry/test/strategies/Jamfile.v2 | 6 | ||||
-rw-r--r-- | libs/geometry/test/strategies/crossings_multiply.cpp | 87 | ||||
-rw-r--r-- | libs/geometry/test/strategies/franklin.cpp | 86 | ||||
-rw-r--r-- | libs/geometry/test/strategies/point_in_box.cpp | 81 | ||||
-rw-r--r-- | libs/geometry/test/strategies/test_within.hpp | 106 | ||||
-rw-r--r-- | libs/geometry/test/strategies/winding.cpp | 227 | ||||
-rw-r--r-- | libs/geometry/test/strategies/within.cpp | 194 |
7 files changed, 592 insertions, 195 deletions
diff --git a/libs/geometry/test/strategies/Jamfile.v2 b/libs/geometry/test/strategies/Jamfile.v2 index f3e591cf5..d32c10737 100644 --- a/libs/geometry/test/strategies/Jamfile.v2 +++ b/libs/geometry/test/strategies/Jamfile.v2 @@ -8,6 +8,7 @@ # Modifications copyright (c) 2014, Oracle and/or its affiliates. # # Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle +# Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle # # Use, modification and distribution is subject to the Boost Software License, # Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -16,8 +17,11 @@ test-suite boost-geometry-strategies : [ run cross_track.cpp ] + [ run crossings_multiply.cpp ] [ run distance_default_result.cpp ] + [ run franklin.cpp ] [ run haversine.cpp ] + [ run point_in_box.cpp ] [ run projected_point.cpp ] [ run projected_point_ax.cpp ] [ run pythagoras.cpp ] @@ -26,5 +30,5 @@ test-suite boost-geometry-strategies [ run segment_intersection_collinear.cpp ] [ run transform_cs.cpp ] [ run transformer.cpp ] - [ run within.cpp ] + [ run winding.cpp ] ; diff --git a/libs/geometry/test/strategies/crossings_multiply.cpp b/libs/geometry/test/strategies/crossings_multiply.cpp new file mode 100644 index 000000000..f57d383f1 --- /dev/null +++ b/libs/geometry/test/strategies/crossings_multiply.cpp @@ -0,0 +1,87 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// 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 <strategies/test_within.hpp> + + +template <typename Point> +void test_all() +{ + typedef bg::model::polygon<Point> polygon; + + std::string const box = "POLYGON((0 0,0 2,2 2,2 0,0 0))"; + std::string const triangle = "POLYGON((0 0,0 4,6 0,0 0))"; + std::string const with_hole = "POLYGON((0 0,0 3,3 3,3 0,0 0),(1 1,2 1,2 2,1 2,1 1))"; + + bg::strategy::within::crossings_multiply<Point> s; + + + test_geometry<Point, polygon>("b1", "POINT(1 1)", box, s, true); + test_geometry<Point, polygon>("b2", "POINT(3 3)", box, s, false); + + // Test ALL corners (officialy false but some strategies might answer true) + test_geometry<Point, polygon>("b3a", "POINT(0 0)", box, s, false); + test_geometry<Point, polygon>("b3b", "POINT(0 2)", box, s, false); + test_geometry<Point, polygon>("b3c", "POINT(2 2)", box, s, false); + test_geometry<Point, polygon>("b3d", "POINT(2 0)", box, s, false); + + // Test ALL sides (officialy false but some strategies might answer true) + test_geometry<Point, polygon>("b4a", "POINT(0 1)", box, s, false); + test_geometry<Point, polygon>("b4b", "POINT(1 2)", box, s, true); // different + test_geometry<Point, polygon>("b4c", "POINT(2 1)", box, s, false); + test_geometry<Point, polygon>("b4d", "POINT(1 0)", box, s, false); + + + test_geometry<Point, polygon>("t1", "POINT(1 1)", triangle, s, true); + test_geometry<Point, polygon>("t2", "POINT(3 3)", triangle, s, false); + + test_geometry<Point, polygon>("t3a", "POINT(0 0)", triangle, s, false); + test_geometry<Point, polygon>("t3b", "POINT(0 4)", triangle, s, true); // diff + test_geometry<Point, polygon>("t3c", "POINT(5 0)", triangle, s, false); + + test_geometry<Point, polygon>("t4a", "POINT(0 2)", triangle, s, false); + test_geometry<Point, polygon>("t4b", "POINT(3 2)", triangle, s, false); + test_geometry<Point, polygon>("t4c", "POINT(2 0)", triangle, s, false); + + + test_geometry<Point, polygon>("h1", "POINT(0.5 0.5)", with_hole, s, true); + test_geometry<Point, polygon>("h2a", "POINT(1.5 1.5)", with_hole, s, false); + test_geometry<Point, polygon>("h2b", "POINT(5 5)", with_hole, s, false); + + test_geometry<Point, polygon>("h3a", "POINT(1 1)", with_hole, s, true); // diff + test_geometry<Point, polygon>("h3b", "POINT(2 2)", with_hole, s, false); + test_geometry<Point, polygon>("h3c", "POINT(0 0)", with_hole, s, false); + + test_geometry<Point, polygon>("h4a", "POINT(1 1.5)", with_hole, s, false); + test_geometry<Point, polygon>("h4b", "POINT(1.5 2)", with_hole, s, false); + + // Lying ON (one of the sides of) interior ring + test_geometry<Point, polygon>("#77-1", "POINT(6 3.5)", + "POLYGON((5 3,5 4,4 4,4 5,3 5,3 6,5 6,5 5,7 5,7 6,8 6,8 5,9 5,9 2,8 2,8 1,7 1,7 2,5 2,5 3),(6 3,8 3,8 4,6 4,6 3))", + s, false); +} + + +int test_main(int, char* []) +{ + test_all<bg::model::point<float, 2, bg::cs::cartesian> >(); + test_all<bg::model::point<double, 2, bg::cs::cartesian> >(); + +#if defined(HAVE_TTMATH) + test_all<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >(); +#endif + + return 0; +} diff --git a/libs/geometry/test/strategies/franklin.cpp b/libs/geometry/test/strategies/franklin.cpp new file mode 100644 index 000000000..6a6c5fe17 --- /dev/null +++ b/libs/geometry/test/strategies/franklin.cpp @@ -0,0 +1,86 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// 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 <strategies/test_within.hpp> + + +template <typename Point> +void test_all() +{ + typedef bg::model::polygon<Point> polygon; + + std::string const box = "POLYGON((0 0,0 2,2 2,2 0,0 0))"; + std::string const triangle = "POLYGON((0 0,0 4,6 0,0 0))"; + std::string const with_hole = "POLYGON((0 0,0 3,3 3,3 0,0 0),(1 1,2 1,2 2,1 2,1 1))"; + + bg::strategy::within::franklin<Point> s; + + test_geometry<Point, polygon>("b1", "POINT(1 1)", box, s, true); + test_geometry<Point, polygon>("b2", "POINT(3 3)", box, s, false); + + // Test ALL corners (officialy false but some strategies might answer true) + test_geometry<Point, polygon>("b3a", "POINT(0 0)", box, s, true); // different + test_geometry<Point, polygon>("b3b", "POINT(0 2)", box, s, false); + test_geometry<Point, polygon>("b3c", "POINT(2 2)", box, s, false); + test_geometry<Point, polygon>("b3d", "POINT(2 0)", box, s, false); + + // Test ALL sides (officialy false but some strategies might answer true) + test_geometry<Point, polygon>("b4a", "POINT(0 1)", box, s, true); // different + test_geometry<Point, polygon>("b4b", "POINT(1 2)", box, s, false); + test_geometry<Point, polygon>("b4c", "POINT(2 1)", box, s, false); + test_geometry<Point, polygon>("b4d", "POINT(1 0)", box, s, true); // different + + + test_geometry<Point, polygon>("t1", "POINT(1 1)", triangle, s, true); + test_geometry<Point, polygon>("t2", "POINT(3 3)", triangle, s, false); + + test_geometry<Point, polygon>("t3a", "POINT(0 0)", triangle, s, true); // diff + test_geometry<Point, polygon>("t3b", "POINT(0 4)", triangle, s, false); + test_geometry<Point, polygon>("t3c", "POINT(5 0)", triangle, s, true); // diff + + test_geometry<Point, polygon>("t4a", "POINT(0 2)", triangle, s, true); // diff + test_geometry<Point, polygon>("t4b", "POINT(3 2)", triangle, s, false); + test_geometry<Point, polygon>("t4c", "POINT(2 0)", triangle, s, true); // diff + + + test_geometry<Point, polygon>("h1", "POINT(0.5 0.5)", with_hole, s, true); + test_geometry<Point, polygon>("h2a", "POINT(1.5 1.5)", with_hole, s, false); + test_geometry<Point, polygon>("h2b", "POINT(5 5)", with_hole, s, false); + + test_geometry<Point, polygon>("h3a", "POINT(1 1)", with_hole, s, false); + test_geometry<Point, polygon>("h3b", "POINT(2 2)", with_hole, s, true); // diff + test_geometry<Point, polygon>("h3c", "POINT(0 0)", with_hole, s, true); // diff + + test_geometry<Point, polygon>("h4a", "POINT(1 1.5)", with_hole, s, false); + test_geometry<Point, polygon>("h4b", "POINT(1.5 2)", with_hole, s, true); // diff + + // Lying ON (one of the sides of) interior ring + test_geometry<Point, polygon>("#77-1", "POINT(6 3.5)", + "POLYGON((5 3,5 4,4 4,4 5,3 5,3 6,5 6,5 5,7 5,7 6,8 6,8 5,9 5,9 2,8 2,8 1,7 1,7 2,5 2,5 3),(6 3,8 3,8 4,6 4,6 3))", + s, false); +} + + +int test_main(int, char* []) +{ + test_all<bg::model::point<float, 2, bg::cs::cartesian> >(); + test_all<bg::model::point<double, 2, bg::cs::cartesian> >(); + +#if defined(HAVE_TTMATH) + test_all<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >(); +#endif + + return 0; +} diff --git a/libs/geometry/test/strategies/point_in_box.cpp b/libs/geometry/test/strategies/point_in_box.cpp new file mode 100644 index 000000000..1c5e04879 --- /dev/null +++ b/libs/geometry/test/strategies/point_in_box.cpp @@ -0,0 +1,81 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// 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 <strategies/test_within.hpp> + + +template <typename Point> +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<Point> 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<Point, box_type> within_strategy; + wi::point_in_box_by_side<Point, box_type, wi::decide_covered_by> 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 <typename Point> +void test_box() +{ + test_box_of<Point>("POINT(1 1)", "BOX(0 0,2 2)", true, true); + test_box_of<Point>("POINT(0 0)", "BOX(0 0,2 2)", false, true); + test_box_of<Point>("POINT(2 2)", "BOX(0 0,2 2)", false, true); + test_box_of<Point>("POINT(0 1)", "BOX(0 0,2 2)", false, true); + test_box_of<Point>("POINT(1 0)", "BOX(0 0,2 2)", false, true); + test_box_of<Point>("POINT(3 3)", "BOX(0 0,2 2)", false, false); +} + + +int test_main(int, char* []) +{ + test_box<bg::model::point<float, 2, bg::cs::cartesian> >(); + test_box<bg::model::point<double, 2, bg::cs::cartesian> >(); + +#if defined(HAVE_TTMATH) + test_box<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >(); +#endif + + return 0; +} diff --git a/libs/geometry/test/strategies/test_within.hpp b/libs/geometry/test/strategies/test_within.hpp new file mode 100644 index 000000000..4ceb2608e --- /dev/null +++ b/libs/geometry/test/strategies/test_within.hpp @@ -0,0 +1,106 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// 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) + +#ifndef BOOST_GEOMETRY_TEST_STRATEGIES_TEST_WITHIN_HPP +#define BOOST_GEOMETRY_TEST_STRATEGIES_TEST_WITHIN_HPP + + +#include <geometry_test_common.hpp> + +#include <boost/geometry/algorithms/covered_by.hpp> +#include <boost/geometry/algorithms/within.hpp> + +#include <boost/geometry/strategies/cartesian/point_in_poly_franklin.hpp> +#include <boost/geometry/strategies/cartesian/point_in_poly_crossings_multiply.hpp> +#include <boost/geometry/strategies/agnostic/point_in_poly_winding.hpp> +#include <boost/geometry/strategies/cartesian/point_in_box.hpp> +#include <boost/geometry/strategies/cartesian/box_in_box.hpp> +#include <boost/geometry/strategies/agnostic/point_in_box_by_side.hpp> + +#include <boost/geometry/strategies/cartesian/side_by_triangle.hpp> +#include <boost/geometry/strategies/spherical/ssf.hpp> + + +#include <boost/geometry/geometries/point.hpp> +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/polygon.hpp> + +#include <boost/geometry/io/wkt/wkt.hpp> + + +template <typename Strategy> +inline const char * strategy_name(Strategy const&) +{ + return typeid(Strategy).name(); +} + +template <typename P, typename PoS, typename CT> +inline const char * strategy_name(bg::strategy::within::crossings_multiply<P, PoS, CT> const&) +{ + return "crossings_multiply"; +} + +template <typename P, typename PoS, typename CT> +inline const char * strategy_name(bg::strategy::within::franklin<P, PoS, CT> const&) +{ + return "franklin"; +} + +template <typename P, typename PoS, typename CT> +inline const char * strategy_name(bg::strategy::within::winding<P, PoS, CT> const&) +{ + return "winding"; +} + + +template <typename Point, typename Polygon, typename Strategy> +void test_point_in_polygon(std::string const& case_id, + Point const& point, + Polygon const& polygon, + Strategy const& strategy, + bool expected, + bool use_within = true) +{ + BOOST_CONCEPT_ASSERT( (bg::concept::WithinStrategyPolygonal<Strategy>) ); + bool detected = use_within ? + bg::within(point, polygon, strategy) : + bg::covered_by(point, polygon, strategy); + + BOOST_CHECK_MESSAGE(detected == expected, + (use_within ? "within: " : "covered_by: ") << case_id + << " strategy: " << strategy_name(strategy) + << " output expected: " << int(expected) + << " detected: " << int(detected) + ); +} + + +template <typename Point, typename Polygon, typename Strategy> +void test_geometry(std::string const& case_id, + std::string const& wkt_point, + std::string const& wkt_polygon, + Strategy const& strategy, + bool expected, + bool use_within = true) +{ + Point point; + Polygon polygon; + bg::read_wkt(wkt_point, point); + bg::read_wkt(wkt_polygon, polygon); + + test_point_in_polygon(case_id, point, polygon, strategy, expected, use_within); +} + + +#endif // BOOST_GEOMETRY_TEST_STRATEGIES_TEST_WITHIN_HPP diff --git a/libs/geometry/test/strategies/winding.cpp b/libs/geometry/test/strategies/winding.cpp new file mode 100644 index 000000000..ff0f3605a --- /dev/null +++ b/libs/geometry/test/strategies/winding.cpp @@ -0,0 +1,227 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// 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 <strategies/test_within.hpp> + + +template <typename Point> +void test_cartesian() +{ + typedef bg::model::polygon<Point> polygon; + + std::string const box = "POLYGON((0 0,0 2,2 2,2 0,0 0))"; + std::string const triangle = "POLYGON((0 0,0 4,6 0,0 0))"; + std::string const with_hole = "POLYGON((0 0,0 3,3 3,3 0,0 0),(1 1,2 1,2 2,1 2,1 1))"; + + bg::strategy::within::winding<Point> s; + + + test_geometry<Point, polygon>("b1", "POINT(1 1)", box, s, true); + test_geometry<Point, polygon>("b2", "POINT(3 3)", box, s, false); + + // Test ALL corners (officialy false but some strategies might answer true) + test_geometry<Point, polygon>("b3a", "POINT(0 0)", box, s, false); + test_geometry<Point, polygon>("b3b", "POINT(0 2)", box, s, false); + test_geometry<Point, polygon>("b3c", "POINT(2 2)", box, s, false); + test_geometry<Point, polygon>("b3d", "POINT(2 0)", box, s, false); + + // Test ALL sides (officialy false but some strategies might answer true) + test_geometry<Point, polygon>("b4a", "POINT(0 1)", box, s, false); + test_geometry<Point, polygon>("b4b", "POINT(1 2)", box, s, false); + test_geometry<Point, polygon>("b4c", "POINT(2 1)", box, s, false); + test_geometry<Point, polygon>("b4d", "POINT(1 0)", box, s, false); + + + test_geometry<Point, polygon>("t1", "POINT(1 1)", triangle, s, true); + test_geometry<Point, polygon>("t2", "POINT(3 3)", triangle, s, false); + + test_geometry<Point, polygon>("t3a", "POINT(0 0)", triangle, s, false); + test_geometry<Point, polygon>("t3b", "POINT(0 4)", triangle, s, false); + test_geometry<Point, polygon>("t3c", "POINT(5 0)", triangle, s, false); + + test_geometry<Point, polygon>("t4a", "POINT(0 2)", triangle, s, false); + test_geometry<Point, polygon>("t4b", "POINT(3 2)", triangle, s, false); + test_geometry<Point, polygon>("t4c", "POINT(2 0)", triangle, s, false); + + + test_geometry<Point, polygon>("h1", "POINT(0.5 0.5)", with_hole, s, true); + test_geometry<Point, polygon>("h2a", "POINT(1.5 1.5)", with_hole, s, false); + test_geometry<Point, polygon>("h2b", "POINT(5 5)", with_hole, s, false); + + test_geometry<Point, polygon>("h3a", "POINT(1 1)", with_hole, s, false); + test_geometry<Point, polygon>("h3b", "POINT(2 2)", with_hole, s, false); + test_geometry<Point, polygon>("h3c", "POINT(0 0)", with_hole, s, false); + + test_geometry<Point, polygon>("h4a", "POINT(1 1.5)", with_hole, s, false); + test_geometry<Point, polygon>("h4b", "POINT(1.5 2)", with_hole, s, false); + + // Lying ON (one of the sides of) interior ring + test_geometry<Point, polygon>("#77-1", "POINT(6 3.5)", + "POLYGON((5 3,5 4,4 4,4 5,3 5,3 6,5 6,5 5,7 5,7 6,8 6,8 5,9 5,9 2,8 2,8 1,7 1,7 2,5 2,5 3),(6 3,8 3,8 4,6 4,6 3))", + s, false); +} + +template <typename T> +void test_spherical() +{ + typedef bg::model::point<T, 2, bg::cs::spherical_equatorial<bg::degree> > point; + typedef bg::model::polygon<point> polygon; + + bg::strategy::within::winding<point> s; + + + // Ticket #9354 + test_geometry<point, polygon>( + "#9354", + "POINT(-78.1239 25.9556)", + "POLYGON((-97.08466667 25.95683333, -97.13683333 25.954, -97.1 26, -97.08466667 25.95683333))", + s, + false); + +#ifdef BOOST_GEOMETRY_TEST_STRATEGIES_WINDING_ENABLE_FAILING_TESTS + + test_geometry<point, polygon>( + "sph1N", + "POINT(0 10.001)", + "POLYGON((-10 10, 10 10, 10 -10, -10 -10, -10 10))", + s, + bg::strategy::side::spherical_side_formula<>::apply( + point(-10, 10), + point(10, 10), + point(0, (T)10.001)) == -1 // right side + /*true*/); + test_geometry<point, polygon>( + "sph1S", + "POINT(0 -10.001)", + "POLYGON((-10 10, 10 10, 10 -10, -10 -10, -10 10))", + s, + bg::strategy::side::spherical_side_formula<>::apply( + point(10, -10), + point(-10, -10), + point(0, (T)-10.001)) == -1 // right side + /*true*/); + + test_geometry<point, polygon>( + "sph2S", + "POINT(0 10.001)", + "POLYGON((-10 20, 10 20, 10 10, -10 10, -10 20))", + s, + bg::strategy::side::spherical_side_formula<>::apply( + point(10, 10), + point(-10, 10), + point(0, (T)10.001)) == -1 // right side + /*false*/); + + test_geometry<point, polygon>( + "sph3N", + "POINT(0 10)", + "POLYGON((-10 10, 10 10, 10 -10, -10 -10, -10 10))", + s, + bg::strategy::side::spherical_side_formula<>::apply( + point(-10, 10), + point(10, 10), + point(0, (T)10.001)) == -1 // right side + /*true*/); + test_geometry<point, polygon>( + "sph3S", + "POINT(0 -10)", + "POLYGON((-10 10, 10 10, 10 -10, -10 -10, -10 10))", + s, + bg::strategy::side::spherical_side_formula<>::apply( + point(10, -10), + point(-10, -10), + point(0, (T)-10.001)) == -1 // right side + /*true*/); + +#endif // BOOST_GEOMETRY_TEST_STRATEGIES_WINDING_ENABLE_FAILING_TESTS + + test_geometry<point, polygon>( + "sphEq1", + "POINT(179 10)", + "POLYGON((170 10, -170 10, -170 0, 170 0, 170 10))", + s, + true, + false); + test_geometry<point, polygon>( + "sphEq2", + "POINT(179 10)", + "POLYGON((170 20, -170 20, -170 10, 170 10, 170 20))", + s, + true, + false); + test_geometry<point, polygon>( + "sphEq3", + "POINT(-179 10)", + "POLYGON((170 10, -170 10, -170 0, 170 0, 170 10))", + s, + true, + false); + test_geometry<point, polygon>( + "sphEq4", + "POINT(-179 10)", + "POLYGON((170 20, -170 20, -170 10, 170 10, 170 20))", + s, + true, + false); + +#ifdef BOOST_GEOMETRY_TEST_STRATEGIES_WINDING_ENABLE_FAILING_TESTS + + test_geometry<point, polygon>( + "sphEq5", + "POINT(169 10)", + "POLYGON((170 20, -170 20, -170 10, 170 10, 170 20))", + s, + false, + false); + test_geometry<point, polygon>( + "sphEq6", + "POINT(-169 10)", + "POLYGON((170 20, -170 20, -170 10, 170 10, 170 20))", + s, + false, + false); + test_geometry<point, polygon>( + "sphEq7", + "POINT(169 10)", + "POLYGON((170 10, -170 10, -170 0, 170 0, 170 10))", + s, + false, + false); + test_geometry<point, polygon>( + "sphEq8", + "POINT(-169 10)", + "POLYGON((170 10, -170 10, -170 0, 170 0, 170 10))", + s, + false, + false); + +#endif // BOOST_GEOMETRY_TEST_STRATEGIES_WINDING_ENABLE_FAILING_TESTS +} + +int test_main(int, char* []) +{ + test_cartesian<bg::model::point<float, 2, bg::cs::cartesian> >(); + test_cartesian<bg::model::point<double, 2, bg::cs::cartesian> >(); + + test_spherical<float>(); + test_spherical<double>(); + +#if defined(HAVE_TTMATH) + test_cartesian<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >(); + test_spherical<ttmath_big>(); +#endif + + return 0; +} diff --git a/libs/geometry/test/strategies/within.cpp b/libs/geometry/test/strategies/within.cpp deleted file mode 100644 index 390e5708c..000000000 --- a/libs/geometry/test/strategies/within.cpp +++ /dev/null @@ -1,194 +0,0 @@ -// Boost.Geometry (aka GGL, Generic Geometry Library) -// Unit Test - -// Copyright (c) 2010-2012 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) - -// Tests with-strategies, especially point-in-polygon - -#include <geometry_test_common.hpp> - -#include <boost/geometry/algorithms/covered_by.hpp> -#include <boost/geometry/algorithms/within.hpp> - -#include <boost/geometry/strategies/cartesian/point_in_poly_franklin.hpp> -#include <boost/geometry/strategies/cartesian/point_in_poly_crossings_multiply.hpp> -#include <boost/geometry/strategies/agnostic/point_in_poly_winding.hpp> -#include <boost/geometry/strategies/cartesian/point_in_box.hpp> -#include <boost/geometry/strategies/cartesian/box_in_box.hpp> -#include <boost/geometry/strategies/agnostic/point_in_box_by_side.hpp> - -#include <boost/geometry/strategies/cartesian/side_by_triangle.hpp> - - -#include <boost/geometry/geometries/point.hpp> -#include <boost/geometry/geometries/box.hpp> -#include <boost/geometry/geometries/polygon.hpp> - -#include <boost/geometry/io/wkt/wkt.hpp> - - - - - - -template <typename Point, typename Polygon, typename Strategy> -void test_point_in_polygon(std::string const& case_id, - Point const& point, Polygon const& polygon, - Strategy const& strategy, std::string const& strategy_id, - bool expected) -{ - BOOST_CONCEPT_ASSERT( (bg::concept::WithinStrategyPolygonal<Strategy>) ); - bool detected = bg::within(point, polygon, strategy); - - BOOST_CHECK_MESSAGE(detected == expected, - "within: " << case_id - << " strategy: " << strategy_id // typeid(strategy).name() is too long - << " output expected: " << int(expected) - << " detected: " << int(detected) - ); -} - -template <typename Point, typename Polygon> -void test_geometry(std::string const& case_id, std::string const& wkt_point - , std::string const& wkt_polygon - , bool expected - , std::string const& deviations = "" - ) -{ - Point point; - Polygon polygon; - bg::read_wkt(wkt_point, point); - bg::read_wkt(wkt_polygon, polygon); - - namespace sw = bg::strategy::within; - test_point_in_polygon(case_id, point, polygon, sw::winding<Point>(), - "winding", expected); - test_point_in_polygon(case_id, point, polygon, sw::franklin<Point>(), - "franklin", boost::contains(deviations, "f") ? !expected : expected); - test_point_in_polygon(case_id, point, polygon, sw::crossings_multiply<Point>(), - "cross.mult", boost::contains(deviations, "c") ? !expected : expected); -} - -template <typename Point> -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<Point> 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<Point, box_type> within_strategy; - wi::point_in_box_by_side<Point, box_type, wi::decide_covered_by> 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 <typename Point> -void test_box() -{ - test_box_of<Point>("POINT(1 1)", "BOX(0 0,2 2)", true, true); - test_box_of<Point>("POINT(0 0)", "BOX(0 0,2 2)", false, true); - test_box_of<Point>("POINT(2 2)", "BOX(0 0,2 2)", false, true); - test_box_of<Point>("POINT(0 1)", "BOX(0 0,2 2)", false, true); - test_box_of<Point>("POINT(1 0)", "BOX(0 0,2 2)", false, true); - test_box_of<Point>("POINT(3 3)", "BOX(0 0,2 2)", false, false); -} - - -template <typename Point> -void test_all() -{ - test_box<Point>(); - - typedef bg::model::polygon<Point> polygon; - - std::string const box = "POLYGON((0 0,0 2,2 2,2 0,0 0))"; - std::string const triangle = "POLYGON((0 0,0 4,6 0,0 0))"; - std::string const with_hole = "POLYGON((0 0,0 3,3 3,3 0,0 0),(1 1,2 1,2 2,1 2,1 1))"; - - - test_geometry<Point, polygon>("b1", "POINT(1 1)", box, true); - test_geometry<Point, polygon>("b2", "POINT(3 3)", box, false); - - // Test ALL corners (officialy false but some strategies might answer true) - test_geometry<Point, polygon>("b3a", "POINT(0 0)", box, false, "f"); - test_geometry<Point, polygon>("b3b", "POINT(0 2)", box, false); - test_geometry<Point, polygon>("b3c", "POINT(2 2)", box, false); - test_geometry<Point, polygon>("b3d", "POINT(2 0)", box, false); - - // Test ALL sides (officialy false but some strategies might answer true) - test_geometry<Point, polygon>("b4a", "POINT(0 1)", box, false, "f"); - test_geometry<Point, polygon>("b4b", "POINT(1 2)", box, false, "c"); - test_geometry<Point, polygon>("b4c", "POINT(2 1)", box, false); - test_geometry<Point, polygon>("b4d", "POINT(1 0)", box, false, "f"); - - - test_geometry<Point, polygon>("t1", "POINT(1 1)", triangle, true); - test_geometry<Point, polygon>("t2", "POINT(3 3)", triangle, false); - - test_geometry<Point, polygon>("t3a", "POINT(0 0)", triangle, false, "f"); - test_geometry<Point, polygon>("t3b", "POINT(0 4)", triangle, false, "c"); - test_geometry<Point, polygon>("t3c", "POINT(5 0)", triangle, false, "f"); - - test_geometry<Point, polygon>("t4a", "POINT(0 2)", triangle, false, "f"); - test_geometry<Point, polygon>("t4b", "POINT(3 2)", triangle, false); - test_geometry<Point, polygon>("t4c", "POINT(2 0)", triangle, false, "f"); - - - test_geometry<Point, polygon>("h1", "POINT(0.5 0.5)", with_hole, true); - test_geometry<Point, polygon>("h2a", "POINT(1.5 1.5)", with_hole, false); - test_geometry<Point, polygon>("h2b", "POINT(5 5)", with_hole, false); - - test_geometry<Point, polygon>("h3a", "POINT(1 1)", with_hole, false, "c"); - test_geometry<Point, polygon>("h3b", "POINT(2 2)", with_hole, false, "f"); - test_geometry<Point, polygon>("h3c", "POINT(0 0)", with_hole, false, "f"); - - test_geometry<Point, polygon>("h4a", "POINT(1 1.5)", with_hole, false); - test_geometry<Point, polygon>("h4b", "POINT(1.5 2)", with_hole, false, "f"); - - // Lying ON (one of the sides of) interior ring - test_geometry<Point, polygon>("#77-1", "POINT(6 3.5)", "POLYGON((5 3,5 4,4 4,4 5,3 5,3 6,5 6,5 5,7 5,7 6,8 6,8 5,9 5,9 2,8 2,8 1,7 1,7 2,5 2,5 3),(6 3,8 3,8 4,6 4,6 3))", false); -} - - -int test_main(int, char* []) -{ - test_all<bg::model::point<float, 2, bg::cs::cartesian> >(); - test_all<bg::model::point<double, 2, bg::cs::cartesian> >(); - -#if defined(HAVE_TTMATH) - test_all<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >(); -#endif - - return 0; -} |