aboutsummaryrefslogtreecommitdiff
path: root/test/platform/MatrixTest.cpp
blob: c107ddc39033f61dd8b38781cfc281134a152917 (plain)
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
#include "cru/platform/GraphicsBase.h"
#include "cru/platform/Matrix.h"

#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp>

using Catch::Approx;
using cru::platform::Matrix;

TEST_CASE("Matrix Rotation", "[matrix]") {
  using cru::platform::Point;

  Point p(1, 1);

  Point p90 = Matrix::Rotation(90).TransformPoint(p);
  REQUIRE(p90.x == Approx(-1));
  REQUIRE(p90.y == Approx(1));

  Point p180 = Matrix::Rotation(180).TransformPoint(p);
  REQUIRE(p180.x == Approx(-1));
  REQUIRE(p180.y == Approx(-1));

  Point p270 = Matrix::Rotation(270).TransformPoint(p);
  REQUIRE(p270.x == Approx(1));
  REQUIRE(p270.y == Approx(-1));
}

TEST_CASE("Matrix TranslationAndRotation", "[matrix]") {
  using cru::platform::Point;

  Point p =
      (Matrix::Translation(1, 1) * Matrix::Rotation(90)).TransformPoint({1, 1});
  REQUIRE(p.x == Approx(-2));
  REQUIRE(p.y == Approx(2));
}

TEST_CASE("Matrix RotationAndTranslation", "[matrix]") {
  using cru::platform::Point;

  Point p =
      (Matrix::Rotation(90) * Matrix::Translation(1, 1)).TransformPoint({1, 1});
  REQUIRE(p.x == Approx(0));
  REQUIRE(p.y == Approx(2));
}