ALL 0.9.3
A Loadbalacing Library
Loading...
Searching...
No Matches
point_arithmetic.cpp
Go to the documentation of this file.
1/*
2Copyright 2018-2020 Rene Halver, Forschungszentrum Juelich GmbH, Germany
3Copyright 2018-2020 Godehard Sutmann, Forschungszentrum Juelich GmbH, Germany
4
5Redistribution and use in source and binary forms, with or without modification,
6are permitted provided that the following conditions are met:
7
81. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10
112. Redistributions in binary form must reproduce the above copyright notice, this
12 list of conditions and the following disclaimer in the documentation and/or
13 other materials provided with the distribution.
14
153. Neither the name of the copyright holder nor the names of its contributors may
16 be used to endorse or promote products derived from this software without
17 specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
25OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28POSSIBILITY OF SUCH DAMAGE.
29*/
30
31#define BOOST_TEST_MAIN
32
33#define BOOST_TEST_MODULE point_arithmetic
34#include "ALL_Point.hpp"
35#include <vector>
36#include <boost/test/unit_test.hpp>
37
38BOOST_AUTO_TEST_SUITE(point_arithmetic)
39
40BOOST_AUTO_TEST_CASE(point_add_double) {
41 std::vector<double> A_data = {2.8, -5.3, 8.8};
42 std::vector<double> B_data = {-5.2, 1.1, 0.4};
43
44 ALL::Point<double> A(A_data);
45 ALL::Point<double> B(B_data);
46
47 ALL::Point<double> C = A+B;
48
49 BOOST_CHECK_CLOSE(C[0],-2.4,1e-9);
50 BOOST_CHECK_CLOSE(C[1],-4.2,1e-9);
51 BOOST_CHECK_CLOSE(C[2],9.2,1e-9);
52}
53
54BOOST_AUTO_TEST_CASE(point_add_float) {
55 std::vector<float> A_data = {2.8f, -5.3f, 8.8f};
56 std::vector<float> B_data = {-5.2f, 1.1f, 0.4f};
57
58 ALL::Point<float> A(A_data);
59 ALL::Point<float> B(B_data);
60
61 ALL::Point<float> C = A+B;
62
63 BOOST_CHECK_CLOSE(C[0],-2.4f,1e-4);
64 BOOST_CHECK_CLOSE(C[1],-4.2f,1e-4);
65 BOOST_CHECK_CLOSE(C[2],9.2f,1e-4);
66}
67
68BOOST_AUTO_TEST_CASE(point_add_long_double) {
69 std::vector<long double> A_data = {2.8l, -5.3l, 8.8l};
70 std::vector<long double> B_data = {-5.2l, 1.1l, 0.4l};
71
74
76
77 BOOST_CHECK_CLOSE(C[0],-2.4l,1e-14);
78 BOOST_CHECK_CLOSE(C[1],-4.2l,1e-14);
79 BOOST_CHECK_CLOSE(C[2],9.2l,1e-14);
80}
81
82BOOST_AUTO_TEST_CASE(point_sub_double) {
83 std::vector<double> A_data = {2.8, -5.3, 8.8};
84 std::vector<double> B_data = {-5.2, 1.1, 0.4};
85
86 ALL::Point<double> A(A_data);
87 ALL::Point<double> B(B_data);
88
89 ALL::Point<double> C = A-B;
90
91 BOOST_CHECK_CLOSE(C[0],8.0,1e-9);
92 BOOST_CHECK_CLOSE(C[1],-6.4,1e-9);
93 BOOST_CHECK_CLOSE(C[2],8.4,1e-9);
94}
95
96BOOST_AUTO_TEST_CASE(point_cross_float) {
97 std::vector<float> A_data = {2.8f, -5.3f, 8.8f};
98 std::vector<float> B_data = {-5.2f, 1.1f, 0.4f};
99
100 ALL::Point<float> A(A_data);
101 ALL::Point<float> B(B_data);
102
103 ALL::Point<float> C = A-B;
104
105 BOOST_CHECK_CLOSE(C[0],8.0f,1e-4);
106 BOOST_CHECK_CLOSE(C[1],-6.4f,1e-4);
107 BOOST_CHECK_CLOSE(C[2],8.4f,1e-4);
108}
109
110BOOST_AUTO_TEST_CASE(point_cross_long_double) {
111 std::vector<long double> A_data = {2.8l, -5.3l, 8.8l};
112 std::vector<long double> B_data = {-5.2l, 1.1l, 0.4l};
113
114 ALL::Point<long double> A(A_data);
115 ALL::Point<long double> B(B_data);
116
118
119 BOOST_CHECK_CLOSE(C[0],8.0l,1e-14);
120 BOOST_CHECK_CLOSE(C[1],-6.4l,1e-14);
121 BOOST_CHECK_CLOSE(C[2],8.4l,1e-14);
122}
123
124BOOST_AUTO_TEST_CASE(point_scale_double) {
125 std::vector<double> A_data = {2.8, -5.3, 8.8};
126
127 ALL::Point<double> A(A_data);
128 double B = 0.5;
129
130 ALL::Point<double> C1 = A*B;
131 ALL::Point<double> C2 = B*A;
132
133 BOOST_CHECK_CLOSE(C1[0],1.4,1e-9);
134 BOOST_CHECK_CLOSE(C1[1],-2.65,1e-9);
135 BOOST_CHECK_CLOSE(C1[2],4.4,1e-9);
136 BOOST_CHECK_CLOSE(C2[0],1.4,1e-9);
137 BOOST_CHECK_CLOSE(C2[1],-2.65,1e-9);
138 BOOST_CHECK_CLOSE(C2[2],4.4,1e-9);
139}
140
141BOOST_AUTO_TEST_CASE(point_scale_float) {
142 std::vector<float> A_data = {2.8f, -5.3f, 8.8f};
143
144 ALL::Point<float> A(A_data);
145 float B = 0.5f;
146
147 ALL::Point<float> C1 = A*B;
148 ALL::Point<float> C2 = B*A;
149
150 BOOST_CHECK_CLOSE(C1[0],1.4f,1e-4);
151 BOOST_CHECK_CLOSE(C1[1],-2.65f,1e-4);
152 BOOST_CHECK_CLOSE(C1[2],4.4f,1e-4);
153 BOOST_CHECK_CLOSE(C2[0],1.4f,1e-4);
154 BOOST_CHECK_CLOSE(C2[1],-2.65f,1e-4);
155 BOOST_CHECK_CLOSE(C2[2],4.4f,1e-4);
156}
157
158BOOST_AUTO_TEST_CASE(point_scale_long_double) {
159 std::vector<long double> A_data = {2.8, -5.3, 8.8};
160
161 ALL::Point<long double> A(A_data);
162 long double B = 0.5l;
163
166
167 BOOST_CHECK_CLOSE(C1[0],1.4l,1e-14);
168 BOOST_CHECK_CLOSE(C1[1],-2.65l,1e-14);
169 BOOST_CHECK_CLOSE(C1[2],4.4l,1e-14);
170 BOOST_CHECK_CLOSE(C2[0],1.4l,1e-14);
171 BOOST_CHECK_CLOSE(C2[1],-2.65l,1e-14);
172 BOOST_CHECK_CLOSE(C2[2],4.4l,1e-14);
173}
174
175BOOST_AUTO_TEST_CASE(point_dist_plane) {
176 std::vector<double> A_data = {1.,0.,0.};
177 std::vector<double> B_data = {0.,1.,0.};
178 std::vector<double> C_data = {0.,0.,1.};
179 std::vector<double> p_data = {0.5,0.5,0.5};
180 ALL::Point<double> A(A_data);
181 ALL::Point<double> B(B_data);
182 ALL::Point<double> C(C_data);
183 ALL::Point<double> p(p_data);
184
185 double dist = p.dist_plane(A,B,C);
186
187 BOOST_CHECK_CLOSE(dist, 0.28867513459481292, 1e-14);
188}
189
190BOOST_AUTO_TEST_SUITE_END()
191
BOOST_AUTO_TEST_CASE(empty)
T dist_plane(const Point< T > &A, const Point< T > &B, const Point< T > &C)
BOOST_AUTO_TEST_CASE(point_add_double)