1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
6 // This file was modified by Oracle on 2015.
7 // Modifications copyright (c) 2015, Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
15 #ifndef BOOST_GEOMETRY_TEST_CENTROID_HPP
16 #define BOOST_GEOMETRY_TEST_CENTROID_HPP
18 // Test-functionality, shared between single and multi tests
20 #include <boost/variant/variant.hpp>
22 #include <geometry_test_common.hpp>
24 #include <boost/geometry/strategies/strategies.hpp>
25 #include <boost/geometry/algorithms/centroid.hpp>
26 #include <boost/geometry/algorithms/distance.hpp>
27 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
29 #include <boost/geometry/io/wkt/read.hpp>
32 template <std::size_t D>
35 template <typename Point1, typename Point2>
36 static void apply(Point1 const& actual, Point2 const& expected)
38 check_result<D-1>::apply(actual, expected);
40 BOOST_CHECK_CLOSE(bg::get<D-1>(actual), bg::get<D-1>(expected), 0.001);
45 struct check_result<0>
47 template <typename Point1, typename Point2>
48 static void apply(Point1 const&, Point2 const&)
53 template <typename CalculationType, typename Geometry, typename Point>
54 void test_with_other_calculation_type(Geometry const& geometry, Point& c1)
56 typedef typename bg::point_type<Geometry>::type point_type;
57 // Calculate it with user defined strategy
59 bg::centroid(geometry, c2,
60 bg::strategy::centroid::bashein_detmer<Point, point_type, CalculationType>());
62 std::cout << typeid(CalculationType).name() << ": " << std::setprecision(20)
63 << bg::get<0>(c2) << " " << bg::get<1>(c2)
64 << " -> difference: " << bg::distance(c1, c2)
68 template <typename Geometry, typename Point, typename T>
69 void test_centroid(Geometry const& geometry, T const& d1, T const& d2, T const& d3 = T(), T const& d4 = T(), T const& d5 = T())
73 bg::centroid(geometry, c1);
74 check_result<bg::dimension<Geometry>::type::value>::apply(c1, boost::make_tuple(d1, d2, d3, d4, d5));
76 boost::variant<Geometry> v(geometry);
80 std::cout << "normal: " << std::setprecision(20) << bg::get<0>(c1) << " " << bg::get<1>(c1) << std::endl;
82 //test_with_other_calculation_type<long long>(geometry, c1);
83 test_with_other_calculation_type<float>(geometry, c1);
84 test_with_other_calculation_type<long double>(geometry, c1);
85 #if defined(HAVE_TTMATH)
86 test_with_other_calculation_type<ttmath_big>(geometry, c1);
92 template <typename Geometry, typename Point, typename T>
93 void test_centroid(std::string const& wkt, T const& d1, T const& d2, T const& d3 = T(), T const& d4 = T(), T const& d5 = T())
96 bg::read_wkt(wkt, geometry);
98 test_centroid<Geometry, Point>(geometry, d1, d2, d3, d4, d5);
101 template <typename Geometry, typename T>
102 void test_centroid(Geometry const& geometry, T const& d1, T const& d2, T const& d3 = T(), T const& d4 = T(), T const& d5 = T())
104 test_centroid<Geometry, typename bg::point_type<Geometry>::type>(geometry, d1, d2, d3, d4, d5);
107 template <typename Geometry, typename T>
108 void test_centroid(std::string const& wkt, T const& d1, T const& d2, T const& d3 = T(), T const& d4 = T(), T const& d5 = T())
110 test_centroid<Geometry, typename bg::point_type<Geometry>::type>(wkt, d1, d2, d3, d4, d5);
113 template <typename Geometry>
114 void test_centroid_exception()
119 typename bg::point_type<Geometry>::type c;
120 bg::centroid(geometry, c);
122 catch(bg::centroid_exception const& )
126 BOOST_CHECK_MESSAGE(false, "A centroid_exception should have been thrown" );
129 template <typename Geometry>
130 void test_centroid_exception(std::string const& wkt)
133 bg::read_wkt(wkt, geometry);
136 typename bg::point_type<Geometry>::type c;
137 bg::centroid(geometry, c);
139 catch(bg::centroid_exception const& )
143 BOOST_CHECK_MESSAGE(false, "A centroid_exception should have been thrown" );