]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/geometries/segment.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / geometry / test / geometries / segment.cpp
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 // This file was modified by Oracle on 2020.
9 // Modifications copyright (c) 2020, Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18
19 #include <geometry_test_common.hpp>
20
21 #include <boost/core/ignore_unused.hpp>
22
23 #include <boost/geometry/geometries/concepts/segment_concept.hpp>
24
25 #include <boost/geometry/geometries/point.hpp>
26 #include <boost/geometry/geometries/segment.hpp>
27
28 #include <boost/geometry/geometries/adapted/c_array.hpp>
29 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
30
31
32 #include <test_common/test_point.hpp>
33 #include <test_geometries/custom_segment.hpp>
34
35 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
36 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
37
38
39 template <typename P>
40 void test_all()
41 {
42 typedef bg::model::referring_segment<P> S;
43
44 P p1;
45 P p2;
46 S s(p1, p2);
47 BOOST_CHECK_EQUAL(&s.first, &p1);
48 BOOST_CHECK_EQUAL(&s.second, &p2);
49
50 // Compilation tests, all things should compile.
51 BOOST_CONCEPT_ASSERT( (bg::concepts::ConstSegment<S>) );
52 BOOST_CONCEPT_ASSERT( (bg::concepts::Segment<S>) );
53
54 typedef typename bg::coordinate_type<S>::type T;
55 typedef typename bg::point_type<S>::type SP;
56 boost::ignore_unused<T, SP>();
57
58 //std::cout << sizeof(typename coordinate_type<S>::type) << std::endl;
59
60 typedef bg::model::referring_segment<P const> refseg_t;
61 //BOOST_CONCEPT_ASSERT( (concepts::ConstSegment<refseg_t>) );
62
63 refseg_t seg(p1, p2);
64
65 typedef typename bg::coordinate_type<refseg_t>::type CT;
66 typedef typename bg::point_type<refseg_t>::type CSP;
67 boost::ignore_unused<CT, CSP>();
68 }
69
70
71
72 template <typename S>
73 void test_custom()
74 {
75 S seg;
76 bg::set<0,0>(seg, 1);
77 bg::set<0,1>(seg, 2);
78 bg::set<1,0>(seg, 3);
79 bg::set<1,1>(seg, 4);
80
81 BOOST_CHECK_EQUAL((bg::get<0, 0>(seg)), 1);
82 BOOST_CHECK_EQUAL((bg::get<0, 1>(seg)), 2);
83 BOOST_CHECK_EQUAL((bg::get<1, 0>(seg)), 3);
84 BOOST_CHECK_EQUAL((bg::get<1, 1>(seg)), 4);
85 }
86
87
88 template <typename P>
89 void test_constexpr()
90 {
91 typedef bg::model::segment<P> S;
92 constexpr S s = S{ {1, 2, 3}, {4, 5} };
93 constexpr auto c1 = bg::get<0, 0>(s);
94 constexpr auto c2 = bg::get<1, 2>(s);
95 BOOST_CHECK_EQUAL(c1, 1);
96 BOOST_CHECK_EQUAL(c2, 0);
97 BOOST_CHECK_EQUAL((bg::get<0, 0>(s)), 1);
98 BOOST_CHECK_EQUAL((bg::get<0, 1>(s)), 2);
99 BOOST_CHECK_EQUAL((bg::get<0, 2>(s)), 3);
100 BOOST_CHECK_EQUAL((bg::get<1, 0>(s)), 4);
101 BOOST_CHECK_EQUAL((bg::get<1, 1>(s)), 5);
102 BOOST_CHECK_EQUAL((bg::get<1, 2>(s)), 0);
103 }
104
105
106 int test_main(int, char* [])
107 {
108 test_all<int[3]>();
109 test_all<float[3]>();
110 test_all<double[3]>();
111 //test_all<test_point>();
112 test_all<bg::model::point<int, 3, bg::cs::cartesian> >();
113 test_all<bg::model::point<float, 3, bg::cs::cartesian> >();
114 test_all<bg::model::point<double, 3, bg::cs::cartesian> >();
115
116 test_custom<test::custom_segment>();
117 test_custom<test::custom_segment_of<bg::model::point<double, 2, bg::cs::cartesian> > >();
118 test_custom<test::custom_segment_of<test::custom_point_for_segment> >();
119 test_custom<test::custom_segment_4>();
120
121 test_constexpr<bg::model::point<double, 3, bg::cs::cartesian> >();
122
123 return 0;
124 }
125