File: matrix.cpp

package info (click to toggle)
libcamera 0.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,380 kB
  • sloc: cpp: 81,540; python: 18,107; ansic: 12,608; sh: 1,258; makefile: 56
file content (53 lines) | stat: -rw-r--r-- 1,191 bytes parent folder | download
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
50
51
52
53
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2024, Ideas on Board Oy
 *
 * Matrix tests
 */

#include "libcamera/internal/matrix.h"

#include <cmath>
#include <iostream>

#include "test.h"

using namespace libcamera;

#define ASSERT_EQ(a, b)                                                   \
	if ((a) != (b)) {                                                 \
		std::cout << #a " != " #b << " (line " << __LINE__ << ")" \
			  << std::endl;                                   \
		return TestFail;                                          \
	}

class MatrixTest : public Test
{
protected:
	int run()
	{
		Matrix<double, 3, 3> m1;

		ASSERT_EQ(m1[0][0], 0.0);
		ASSERT_EQ(m1[0][1], 0.0);

		constexpr Matrix<float, 2, 2> m2 = Matrix<float, 2, 2>().identity();
		ASSERT_EQ(m2[0][0], 1.0);
		ASSERT_EQ(m2[0][1], 0.0);
		ASSERT_EQ(m2[1][0], 0.0);
		ASSERT_EQ(m2[1][1], 1.0);

		Matrix<float, 2, 2> m3{ { 2.0, 0.0, 0.0, 2.0 } };
		Matrix<float, 2, 2> m4 = m3.inverse();

		Matrix<float, 2, 2> m5 = m3 * m4;
		ASSERT_EQ(m5[0][0], 1.0);
		ASSERT_EQ(m5[0][1], 0.0);
		ASSERT_EQ(m5[1][0], 0.0);
		ASSERT_EQ(m5[1][1], 1.0);

		return TestPass;
	}
};

TEST_REGISTER(MatrixTest)