Skip to content
This repository
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 49 lines (34 sloc) 1.143 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#include <UnitTest++.h>

#include "../kazmath/vec2.h"
#include "../kazmath/utility.h"
#include "../kazmath/mat3.h"

TEST(test_transform) {
    kmVec2 orig;
    kmVec2Fill(&orig, 0.0, 1.0f);
    
    kmMat3 rotate;
    kmMat3RotationZ(&rotate, kmDegreesToRadians(90.0f));
    
    kmVec2 rotated;
    kmVec2Transform(&rotated, &orig, &rotate);
    
    CHECK_CLOSE(1.0f, rotated.x, 0.001f);
    CHECK_CLOSE(0.0f, rotated.y, 0.001f);
}

TEST(test_degrees_between) {
    kmVec2 v1;
    kmVec2 v2;
    
    kmVec2Fill(&v1, 1, 0);
    kmVec2Fill(&v2, 0, 1);
    
    CHECK_CLOSE(90.0f, kmVec2DegreesBetween(&v1, &v2), 0.001f);
    CHECK_CLOSE(-90.0f, kmVec2DegreesBetween(&v2, &v1), 0.001f);
}

TEST(test_vec2_rotate_by) {
    kmVec2 res;
    kmVec2RotateBy(&res, &KM_VEC2_POS_Y, 90, &KM_VEC2_ZERO);

    CHECK_CLOSE(-1, res.x, 0.001f);
    CHECK_CLOSE(0, res.y, 0.001f);

    kmVec2RotateBy(&res, &KM_VEC2_POS_Y, -90, &KM_VEC2_ZERO);

    CHECK_CLOSE(1, res.x, 0.001f);
    CHECK_CLOSE(0, res.y, 0.001f);

    kmVec2RotateBy(&res, &KM_VEC2_POS_Y, 180, &KM_VEC2_ZERO);

    CHECK_CLOSE(0, res.x, 0.001f);
    CHECK_CLOSE(-1, res.y, 0.001f);

}
Something went wrong with that request. Please try again.