]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/arithmetic/cross_product.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / geometry / test / arithmetic / cross_product.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
5 // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
6
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11
12 #include <geometry_test_common.hpp>
13
14 #include <boost/core/ignore_unused.hpp>
15
16 #include <boost/geometry/arithmetic/cross_product.hpp>
17
18 #include <boost/geometry/algorithms/assign.hpp>
19
20 #include <boost/geometry/geometries/point.hpp>
21 #include <boost/geometry/geometries/adapted/c_array.hpp>
22 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
23 #include <test_common/test_point.hpp>
24
25
26 template <typename P>
27 void test_2d()
28 {
29 P p1;
30 bg::assign_values(p1, 20, 30);
31 P p2;
32 bg::assign_values(p2, 45, 70);
33 P c = bg::cross_product(p1, p2);
34
35 typedef typename bg::coordinate_type<P>::type scalar_type;
36 BOOST_CHECK_EQUAL(bg::get<0>(c), scalar_type(50));
37 }
38
39 template <typename P>
40 void test_3d()
41 {
42 P p1;
43 bg::assign_values(p1, 20, 30, 10);
44 P p2;
45 bg::assign_values(p2, 45, 70, 20);
46 P c = bg::cross_product(p1, p2);
47
48 typedef typename bg::coordinate_type<P>::type scalar_type;
49 BOOST_CHECK_EQUAL(bg::get<0>(c), scalar_type(-100));
50 BOOST_CHECK_EQUAL(bg::get<1>(c), scalar_type(50));
51 BOOST_CHECK_EQUAL(bg::get<2>(c), scalar_type(50));
52 }
53
54 #ifdef TEST_FAIL_CROSS_PRODUCT
55 template <typename P>
56 void test_4d()
57 {
58 P p1;
59 bg::assign_values(p1, 20, 30, 10);
60 bg::set<3>(p1, 15);
61 P p2;
62 bg::assign_values(p2, 45, 70, 20);
63 bg::set<3>(p2, 35);
64 P c = bg::cross_product(p1, p2);
65 boost::ignore_unused(c);
66 }
67 #endif
68
69 int test_main(int, char* [])
70 {
71 test_2d<bg::model::point<int, 2, bg::cs::cartesian> >();
72 test_2d<bg::model::point<float, 2, bg::cs::cartesian> >();
73 test_2d<bg::model::point<double, 2, bg::cs::cartesian> >();
74
75 test_3d<bg::model::point<int, 3, bg::cs::cartesian> >();
76 test_3d<bg::model::point<float, 3, bg::cs::cartesian> >();
77 test_3d<bg::model::point<double, 3, bg::cs::cartesian> >();
78
79 #ifdef TEST_FAIL_CROSS_PRODUCT
80 test_4d<bg::model::point<int, 4, bg::cs::cartesian> >();
81 test_4d<bg::model::point<float, 4, bg::cs::cartesian> >();
82 test_4d<bg::model::point<double, 4, bg::cs::cartesian> >();
83 #endif
84
85 return 0;
86 }
87