Skip to content
Snippets Groups Projects
Commit a031a008 authored by Anna Wellmann's avatar Anna Wellmann
Browse files

Test function for rotation

parent b720b425
No related branches found
No related tags found
1 merge request!307[GPU] Add a cylinder geometry
......@@ -2,6 +2,7 @@
#define TESTUTILITIES_H
#include <gmock/gmock.h>
#include <basics/DataTypes.h>
inline auto RealEq = [](auto value) {
#ifdef VF_DOUBLE_ACCURACY
......@@ -19,9 +20,35 @@ inline auto RealNear = [](auto value, auto max_abs_error) {
#endif
};
namespace
{
__inline__ bool isEqualWithAccuracy(real number, real expected, real accuracy)
{
return number > (expected - accuracy) && number < (expected + accuracy);
}
} // namespace
namespace testingVF
{
MATCHER_P2(RealNearForContainer, expectedContainer, accuracy, "")
{
if (arg.size() != expectedContainer.size()) {
std::cout << "The checked container does not have the same size as the expected container.\n" << std::endl;
return false;
}
for (int i = 0; i < arg.size(); i++) {
if (!isEqualWithAccuracy(arg[i], expectedContainer[i], accuracy)) {
std::cout << "First mismatching element at index " << i << ": The actual element " << std::to_string(arg[i])
<< " is not near the expected element " << std::to_string(expectedContainer[i])
<< " (difference = " << std::to_string(expectedContainer[i] - arg[i]) << ").\n";
return false;
}
}
return true;
}
__inline__ void captureStdOut()
{
testing::internal::CaptureStdout();
......
#include "testUtilities.h"
TEST(isEqualWithAccuracy, test)
{
const real accuracy = 1.0;
const real expected = 0.0;
EXPECT_TRUE(isEqualWithAccuracy( 0.0, expected, accuracy));
EXPECT_TRUE(isEqualWithAccuracy( 0.999999, expected, accuracy));
EXPECT_TRUE(isEqualWithAccuracy( -0.999999, expected, accuracy));
EXPECT_FALSE(isEqualWithAccuracy( 1.000001, expected, accuracy));
EXPECT_FALSE(isEqualWithAccuracy( -1.000001, expected, accuracy));
}
......@@ -30,7 +30,7 @@ __inline__ __host__ __device__ void rotateDataFromRotatingToGlobal(real &datumX,
datumZ = datumZTemp;
}
__inline__ __device__ void transformRotatingToGlobal(real &globalX, real &globalY, real &globalZ, real localX, real localY,
__inline__ __host__ __device__ void transformRotatingToGlobal(real &globalX, real &globalY, real &globalZ, real localX, real localY,
real localZ, real centerCoordX, real centerCoordY, real centerCoordZ,
real angleX, real angleY, real angleZ)
{
......@@ -38,20 +38,7 @@ __inline__ __device__ void transformRotatingToGlobal(real &globalX, real &global
globalY = localY;
globalZ = localZ;
// rotate
if (angleX != 0) {
// rotate in x
globalY = localY * cos(angleX) - localZ * sin(angleX);
globalZ = localY * sin(angleX) + localZ * cos(angleX);
} else if (angleY != 0) {
// rotate in y
globalX = localX * cos(angleY) + localZ * sin(angleY);
globalZ = -localX * sin(angleY) + localZ * cos(angleY);
} else if (angleZ != 0) {
// rotate in z
globalX = localX * cos(angleZ) - localY * sin(angleZ);
globalY = localX * sin(angleZ) + localY * cos(angleZ);
}
rotateDataFromRotatingToGlobal(globalX, globalY, globalZ, angleX, angleY, angleZ);
// translate
globalX += centerCoordX;
......@@ -60,7 +47,7 @@ __inline__ __device__ void transformRotatingToGlobal(real &globalX, real &global
}
__inline__ __device__ void rotateDataFromGlobalToRotating(real &datumX, real &datumY, real &datumZ, real angleX,
__inline__ __host__ __device__ void rotateDataFromGlobalToRotating(real &datumX, real &datumY, real &datumZ, real angleX,
real angleY, real angleZ)
{
real datumXTemp = datumX;
......@@ -83,7 +70,7 @@ __inline__ __device__ void rotateDataFromGlobalToRotating(real &datumX, real &da
datumZ = datumZTemp;
}
__inline__ __device__ void transformGlobalToRotating(real &rotatingX, real &rotatingY, real &rotatingZ, real globalX,
__inline__ __host__ __device__ void transformGlobalToRotating(real &rotatingX, real &rotatingY, real &rotatingZ, real globalX,
real globalY, real globalZ, real centerCoordX, real centerCoordY,
real centerCoordZ, real angleX, real angleY, real angleZ)
{
......@@ -97,20 +84,7 @@ __inline__ __device__ void transformGlobalToRotating(real &rotatingX, real &rota
rotatingY = globalY;
rotatingZ = globalZ;
// rotate
if (angleX != 0) {
// rotate in x
rotatingY = globalY * cos(angleX) + globalZ * sin(angleX);
rotatingZ = -globalY * sin(angleX) + globalZ * cos(angleX);
} else if (angleY != 0) {
// rotate in y
rotatingX = globalX * cos(angleY) - globalZ * sin(angleY);
rotatingZ = globalX * sin(angleY) + globalZ * cos(angleY);
} else if (angleZ != 0) {
// rotate in z
rotatingX = globalX * cos(angleZ) + globalY * sin(angleZ);
rotatingY = -globalX * sin(angleZ) + globalY * cos(angleZ);
}
rotateDataFromGlobalToRotating(rotatingX, rotatingY, rotatingZ, angleX, angleY, angleZ);
}
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment