mirror of
https://github.com/recp/cglm.git
synced 2025-10-04 09:08:53 +00:00
add tests for translate2d functions
This commit is contained in:
101
test/src/test_affine2d.h
Normal file
101
test/src/test_affine2d.h
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c), Recep Aslantas.
|
||||||
|
*
|
||||||
|
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||||
|
* Full license can be found in the LICENSE file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "test_common.h"
|
||||||
|
|
||||||
|
TEST_IMPL(GLM_PREFIX, translate2d) {
|
||||||
|
mat3 m1;
|
||||||
|
vec3 v1 = {2.0f, 3.0f, 1.0f}, v2;
|
||||||
|
|
||||||
|
glm_mat3_identity(m1);
|
||||||
|
GLM(translate2d)(m1, (vec2){13.0f, 11.0f});
|
||||||
|
glm_mat3_mulv(m1, v1, v2);
|
||||||
|
|
||||||
|
ASSERT(test_eq(v2[0], 15.0f))
|
||||||
|
ASSERT(test_eq(v2[1], 14.0f))
|
||||||
|
ASSERT(test_eq(v2[2], 1.0f))
|
||||||
|
|
||||||
|
glm_mat3_identity(m1);
|
||||||
|
GLM(translate2d)(m1, (vec2){1.0f, -1.0f});
|
||||||
|
glm_mat3_mulv(m1, v2, v2);
|
||||||
|
|
||||||
|
ASSERT(test_eq(v2[0], 16.0f))
|
||||||
|
ASSERT(test_eq(v2[1], 13.0f))
|
||||||
|
ASSERT(test_eq(v2[2], 1.0f))
|
||||||
|
|
||||||
|
TEST_SUCCESS
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_IMPL(GLM_PREFIX, translate2d_to) {
|
||||||
|
mat3 m1, m2;
|
||||||
|
vec3 v1 = {2.0f, 3.0f, 1.0f}, v2;
|
||||||
|
|
||||||
|
glm_mat3_identity(m1);
|
||||||
|
GLM(translate2d_to)(m1, (vec3){13.0f, 11.0f}, m2);
|
||||||
|
glm_mat3_mulv(m2, v1, v2);
|
||||||
|
|
||||||
|
ASSERT(test_eq(v2[0], 15.0f))
|
||||||
|
ASSERT(test_eq(v2[1], 14.0f))
|
||||||
|
ASSERT(test_eq(v2[2], 1.0f))
|
||||||
|
|
||||||
|
glm_mat3_identity(m1);
|
||||||
|
GLM(translate2d_to)(m1, (vec3){1.0f, -1.0f}, m2);
|
||||||
|
glm_mat3_mulv(m2, v2, v2);
|
||||||
|
|
||||||
|
ASSERT(test_eq(v2[0], 16.0f))
|
||||||
|
ASSERT(test_eq(v2[1], 13.0f))
|
||||||
|
ASSERT(test_eq(v2[2], 1.0f))
|
||||||
|
|
||||||
|
TEST_SUCCESS
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_IMPL(GLM_PREFIX, translate2d_x) {
|
||||||
|
mat3 m1;
|
||||||
|
vec3 v1 = {2.0f, 3.0f, 1.0f}, v2;
|
||||||
|
|
||||||
|
glm_mat3_identity(m1);
|
||||||
|
GLM(translate2d_x)(m1, 13.0f);
|
||||||
|
glm_mat3_mulv(m1, v1, v2);
|
||||||
|
|
||||||
|
ASSERT(test_eq(v2[0], 15.0f))
|
||||||
|
ASSERT(test_eq(v2[1], 3.0f))
|
||||||
|
ASSERT(test_eq(v2[2], 1.0f))
|
||||||
|
|
||||||
|
glm_mat3_identity(m1);
|
||||||
|
GLM(translate2d_x)(m1, -1.0f);
|
||||||
|
glm_mat3_mulv(m1, v2, v2);
|
||||||
|
|
||||||
|
ASSERT(test_eq(v2[0], 14.0f))
|
||||||
|
ASSERT(test_eq(v2[1], 3.0f))
|
||||||
|
ASSERT(test_eq(v2[2], 1.0f))
|
||||||
|
|
||||||
|
TEST_SUCCESS
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_IMPL(GLM_PREFIX, translate2d_y) {
|
||||||
|
mat3 m1;
|
||||||
|
vec3 v1 = {2.0f, 3.0f, 1.0f}, v2;
|
||||||
|
|
||||||
|
glm_mat3_identity(m1);
|
||||||
|
GLM(translate2d_y)(m1, 11.0f);
|
||||||
|
glm_mat3_mulv(m1, v1, v2);
|
||||||
|
|
||||||
|
|
||||||
|
ASSERT(test_eq(v2[0], 2.0f))
|
||||||
|
ASSERT(test_eq(v2[1], 14.0f))
|
||||||
|
ASSERT(test_eq(v2[2], 1.0f))
|
||||||
|
|
||||||
|
glm_mat3_identity(m1);
|
||||||
|
GLM(translate2d_y)(m1, -1.0f);
|
||||||
|
glm_mat3_mulv(m1, v2, v2);
|
||||||
|
|
||||||
|
ASSERT(test_eq(v2[0], 2.0f))
|
||||||
|
ASSERT(test_eq(v2[1], 13.0f))
|
||||||
|
ASSERT(test_eq(v2[2], 1.0f))
|
||||||
|
|
||||||
|
TEST_SUCCESS
|
||||||
|
}
|
@@ -22,6 +22,7 @@
|
|||||||
#include "test_project.h"
|
#include "test_project.h"
|
||||||
#include "test_plane.h"
|
#include "test_plane.h"
|
||||||
#include "test_affine.h"
|
#include "test_affine.h"
|
||||||
|
#include "test_affine2d.h"
|
||||||
#include "test_affine_mat.h"
|
#include "test_affine_mat.h"
|
||||||
#include "test_ray.h"
|
#include "test_ray.h"
|
||||||
#include "test_camera.h"
|
#include "test_camera.h"
|
||||||
@@ -45,6 +46,7 @@
|
|||||||
#include "test_project.h"
|
#include "test_project.h"
|
||||||
#include "test_plane.h"
|
#include "test_plane.h"
|
||||||
#include "test_affine.h"
|
#include "test_affine.h"
|
||||||
|
#include "test_affine2d.h"
|
||||||
#include "test_affine_mat.h"
|
#include "test_affine_mat.h"
|
||||||
#include "test_ray.h"
|
#include "test_ray.h"
|
||||||
#include "test_camera.h"
|
#include "test_camera.h"
|
||||||
|
22
test/tests.h
22
test/tests.h
@@ -70,6 +70,17 @@ TEST_DECLARE(glmc_uniscaled)
|
|||||||
TEST_DECLARE(glmc_decompose_rs)
|
TEST_DECLARE(glmc_decompose_rs)
|
||||||
TEST_DECLARE(glmc_decompose)
|
TEST_DECLARE(glmc_decompose)
|
||||||
|
|
||||||
|
/* affine 2d */
|
||||||
|
TEST_DECLARE(glm_translate2d)
|
||||||
|
TEST_DECLARE(glm_translate2d_to)
|
||||||
|
TEST_DECLARE(glm_translate2d_x)
|
||||||
|
TEST_DECLARE(glm_translate2d_y)
|
||||||
|
|
||||||
|
TEST_DECLARE(glmc_translate2d)
|
||||||
|
TEST_DECLARE(glmc_translate2d_to)
|
||||||
|
TEST_DECLARE(glmc_translate2d_x)
|
||||||
|
TEST_DECLARE(glmc_translate2d_y)
|
||||||
|
|
||||||
/* mat4 */
|
/* mat4 */
|
||||||
TEST_DECLARE(glm_mat4_ucopy)
|
TEST_DECLARE(glm_mat4_ucopy)
|
||||||
TEST_DECLARE(glm_mat4_copy)
|
TEST_DECLARE(glm_mat4_copy)
|
||||||
@@ -764,6 +775,17 @@ TEST_LIST {
|
|||||||
TEST_ENTRY(glmc_uniscaled)
|
TEST_ENTRY(glmc_uniscaled)
|
||||||
TEST_ENTRY(glmc_decompose_rs)
|
TEST_ENTRY(glmc_decompose_rs)
|
||||||
TEST_ENTRY(glmc_decompose)
|
TEST_ENTRY(glmc_decompose)
|
||||||
|
|
||||||
|
/* affine 2d */
|
||||||
|
TEST_ENTRY(glm_translate2d)
|
||||||
|
TEST_ENTRY(glm_translate2d_to)
|
||||||
|
TEST_ENTRY(glm_translate2d_x)
|
||||||
|
TEST_ENTRY(glm_translate2d_y)
|
||||||
|
|
||||||
|
TEST_ENTRY(glmc_translate2d)
|
||||||
|
TEST_ENTRY(glmc_translate2d_to)
|
||||||
|
TEST_ENTRY(glmc_translate2d_x)
|
||||||
|
TEST_ENTRY(glmc_translate2d_y)
|
||||||
|
|
||||||
/* mat4 */
|
/* mat4 */
|
||||||
TEST_ENTRY(glm_mat4_ucopy)
|
TEST_ENTRY(glm_mat4_ucopy)
|
||||||
|
Reference in New Issue
Block a user