1 // Boost.Geometry Index
2 // Unit Test
3
4 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 #include <algorithm>
11
12 #include <geometry_index_test_common.hpp>
13
14 #include <boost/geometry/index/detail/algorithms/minmaxdist.hpp>
15
16 #include <boost/geometry/geometries/point_xy.hpp>
17 #include <boost/geometry/geometries/point.hpp>
18 #include <boost/geometry/geometries/box.hpp>
19
20 #define BOOST_GEOMETRY_TEST_DEBUG
21
22 template <typename Point, typename Indexable>
test(Point const & pt,Indexable const & indexable,typename bg::default_distance_result<Point,Indexable>::type expected_value)23 void test(Point const& pt, Indexable const& indexable,
24 typename bg::default_distance_result<Point, Indexable>::type expected_value)
25 {
26 typename bg::default_distance_result<Point, Indexable>::type value = bgi::detail::minmaxdist(pt, indexable);
27
28 #ifdef BOOST_GEOMETRY_TEST_DEBUG
29 std::ostringstream out;
30 out << typeid(typename bg::coordinate_type<Point>::type).name()
31 << " "
32 << typeid(typename bg::coordinate_type<Indexable>::type).name()
33 << " "
34 << typeid(bg::default_distance_result<Point, Indexable>::type).name()
35 << " "
36 << "minmaxdist : " << value
37 << std::endl;
38 std::cout << out.str();
39 #endif
40
41 BOOST_CHECK_CLOSE(value, expected_value, 0.0001);
42 }
43
44 template <typename Indexable, typename Point>
test_indexable(Point const & pt,std::string const & wkt,typename bg::default_distance_result<Point,Indexable>::type expected_value)45 void test_indexable(Point const& pt, std::string const& wkt,
46 typename bg::default_distance_result<Point, Indexable>::type expected_value)
47 {
48 Indexable indexable;
49 bg::read_wkt(wkt, indexable);
50 test(pt, indexable, expected_value);
51 }
52
test_large_integers()53 void test_large_integers()
54 {
55 typedef bg::model::point<int, 2, bg::cs::cartesian> int_point_type;
56 typedef bg::model::point<double, 2, bg::cs::cartesian> double_point_type;
57
58 int_point_type int_pt(0, 0);
59 double_point_type double_pt(0, 0);
60
61 bg::model::box<int_point_type> int_box;
62 bg::model::box<double_point_type> double_box;
63
64 std::string const box_li = "POLYGON((1536119 192000, 1872000 528000))";
65 bg::read_wkt(box_li, int_box);
66 bg::read_wkt(box_li, double_box);
67
68 BOOST_CHECK(bgi::detail::minmaxdist(int_pt, int_box) == bgi::detail::minmaxdist(double_pt, double_box));
69 }
70
test_main(int,char * [])71 int test_main(int, char* [])
72 {
73 typedef bg::model::point<int, 2, bg::cs::cartesian> P2ic;
74 typedef bg::model::point<float, 2, bg::cs::cartesian> P2fc;
75 typedef bg::model::point<double, 2, bg::cs::cartesian> P2dc;
76
77 typedef bg::model::point<int, 3, bg::cs::cartesian> P3ic;
78 typedef bg::model::point<float, 3, bg::cs::cartesian> P3fc;
79 typedef bg::model::point<double, 3, bg::cs::cartesian> P3dc;
80
81 test_indexable<bg::model::box<P2ic> >(P2ic(1, 2), "POLYGON((0 1,2 4))", 5.0);
82 test_indexable<bg::model::box<P2fc> >(P2fc(1, 2), "POLYGON((0 1,2 4))", 5.0);
83 test_indexable<bg::model::box<P2dc> >(P2dc(1, 2), "POLYGON((0 1,2 4))", 5.0);
84 test_indexable<bg::model::box<P3ic> >(P3ic(1, 2, 3), "POLYGON((0 1 2,2 4 6))", 14.0);
85 test_indexable<bg::model::box<P3fc> >(P3fc(1, 2, 3), "POLYGON((0 1 2,2 4 6))", 14.0);
86 test_indexable<bg::model::box<P3dc> >(P3dc(1, 2, 3), "POLYGON((0 1 2,2 4 6))", 14.0);
87
88 test_indexable<bg::model::box<P2ic> >(P2ic(1, 2), "POLYGON((1 2,3 5))", 4.0);
89
90 #ifdef HAVE_TTMATH
91 typedef bg::model::point<ttmath_big, 2, bg::cs::cartesian> P2ttmc;
92 typedef bg::model::point<ttmath_big, 3, bg::cs::cartesian> P3ttmc;
93
94 test_indexable<bg::model::box<P2ttmc> >(P2ttmc(1, 2), "POLYGON((0 1,2 4))", 5.0);
95 test_indexable<bg::model::box<P3ttmc> >(P3ttmc(1, 2, 3), "POLYGON((0 1 2,2 4 6))", 14.0);
96 #endif
97
98 test_large_integers();
99
100 return 0;
101 }
102