• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7 
8 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10 
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)
14 
15 #include <sstream>
16 
17 #include <geometry_test_common.hpp>
18 
19 
20 #include <boost/geometry/util/for_each_coordinate.hpp>
21 
22 #include <boost/geometry/algorithms/assign.hpp>
23 
24 
25 #include <boost/geometry/geometries/point.hpp>
26 #include <boost/geometry/geometries/adapted/c_array.hpp>
27 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
28 #include <test_common/test_point.hpp>
29 
30 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
31 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
32 
33 
34 struct test_operation
35 {
36     template <typename P, int I>
applytest_operation37     static void apply(P& p)
38     {
39         bg::set<I>(p, bg::get<I>(p) * 10);
40     }
41 };
42 
43 struct get_operation
44 {
45     std::string s;
46 
47     template <typename P, int I>
applyget_operation48     inline void apply(P const& p)
49     {
50         std::ostringstream out;
51         out << bg::get<I>(p);
52         s += out.str();
53     }
54 };
55 
56 
57 template <typename P>
test_all()58 void test_all()
59 {
60     P p;
61     bg::assign_values(p, 1, 2, 3);
62     bg::for_each_coordinate(p, test_operation());
63     BOOST_CHECK(bg::get<0>(p) == 10);
64     BOOST_CHECK(bg::get<1>(p) == 20);
65     BOOST_CHECK(bg::get<2>(p) == 30);
66 
67     P const& cp = p;
68     get_operation op;
69     op = bg::for_each_coordinate(cp, op);
70     BOOST_CHECK(op.s == std::string("102030"));
71 }
72 
test_main(int,char * [])73 int test_main(int, char* [])
74 {
75     test_all<int[3]>();
76     test_all<float[3]>();
77     test_all<double[3]>();
78     test_all<test::test_point>();
79     test_all<bg::model::point<int, 3, bg::cs::cartesian> >();
80     test_all<bg::model::point<float, 3, bg::cs::cartesian> >();
81     test_all<bg::model::point<double, 3, bg::cs::cartesian> >();
82 
83     return 0;
84 }
85