TEST(Vector, shouldNormalize) { Vector v(2, 2, 2); VECTOR_EQUAL( 0.577350,0.577350,0.577350, v.normalize() ); VECTOR_EQUAL( 0.577350,0.577350,0.577350, v ); }
TEST(Vector, shouldProvideSubtractionOperator) { Vector v1(1,2,3); Vector v2(1,1,1); VECTOR_EQUAL( 0, 1, 2, (v1 - v2) ); Vector v3 = v2 -= v1; VECTOR_EQUAL( 0, -1, -2, v2 ); VECTOR_EQUAL( 0, -1, -2, v3 ); }
TEST(Vector, shouldProvideMultiplyByScalar) { Vector v(1, 2, 3); VECTOR_EQUAL( 3, 6, 9, (v * 3) ); Vector actual = (v *= 2); VECTOR_EQUAL( 2, 4, 6, actual ); VECTOR_EQUAL( 2, 4, 6, v ); }
TEST(Vector, shouldProvideAddOperators) { Vector v1(1,-3,0); Vector v2(4, 4, 2); VECTOR_EQUAL( 5, 1, 2, (v1+v2)); Vector v3 = v1 += v2; VECTOR_EQUAL( 5, 1, 2, v1); VECTOR_EQUAL( 5, 1, 2, v3); }
TEST(RTPolySet, boundingBoxShouldBeUnionOfTriangles) { RTPolySet ps; RTTriangle t1(Vector(0,0,0), Vector(1,0,0), Vector(1,0,1)); ps.addTriangle(t1); RTTriangle t2(Vector(5,5,5), Vector(6,6,5), Vector(6,6,6)); ps.addTriangle(t2); BoundingBox box = ps.getBoundingBox(); VECTOR_EQUAL(0,0,0, box.getOrigin()); VECTOR_EQUAL(6,6,6, box.getDelta()); }
inline TYPE VECTOR_CMOV( TYPE a, TYPE b, TYPE c, TYPE d){ TYPE z = VECTOR_EQUAL ( a, b ); // return _mm_blendv_epi8( d, c, z ); TYPE g = VECTOR_AND ( c, z ); TYPE h = VECTOR_ANDNOT( z, d ); return VECTOR_OR ( g, h ); }
TEST(Vector, shouldProvideUnaryMinus) { Vector v(1,-3,0); VECTOR_EQUAL( -1, 3, 0, (-v)); }
TEST(Vector, shouldProvideTreeValueConstructor) { Vector v(5, 6, 1); VECTOR_EQUAL( 5, 6, 1, v ); }
TEST(Vector, shouldProvideCrossProduct) { Vector v1(5, 4, 2); Vector v2(1, 3, 4); VECTOR_EQUAL(10, -18, 11, v1.cross(v2) ); }
TEST(Vector, shouldHaveTreeComponentArrayConstructor) { float values[] { 1,2,3 }; Vector v(values); VECTOR_EQUAL( 1, 2, 3, v); }
TEST(Vector, shouldRotateAndHomogenize) { Vector v( 0, 1, 0 ); v.rotate( X, M_PI ); VECTOR_EQUAL( 0, -1, 0, v ); }
TEST(Matrix, normalizeShouldHandleNullLength) { Matrix m1(0,0,0); m1.normalize(); VECTOR_EQUAL(0,0,0, m1); }
TEST(Matrix, shouldProvideHadamardProduct) { Matrix m1(1, 2, 3); Matrix r = m1.hadamardProduct(m1); VECTOR_EQUAL(1, 4, 9, r); }
TEST(Matrix, shouldProvideUnaryMinus) { Matrix m(1,0,-3); Matrix actual = -m; VECTOR_EQUAL(-1, 0, 3, actual); }
TEST(Matrix, shouldBeMultipliableWithVector) { Matrix m(4,4); float vals[] = { 1,1,1,1, 2,2,2,2, 3,3,3,3, 4,4,4,4 }; m.setAll(vals); Vector v( 1, 2, 3 ); Vector r = m * v; float l = 4+8+12; VECTOR_EQUAL( (1+2+3)/l, (2+4+6)/l, (3+6+9)/l, r ); }
TEST(Vector, shouldSupportUnaryMinus) { Vector v(1, 2, 3); VECTOR_EQUAL( - 1, -2, -3, -v); }