]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | // Unit Test | |
3 | ||
4 | // Copyright (c) 2020 Digvijay Janartha, Hamirpur, India. | |
5 | ||
20effc67 TL |
6 | // This file was modified by Oracle on 2020. |
7 | // Modifications copyright (c) 2020, Oracle and/or its affiliates. | |
8 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle | |
9 | ||
f67539c2 TL |
10 | // Use, modification and distribution is subject to the Boost Software License, |
11 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
12 | // http://www.boost.org/LICENSE_1_0.txt) | |
13 | ||
14 | ||
15 | #include <geometry_test_common.hpp> | |
16 | ||
17 | #include <boost/core/ignore_unused.hpp> | |
18 | #include <boost/geometry/algorithms/make.hpp> | |
19 | #include <boost/geometry/geometries/concepts/point_concept.hpp> | |
20 | #include <boost/geometry/geometries/point.hpp> | |
21 | ||
22 | #include <test_common/test_point.hpp> | |
23 | ||
24 | ||
25 | template <typename T, typename CS> | |
26 | bg::model::point<T, 3, CS> create_point() | |
27 | { | |
28 | T t1 = 1; | |
29 | T t2 = 2; | |
30 | T t3 = 3; | |
31 | return bg::model::point<T, 3, CS>(t1, t2, t3); | |
32 | } | |
33 | ||
34 | template <typename P, typename T> | |
35 | void check_point(P& to_check, T x, T y, T z) | |
36 | { | |
37 | BOOST_CHECK_EQUAL(bg::get<0>(to_check), x); | |
38 | BOOST_CHECK_EQUAL(bg::get<1>(to_check), y); | |
39 | BOOST_CHECK_EQUAL(bg::get<2>(to_check), z); | |
40 | } | |
41 | ||
42 | template <typename T, typename CS> | |
43 | void test_default_constructor() | |
44 | { | |
45 | bg::model::point<T, 3, CS> p(create_point<T, CS>()); | |
46 | check_point(p, 1, 2, 3); | |
47 | } | |
48 | ||
49 | template <typename T, typename CS> | |
50 | void test_copy_constructor() | |
51 | { | |
52 | bg::model::point<T, 3, CS> p = create_point<T, CS>(); | |
53 | check_point(p, 1, 2, 3); | |
54 | } | |
55 | ||
56 | template <typename T, typename CS> | |
57 | void test_copy_assignment() | |
58 | { | |
59 | bg::model::point<T, 3, CS> p(create_point<T, CS>()); | |
60 | bg::set<0>(p, 4); | |
61 | bg::set<1>(p, 5); | |
62 | bg::set<2>(p, 6); | |
63 | check_point(p, 4, 5, 6); | |
64 | } | |
65 | ||
66 | template <typename T, typename CS> | |
67 | void test_concept() | |
68 | { | |
69 | typedef bg::model::point<T, 3, CS> P; | |
70 | ||
71 | // Compilation tests, all things should compile. | |
72 | BOOST_CONCEPT_ASSERT( (bg::concepts::ConstPoint<P>) ); | |
73 | BOOST_CONCEPT_ASSERT( (bg::concepts::Point<P>) ); | |
74 | ||
75 | typedef typename bg::coordinate_type<P>::type T1; | |
76 | boost::ignore_unused<T1>(); | |
77 | } | |
78 | ||
20effc67 TL |
79 | template <typename T, typename CS> |
80 | void test_constexpr() | |
81 | { | |
82 | typedef bg::model::point<T, 3, CS> P; | |
83 | constexpr P p1 = P(1, 2, 3); | |
84 | constexpr P p2 = P(4, 5); | |
85 | constexpr T c1 = bg::get<0>(p1); | |
86 | constexpr T c2 = bg::get<2>(p2); | |
87 | BOOST_CHECK_EQUAL(c1, 1); | |
88 | BOOST_CHECK_EQUAL(c2, 0); | |
89 | check_point(p1, 1, 2, 3); | |
90 | check_point(p2, 4, 5, 0); | |
91 | } | |
92 | ||
f67539c2 TL |
93 | template <typename T, typename CS> |
94 | void test_all() | |
95 | { | |
96 | test_default_constructor<T, CS>(); | |
97 | test_copy_constructor<T, CS>(); | |
98 | test_copy_assignment<T, CS>(); | |
99 | test_concept<T, CS>(); | |
20effc67 | 100 | test_constexpr<T, CS>(); |
f67539c2 TL |
101 | } |
102 | ||
103 | template <typename CS> | |
104 | void test_cs() | |
105 | { | |
106 | test_all<int, CS>(); | |
107 | test_all<float, CS>(); | |
108 | test_all<double, CS>(); | |
109 | } | |
110 | ||
f67539c2 TL |
111 | int test_main(int, char* []) |
112 | { | |
113 | test_cs<bg::cs::cartesian>(); | |
114 | test_cs<bg::cs::spherical<bg::degree> >(); | |
115 | test_cs<bg::cs::spherical_equatorial<bg::degree> >(); | |
116 | test_cs<bg::cs::geographic<bg::degree> >(); | |
117 | ||
118 | return 0; | |
119 | } |