34 Complexf end_rotation{ Complexf::make_rotation(amount_of_rotation) };
35 float step_percentage = 1.0f / num_equal_steps;
37 for (
int iCurrentStep = 0; iCurrentStep < num_equal_steps; ++iCurrentStep)
39 float current_percentage{ step_percentage * iCurrentStep };
40 Degreef current_rotation_amount{ amount_of_rotation * current_percentage };
41 Complexf new_rotation{ Complexf::make_rotation(current_rotation_amount) };
42 Complexf slerp_result = slerp(begin, end_rotation, current_percentage);
49 slerp_result = Complexf(slerp_result.real(), std::abs(slerp_result.imaginary()));
50 new_rotation = Complexf(new_rotation.real(), std::abs(new_rotation.imaginary()));
55 Complexf slerp_result = slerp(begin, end_rotation, 1.0f);
63 Complexf unit = Complexf::identity();
71 Complexf zero = Complexf::zero();
79 Complexf c{ 1.0, 2.0 };
87 Complexf c_left{ 1.0, 2.0 };
88 Complexf c_right{ 5.0, 6.0 };
89 Complexf c_result = c_left + c_right;
97 Complexf c_original{ 1.0, 2.0 };
98 Complexf c_tocompareagainst{ 1.0, 2.0 };
107 Complexf c_original{ 1.0, 2.0 };
108 Complexf c_tocompareagainst{ 1.0, 2.0 };
109 Complexf c_different4{ -1.0, -2.0 };
110 Complexf c_different3{ 99.0, 2.0 };
111 Complexf c_different2{ 1.0, 12.0 };
112 Complexf c_different1{ 100.0, 2.0 };
116 assert( (c_original != c_tocompareagainst) ==
false );
127 Complexf q_original{ 2.0, 4.0 };
128 Complexf q_copy{ q_original };
135 Complexf arbitrary_value1{ 1.0, 2.0 };
136 Complexf arbitrary_value2{ 1.0, -2.0 };
137 Complexf arbitrary_value3{ 1.0, 2.0 };
139 Complexf expected_value1{ 1.0, -2.0 };
140 Complexf expected_value2{ 1.0, 2.0 };
141 Complexf expected_value3{ 1.0, -2.0 };
150 Complexf arbitrary_value1{ 6.0, 7.0 };
152 CHECK_IF_EQUAL(arbitrary_value1.conjugate().conjugate(), arbitrary_value1);
162 Complexf negative_1{ -1.0, 0.0 };
163 Complexf i = Complexf::unit_i();
178 Complexf::value_type starting_value = 0;
179 Complexf::value_type value = 6;
180 Complexf::value_type added_value = starting_value + value;
181 Complexf::value_type subtracted_value = starting_value - value;
189 CHECK_IF_EQUAL( Complexf{ 1.0, 1.0 }.norm(), std::sqrt(1.0f + 1.0f) );
191 CHECK_IF_EQUAL( Complexf{ 2.0, 2.0 }.norm(), std::sqrt(4.0f + 4.0f) );
192 CHECK_IF_EQUAL( Complexf{ 1.0, 2.0 }.norm(), std::sqrt(1.0f + 4.0f) );
204 Complexf a(1.0f, 2.0f);
205 Complexf a_div = a / 2.0f;
206 Complexf b(1.0f / 2.0f, 2.0f / 2.0f);
211 Complexf a(1.0f, 2.0f);
212 Complexf a_div = a / 3.0f;
213 Complexf b(1.0f / 3.0f, 2.0f / 3.0f);
222 Complexf a(1.0f, 2.0f);
223 Complexf a_mul = a * 2.0f;
224 Complexf b(1.0f * 2.0f, 2.0f * 2.0f);
229 Complexf a(1.0f, 2.0f);
230 Complexf a_mul = a * 3.0f;
231 Complexf b(1.0f * 3.0f, 2.0f * 3.0f);
239 Complexf c1{ 6.3f, 2.2f };
240 Complexf c1_inverse = c1.inverse();
241 Complexf c1_product = c1_inverse * c1;
242 Complexf c1_product_reversed = c1 * c1_inverse;
251 CHECK_IF_EQUAL(Complexf::unit_real().inverse(), Complexf::unit_real().conjugate());
252 CHECK_IF_EQUAL(Complexf::unit_i().inverse(), Complexf::unit_i().conjugate());
257 assert( Complexf::identity().isUnit() );
273 Complexf c1{ 1.0f, 2.0f };
274 Complexf c2{ 9.0f, 10.0f };
281 Complexf c{ 3.5f, -45.668f };
282 Complexf product = c * c.conjugate();
290 Complexf c{ 3.5f, 113.443f };
291 Complexf product = c * c.conjugate();
292 float m_squared = c.magnitudeSquared();
301 Complexf rotation = Complexf::make_rotation( Degreef(90.0f) );
302 Complexf encoded_point = Complexf::encode_point(0.0f, 1.0f);
303 Complexf transformed_point = rotation * encoded_point;
310 Complexf rotation = Complexf::make_rotation( Degreef(90.0f) );
311 Complexf encoded_point = Complexf::encode_point(1.0f, 0.0f);
312 Complexf transformed_point = rotation * encoded_point;
322 Complexf rotation_90 = Complexf::make_rotation( Degreef(90.0f) );
323 Complexf encoded_point = Complexf::encode_point(3.0f, 0.0f);
324 Complexf transformed_point = passively_rotate_encoded_point(rotation_90, encoded_point);
326 transformed_point = passively_rotate_encoded_point(rotation_90, transformed_point);
334 Complexf rotation_45 = Complexf::make_rotation( Degreef(45.0f) );
335 Complexf composed_rotation = compose_rotations( rotation_45, rotation_45 );
336 Complexf encoded_point = Complexf::encode_point(0.0f, 8.0f);
337 Complexf transformed_point = passively_rotate_encoded_point(composed_rotation, encoded_point);
346 auto angle = 90.0_deg_f;
347 Complexf rotation = Complexf::make_rotation( angle );
348 Complexf exp0 = rotation.pow(0.0f);
349 Complexf exp_0_5 = rotation.pow(0.5f);
350 Complexf exp1 = rotation.pow(1.0f);
351 Complexf exp_2_0 = rotation.pow(2.0f);
352 Complexf exp_3_0 = rotation.pow(3.0f);
353 Complexf two_rotations_multiplied{ rotation * rotation };
354 Complexf three_rotations_multiplied{ rotation * rotation * rotation };
357 CHECK_IF_EQUAL( exp_0_5, Complexf::make_rotation( angle * 0.5f ) );
359 CHECK_IF_EQUAL( exp_2_0, Complexf::make_rotation( angle * 2.0f ) );
381 auto a{ Complexf::identity() };
382 auto b{ Complexf::make_rotation(36.3_deg_f) };
383 auto c{ Complexf::make_rotation(90.0_deg_f) };
397 Complexf begin = Complexf::identity();
398 Complexf end = Complexf::make_rotation( 90.0_deg_f );
402 Complexf slerp_begin = slerp(begin, end, 0.0f);
403 Complexf slerp_end = slerp(begin, end, 1.0f);
416void IsNaNIsTrueWhenAtLeastOneMemberIsNaN()
418 assert( Quaternionf(NAN).isNaN() );
419 assert( Quaternionf(NAN, 0.0f, 0.0f, 0.0f).isNaN() );
420 assert( Quaternionf(3.2f, NAN, 0.0f, 0.0f).isNaN() );
421 assert( Quaternionf(3.2f, 0.0f, NAN, 0.0f).isNaN() );
422 assert( Quaternionf(3.2f, 0.0f, 0.0f, NAN).isNaN() );
423 assert( !Quaternionf(3.2f, 4.6f, 0.0f, 1.1f).isNaN() );
428 assert( Quaternionf(INFINITY).isInf() );
429 assert( Quaternionf(INFINITY, 0.0f, 0.0f, 0.0f).isInf() );
430 assert( Quaternionf(3.2f, INFINITY, 0.0f, 0.0f).isInf() );
431 assert( Quaternionf(3.2f, 0.0f, INFINITY, 0.0f).isInf() );
432 assert( Quaternionf(3.2f, 0.0f, 0.0f, INFINITY).isInf() );
433 assert( !Quaternionf(3.2f, 4.6f, 0.0f, 1.1f).isInf() );
438 Quaternionf result{ Quaternionf::identity() / 0.0f };
440 assert( result.isInf() );
482 IsNaNIsTrueWhenAtLeastOneMemberIsNaN();
483 IsInfIsTrueWhenAtLeastOneMemberIsInf();
484 DivideByZeroProducesInf();
void CHECK_IF_NOT_EQUAL(float input, float near_to, float tolerance=0.0002f)
void CHECK_IF_EQUAL(float input, float near_to, float tolerance=0.0002f)
bool approximately_equal_to(float input, float near_to, float tolerance=0.0002f)
void IUnitCoomplexIsDefined()
void DividingByAScalarDividesEachComponent()
void ISquaredIsNegativeOne()
void NormIsEquivalentToDistance()
void UnitComplexIsAsExpected()
void ExpAndLogAreInversesOfEachOther()
void ComplexAddsPerComponent()
void ZeroComplexIsAsExpected()
void DotProductMultiplesCorrespondingElementsAndThenSumsTheResultingValues()
void MakePureComplexSetsImaginaryToInputParameter()
void ConjugateInvertsTheImaginaryComponent()
void MagnitudeSquaredIsValueOfRealPartOfProductOfAComplexAndItsConjugate()
void InverseOfAUnitComplexIsItsConjugate()
void OperatorPlusAndMinusAreInverses()
void PerformTwoConsecutiveRotations()
void OperatorEqualsComparesMatchingComponents()
void MakePureComplexSetsRealComponentToZero()
void UnitComplexHasNormOfOne()
void TestRotationAtRegularIntervals(Complexf begin, Degreef amount_of_rotation, int num_equal_steps)
void UnitComplexIsNear1()
void MultiplyingByItsOwnInverseProducesUnity()
void MultiplyingByAScalarMultipliesEachComponent()
void OperatorNotEqualsIsOppositeOfEquals()
void ConjugateIsItsOwnInverse()
void MultiplyingAComplexByItsConjugateProducesAPureRealNumber()
void CopyOperatorIsImplemented()
void MakingARotationIsAccurate()
void ComplexIsConstructedAsExpected()
void IsInfIsTrueWhenAtLeastOneMemberIsInf()
void DivideByZeroProducesInf()