| 1 |
// |
| 2 |
// SPDX-License-Identifier: BSD-3-Clause |
| 3 |
// Copyright Contributors to the OpenEXR Project. |
| 4 |
// |
| 5 |
|
| 6 |
#ifdef NDEBUG |
| 7 |
# undef NDEBUG |
| 8 |
#endif |
| 9 |
|
| 10 |
#include <ImathMath.h> |
| 11 |
#include <ImathShear.h> |
| 12 |
#include <assert.h> |
| 13 |
#include <iostream> |
| 14 |
#include "testShear.h" |
| 15 |
|
| 16 |
// Include ImathForward *after* other headers to validate forward declarations |
| 17 |
#include <ImathForward.h> |
| 18 |
|
| 19 |
using namespace std; |
| 20 |
|
| 21 |
void |
| 22 |
testShear() |
| 23 |
{ |
| 24 |
cout << "Testing functions in ImathShear.h" << endl; |
| 25 |
|
| 26 |
cout << "Imath::Shear6 constructors" << endl; |
| 27 |
|
| 28 |
const float epsilon = std::numeric_limits<float>::epsilon(); |
| 29 |
|
| 30 |
IMATH_INTERNAL_NAMESPACE::Shear6f testConstructor1; |
| 31 |
IMATH_INTERNAL_NAMESPACE::Shear6f testConstructor2 (testConstructor1); |
| 32 |
|
| 33 |
testConstructor1 = testConstructor2; |
| 34 |
|
| 35 |
IMATH_INTERNAL_NAMESPACE::Shear6f testConstructor3 (52, 128, 254, 127, 12, -20); |
| 36 |
IMATH_INTERNAL_NAMESPACE::Shear6f A (testConstructor3); |
| 37 |
IMATH_INTERNAL_NAMESPACE::Shear6f B = A; |
| 38 |
IMATH_INTERNAL_NAMESPACE::Shear6f X, Y, tmp; |
| 39 |
|
| 40 |
assert (A == B); |
| 41 |
|
| 42 |
cout << "Imath::Shear6 * f" << endl; |
| 43 |
|
| 44 |
assert ((IMATH_INTERNAL_NAMESPACE::Shear6f (0.330f, 0.710f, 0.010f, 0.999f, -0.531f, -0.012f) * |
| 45 |
0.999f) == IMATH_INTERNAL_NAMESPACE::Shear6f (0.330f * 0.999f, |
| 46 |
0.710f * 0.999f, |
| 47 |
0.010f * 0.999f, |
| 48 |
0.999f * 0.999f, |
| 49 |
-0.531f * 0.999f, |
| 50 |
-0.012f * 0.999f)); |
| 51 |
|
| 52 |
cout << "Imath::Shear6 / f" << endl; |
| 53 |
|
| 54 |
assert ((IMATH_INTERNAL_NAMESPACE::Shear6f (0.330f, 0.710f, 0.010f, 0.999f, -0.531f, -0.012f) / |
| 55 |
0.999f) == IMATH_INTERNAL_NAMESPACE::Shear6f (0.330f / 0.999f, |
| 56 |
0.710f / 0.999f, |
| 57 |
0.010f / 0.999f, |
| 58 |
0.999f / 0.999f, |
| 59 |
-0.531f / 0.999f, |
| 60 |
-0.012f / 0.999f)); |
| 61 |
|
| 62 |
cout << "Assignment and comparison" << endl; |
| 63 |
|
| 64 |
B = A; |
| 65 |
assert (B == A); |
| 66 |
assert (!(B != A)); |
| 67 |
|
| 68 |
X = Y = IMATH_INTERNAL_NAMESPACE::Shear6f (0.123f, -0.420f, 0.501f, 0.998f, -0.231f, -0.034f); |
| 69 |
|
| 70 |
X *= 0.001f; |
| 71 |
|
| 72 |
assert (std::fabs ((Y.xy * 0.001f) - X.xy) <= epsilon && |
| 73 |
std::fabs ((Y.xz * 0.001f) - X.xz) <= epsilon && |
| 74 |
std::fabs ((Y.yz * 0.001f) - X.yz) <= epsilon && |
| 75 |
std::fabs ((Y.yx * 0.001f) - X.yx) <= epsilon && |
| 76 |
std::fabs ((Y.zx * 0.001f) - X.zx) <= epsilon && |
| 77 |
std::fabs ((Y.zy * 0.001f) - X.zy) <= epsilon); |
| 78 |
|
| 79 |
X = Y = IMATH_INTERNAL_NAMESPACE::Shear6f (0.123f, -0.420f, 0.501f, 0.998f, -0.231f, -0.034f); |
| 80 |
|
| 81 |
X /= -1.001f; |
| 82 |
|
| 83 |
assert (std::fabs ((Y.xy / -1.001f) - X.xy) <= epsilon && |
| 84 |
std::fabs ((Y.xz / -1.001f) - X.xz) <= epsilon && |
| 85 |
std::fabs ((Y.yz / -1.001f) - X.yz) <= epsilon && |
| 86 |
std::fabs ((Y.yx / -1.001f) - X.yx) <= epsilon && |
| 87 |
std::fabs ((Y.zx / -1.001f) - X.zx) <= epsilon && |
| 88 |
std::fabs ((Y.zy / -1.001f) - X.zy) <= epsilon); |
| 89 |
|
| 90 |
Y = IMATH_INTERNAL_NAMESPACE::Shear6f (0.998f, -0.001f, 0.501f, 1.001f, -0.231f, -0.034f); |
| 91 |
X = IMATH_INTERNAL_NAMESPACE::Shear6f (0.011f, -0.420f, -0.501f, 0.998f, -0.231f, -0.034f); |
| 92 |
|
| 93 |
tmp = X + Y; |
| 94 |
|
| 95 |
assert (std::fabs ((X.xy + Y.xy) - tmp.xy) <= epsilon && |
| 96 |
std::fabs ((X.xz + Y.xz) - tmp.xz) <= epsilon && |
| 97 |
std::fabs ((X.yz + Y.yz) - tmp.yz) <= epsilon && |
| 98 |
std::fabs ((X.yx + Y.yx) - tmp.yx) <= epsilon && |
| 99 |
std::fabs ((X.zx + Y.zx) - tmp.zx) <= epsilon && |
| 100 |
std::fabs ((X.zy + Y.zy) - tmp.zy) <= epsilon); |
| 101 |
|
| 102 |
tmp = X - Y; |
| 103 |
|
| 104 |
assert (std::fabs ((X.xy - Y.xy) - tmp.xy) <= epsilon && |
| 105 |
std::fabs ((X.xz - Y.xz) - tmp.xz) <= epsilon && |
| 106 |
std::fabs ((X.yz - Y.yz) - tmp.yz) <= epsilon && |
| 107 |
std::fabs ((X.yx - Y.yx) - tmp.yx) <= epsilon && |
| 108 |
std::fabs ((X.zx - Y.zx) - tmp.zx) <= epsilon && |
| 109 |
std::fabs ((X.zy - Y.zy) - tmp.zy) <= epsilon); |
| 110 |
|
| 111 |
tmp = X * Y; |
| 112 |
|
| 113 |
assert (std::fabs ((X.xy * Y.xy) - tmp.xy) <= epsilon && |
| 114 |
std::fabs ((X.xz * Y.xz) - tmp.xz) <= epsilon && |
| 115 |
std::fabs ((X.yz * Y.yz) - tmp.yz) <= epsilon && |
| 116 |
std::fabs ((X.yx * Y.yx) - tmp.yx) <= epsilon && |
| 117 |
std::fabs ((X.zx * Y.zx) - tmp.zx) <= epsilon && |
| 118 |
std::fabs ((X.zy * Y.zy) - tmp.zy) <= epsilon); |
| 119 |
|
| 120 |
tmp = X / Y; |
| 121 |
|
| 122 |
// |
| 123 |
// epsilon doesn't work here. |
| 124 |
// |
| 125 |
assert (std::fabs ((X.xy / Y.xy) - tmp.xy) <= 1e-5f && |
| 126 |
std::fabs ((X.xz / Y.xz) - tmp.xz) <= 1e-5f && |
| 127 |
std::fabs ((X.yz / Y.yz) - tmp.yz) <= 1e-5f && |
| 128 |
std::fabs ((X.yx / Y.yx) - tmp.yx) <= 1e-5f && |
| 129 |
std::fabs ((X.zx / Y.zx) - tmp.zx) <= 1e-5f && |
| 130 |
std::fabs ((X.zy / Y.zy) - tmp.zy) <= 1e-5f); |
| 131 |
|
| 132 |
tmp = X; |
| 133 |
tmp += Y; |
| 134 |
|
| 135 |
assert (std::fabs ((X.xy + Y.xy) - tmp.xy) <= epsilon && |
| 136 |
std::fabs ((X.xz + Y.xz) - tmp.xz) <= epsilon && |
| 137 |
std::fabs ((X.yz + Y.yz) - tmp.yz) <= epsilon && |
| 138 |
std::fabs ((X.yx + Y.yx) - tmp.yx) <= epsilon && |
| 139 |
std::fabs ((X.zx + Y.zx) - tmp.zx) <= epsilon && |
| 140 |
std::fabs ((X.zy + Y.zy) - tmp.zy) <= epsilon); |
| 141 |
|
| 142 |
tmp = X; |
| 143 |
tmp -= Y; |
| 144 |
|
| 145 |
assert (std::fabs ((X.xy - Y.xy) - tmp.xy) <= epsilon && |
| 146 |
std::fabs ((X.xz - Y.xz) - tmp.xz) <= epsilon && |
| 147 |
std::fabs ((X.yz - Y.yz) - tmp.yz) <= epsilon && |
| 148 |
std::fabs ((X.yx - Y.yx) - tmp.yx) <= epsilon && |
| 149 |
std::fabs ((X.xz - Y.xz) - tmp.xz) <= epsilon && |
| 150 |
std::fabs ((X.yz - Y.yz) - tmp.yz) <= epsilon); |
| 151 |
|
| 152 |
tmp = X; |
| 153 |
tmp *= Y; |
| 154 |
|
| 155 |
assert (std::fabs ((X.xy * Y.xy) - tmp.xy) <= epsilon && |
| 156 |
std::fabs ((X.xz * Y.xz) - tmp.xz) <= epsilon && |
| 157 |
std::fabs ((X.yz * Y.yz) - tmp.yz) <= epsilon && |
| 158 |
std::fabs ((X.yx * Y.yx) - tmp.yx) <= epsilon && |
| 159 |
std::fabs ((X.zx * Y.zx) - tmp.zx) <= epsilon && |
| 160 |
std::fabs ((X.zy * Y.zy) - tmp.zy) <= epsilon); |
| 161 |
|
| 162 |
tmp = X; |
| 163 |
tmp /= Y; |
| 164 |
|
| 165 |
// |
| 166 |
// epsilon doesn't work here. |
| 167 |
// |
| 168 |
assert (std::fabs ((X.xy / Y.xy) - tmp.xy) <= 1e-5f && |
| 169 |
std::fabs ((X.xz / Y.xz) - tmp.xz) <= 1e-5f && |
| 170 |
std::fabs ((X.yz / Y.yz) - tmp.yz) <= 1e-5f && |
| 171 |
std::fabs ((X.yx / Y.yx) - tmp.yx) <= 1e-5f && |
| 172 |
std::fabs ((X.zx / Y.zx) - tmp.zx) <= 1e-5f && |
| 173 |
std::fabs ((X.zy / Y.zy) - tmp.zy) <= 1e-5f); |
| 174 |
|
| 175 |
cout << "ok\n" << endl; |
| 176 |
} |