]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/arithmetic/cross_product.cpp
import quincy beta 17.1.0
[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 // This file was modified by Oracle on 2020.
8 // Modifications copyright (c) 2020, Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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
16 #include <geometry_test_common.hpp>
17
18 #include <boost/core/ignore_unused.hpp>
19
20 #include <boost/geometry/arithmetic/cross_product.hpp>
21
22 #include <boost/geometry/algorithms/assign.hpp>
23
24 #include <boost/geometry/geometries/point.hpp>
25 #include <boost/geometry/geometries/adapted/c_array.hpp>
26 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
27 #include <test_common/test_point.hpp>
28
29
30 template <typename P>
31 void test_2d()
32 {
33 P p1;
34 bg::assign_values(p1, 20, 30);
35 P p2;
36 bg::assign_values(p2, 45, 70);
37 P c = bg::cross_product(p1, p2);
38
39 typedef typename bg::coordinate_type<P>::type scalar_type;
40 BOOST_CHECK_EQUAL(bg::get<0>(c), scalar_type(50));
41 }
42
43 template <typename P>
44 void test_3d()
45 {
46 P p1;
47 bg::assign_values(p1, 20, 30, 10);
48 P p2;
49 bg::assign_values(p2, 45, 70, 20);
50 P c = bg::cross_product(p1, p2);
51
52 typedef typename bg::coordinate_type<P>::type scalar_type;
53 BOOST_CHECK_EQUAL(bg::get<0>(c), scalar_type(-100));
54 BOOST_CHECK_EQUAL(bg::get<1>(c), scalar_type(50));
55 BOOST_CHECK_EQUAL(bg::get<2>(c), scalar_type(50));
56 }
57
58 template <typename P>
59 void test_constexpr()
60 {
61 constexpr P p1 = P(20, 30, 10);
62 constexpr P p2 = P(45, 70, 20);
63 constexpr P c = bg::cross_product(p1, p2);
64 constexpr auto c0 = bg::get<0>(c);
65 constexpr auto c1 = bg::get<1>(c);
66 constexpr auto c2 = bg::get<2>(c);
67 BOOST_CHECK_EQUAL(c0, -100);
68 BOOST_CHECK_EQUAL(c1, 50);
69 BOOST_CHECK_EQUAL(c2, 50);
70 }
71
72 #ifdef TEST_FAIL_CROSS_PRODUCT
73 template <typename P>
74 void test_4d()
75 {
76 P p1;
77 bg::assign_values(p1, 20, 30, 10);
78 bg::set<3>(p1, 15);
79 P p2;
80 bg::assign_values(p2, 45, 70, 20);
81 bg::set<3>(p2, 35);
82 P c = bg::cross_product(p1, p2);
83 boost::ignore_unused(c);
84 }
85 #endif
86
87 int test_main(int, char* [])
88 {
89 test_2d<bg::model::point<int, 2, bg::cs::cartesian> >();
90 test_2d<bg::model::point<float, 2, bg::cs::cartesian> >();
91 test_2d<bg::model::point<double, 2, bg::cs::cartesian> >();
92
93 test_3d<bg::model::point<int, 3, bg::cs::cartesian> >();
94 test_3d<bg::model::point<float, 3, bg::cs::cartesian> >();
95 test_3d<bg::model::point<double, 3, bg::cs::cartesian> >();
96
97 #ifdef TEST_FAIL_CROSS_PRODUCT
98 test_4d<bg::model::point<int, 4, bg::cs::cartesian> >();
99 test_4d<bg::model::point<float, 4, bg::cs::cartesian> >();
100 test_4d<bg::model::point<double, 4, bg::cs::cartesian> >();
101 #endif
102
103 test_constexpr<bg::model::point<double, 3, bg::cs::cartesian> >();
104
105 return 0;
106 }
107