• 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 <iostream>
16 
17 #include <geometry_test_common.hpp>
18 
19 #include <boost/core/ignore_unused.hpp>
20 
21 #include <boost/geometry/geometries/concepts/segment_concept.hpp>
22 
23 #include <boost/geometry/geometries/point.hpp>
24 #include <boost/geometry/geometries/segment.hpp>
25 
26 
27 #include <boost/geometry/geometries/adapted/c_array.hpp>
28 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
29 
30 #include <boost/geometry/io/dsv/write.hpp>
31 
32 
33 #include <test_common/test_point.hpp>
34 #include <test_geometries/custom_segment.hpp>
35 
36 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)37 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
38 
39 
40 template <typename P>
41 void test_all()
42 {
43     typedef bg::model::referring_segment<P> S;
44 
45     P p1;
46     P p2;
47     S s(p1, p2);
48     BOOST_CHECK_EQUAL(&s.first, &p1);
49     BOOST_CHECK_EQUAL(&s.second, &p2);
50 
51     // Compilation tests, all things should compile.
52     BOOST_CONCEPT_ASSERT( (bg::concepts::ConstSegment<S>) );
53     BOOST_CONCEPT_ASSERT( (bg::concepts::Segment<S>) );
54 
55     typedef typename bg::coordinate_type<S>::type T;
56     typedef typename bg::point_type<S>::type SP;
57     boost::ignore_unused<T, SP>();
58 
59     //std::cout << sizeof(typename coordinate_type<S>::type) << std::endl;
60 
61     typedef bg::model::referring_segment<P const> refseg_t;
62     //BOOST_CONCEPT_ASSERT( (concepts::ConstSegment<refseg_t>) );
63 
64     refseg_t seg(p1, p2);
65 
66     typedef typename bg::coordinate_type<refseg_t>::type CT;
67     typedef typename bg::point_type<refseg_t>::type CSP;
68     boost::ignore_unused<CT, CSP>();
69 }
70 
71 
72 
73 template <typename S>
test_custom()74 void test_custom()
75 {
76     S seg;
77     bg::set<0,0>(seg, 1);
78     bg::set<0,1>(seg, 2);
79     bg::set<1,0>(seg, 3);
80     bg::set<1,1>(seg, 4);
81     std::ostringstream out;
82     out << bg::dsv(seg);
83     BOOST_CHECK_EQUAL(out.str(), "((1, 2), (3, 4))");
84 }
85 
86 
test_main(int,char * [])87 int test_main(int, char* [])
88 {
89     test_all<int[3]>();
90     test_all<float[3]>();
91     test_all<double[3]>();
92     //test_all<test_point>();
93     test_all<bg::model::point<int, 3, bg::cs::cartesian> >();
94     test_all<bg::model::point<float, 3, bg::cs::cartesian> >();
95     test_all<bg::model::point<double, 3, bg::cs::cartesian> >();
96 
97     test_custom<test::custom_segment>();
98     test_custom<test::custom_segment_of<bg::model::point<double, 2, bg::cs::cartesian> > >();
99     test_custom<test::custom_segment_of<test::custom_point_for_segment> >();
100     test_custom<test::custom_segment_4>();
101 
102     return 0;
103 }
104 
105