2018-12-15 17:22:05 +08:00
|
|
|
|
#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);
|
|
|
|
|
}
|
2021-06-24 08:10:31 +08:00
|
|
|
|
|
|
|
|
|
TEST(Matrix, basic1) {
|
|
|
|
|
xy_t x = 0;
|
|
|
|
|
xy_t y = 0;
|
|
|
|
|
xy_t ox = 0;
|
|
|
|
|
xy_t oy = 0;
|
|
|
|
|
matrix_t m;
|
|
|
|
|
|
|
|
|
|
matrix_init(&m);
|
|
|
|
|
matrix_translate(&m, ox, oy);
|
|
|
|
|
matrix_translate(&m, 50, 50);
|
|
|
|
|
matrix_rotate(&m, 3.14159 / 2);
|
|
|
|
|
matrix_translate(&m, -50, -50);
|
|
|
|
|
|
2021-06-24 22:14:27 +08:00
|
|
|
|
matrix_transform_point(&m, ox + 50, oy, &x, &y);
|
2021-06-24 08:10:31 +08:00
|
|
|
|
|
|
|
|
|
ASSERT_EQ(x, 100);
|
|
|
|
|
ASSERT_EQ(y, 50);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Matrix, basic2) {
|
|
|
|
|
xy_t x = 0;
|
|
|
|
|
xy_t y = 0;
|
|
|
|
|
xy_t ox = 0;
|
|
|
|
|
xy_t oy = 10;
|
|
|
|
|
matrix_t m;
|
|
|
|
|
|
|
|
|
|
matrix_init(&m);
|
|
|
|
|
matrix_translate(&m, ox, oy);
|
|
|
|
|
matrix_translate(&m, 50, 50);
|
|
|
|
|
matrix_rotate(&m, 3.14159 / 2);
|
|
|
|
|
matrix_translate(&m, -50, -50);
|
|
|
|
|
|
|
|
|
|
matrix_transform_point(&m, 50, 0, &x, &y);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(x, 100);
|
|
|
|
|
ASSERT_EQ(y, 60);
|
|
|
|
|
}
|