awtk/tests/matrix_test.cc

73 lines
1.3 KiB
C++
Raw Normal View History

#include "tkc/matrix.h"
2018-03-23 19:15:24 +08:00
#include "gtest/gtest.h"
TEST(Matrix, basic) {
xy_t x = 0;
xy_t y = 0;
matrix_t m;
matrix_init(&m);
2018-04-25 17:38:51 +08:00
matrix_transform_point(&m, 10, 20, &x, &y);
2018-03-23 19:15:24 +08:00
ASSERT_EQ(x, 10);
ASSERT_EQ(y, 20);
}
TEST(Matrix, translate) {
xy_t x = 0;
xy_t y = 0;
matrix_t m;
matrix_init(&m);
matrix_translate(&m, 10, 20);
2018-04-25 17:38:51 +08:00
matrix_transform_point(&m, 10, 20, &x, &y);
2018-03-23 19:15:24 +08:00
ASSERT_EQ(x, 20);
ASSERT_EQ(y, 40);
}
TEST(Matrix, rotate) {
xy_t x = 0;
xy_t y = 0;
matrix_t m;
matrix_init(&m);
matrix_rotate(&m, 3.14159);
2018-04-25 17:38:51 +08:00
matrix_transform_point(&m, 10, 20, &x, &y);
2018-03-23 19:15:24 +08:00
ASSERT_EQ(x, -10);
ASSERT_EQ(y, -20);
2018-03-24 21:37:40 +08:00
2018-03-23 19:15:24 +08:00
matrix_rotate(&m, 3.14159);
2018-04-25 17:38:51 +08:00
matrix_transform_point(&m, 10, 20, &x, &y);
2018-03-23 19:15:24 +08:00
ASSERT_EQ(x, 10);
ASSERT_EQ(y, 20);
}
TEST(Matrix, scale) {
xy_t x = 0;
xy_t y = 0;
matrix_t m;
matrix_init(&m);
matrix_scale(&m, 2, 2);
2018-04-25 17:38:51 +08:00
matrix_transform_point(&m, 10, 20, &x, &y);
2018-03-23 19:15:24 +08:00
ASSERT_EQ(x, 20);
ASSERT_EQ(y, 40);
2018-03-24 21:37:40 +08:00
2018-03-23 19:15:24 +08:00
matrix_scale(&m, 0.5, 0.5);
2018-04-25 17:38:51 +08:00
matrix_transform_point(&m, 10, 20, &x, &y);
2018-03-23 19:15:24 +08:00
ASSERT_EQ(x, 10);
ASSERT_EQ(y, 20);
}
TEST(Matrix, all) {
xy_t x = 0;
xy_t y = 0;
matrix_t m;
matrix_init(&m);
matrix_scale(&m, 2, 2);
matrix_translate(&m, 2, 2);
matrix_scale(&m, 2, 2);
2018-03-24 21:37:40 +08:00
matrix_rotate(&m, 3.14159 / 2);
2018-03-23 19:15:24 +08:00
2018-04-25 17:38:51 +08:00
matrix_transform_point(&m, 10, 20, &x, &y);
2018-03-23 19:15:24 +08:00
ASSERT_EQ(x, -76);
ASSERT_EQ(y, 44);
}