File: axis_transform2d_unittest.cc

package info (click to toggle)
chromium-browser 70.0.3538.110-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,619,476 kB
  • sloc: cpp: 13,024,755; ansic: 1,349,823; python: 916,672; xml: 314,489; java: 280,047; asm: 276,936; perl: 75,771; objc: 66,634; sh: 45,860; cs: 28,354; php: 11,064; makefile: 10,911; yacc: 9,109; tcl: 8,403; ruby: 4,065; lex: 1,779; pascal: 1,411; lisp: 1,055; awk: 41; jsp: 39; sed: 17; sql: 3
file content (91 lines) | stat: -rw-r--r-- 2,956 bytes parent folder | download | duplicates (10)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/gfx/geometry/axis_transform2d.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/test/gfx_util.h"

namespace gfx {
namespace {

TEST(AxisTransform2dTest, Mapping) {
  AxisTransform2d t(1.25f, Vector2dF(3.75f, 55.f));

  PointF p(150.f, 100.f);
  EXPECT_EQ(PointF(191.25f, 180.f), t.MapPoint(p));
  EXPECT_POINTF_EQ(PointF(117.f, 36.f), t.InverseMapPoint(p));

  RectF r(150.f, 100.f, 22.5f, 37.5f);
  EXPECT_EQ(RectF(191.25f, 180.f, 28.125f, 46.875f), t.MapRect(r));
  EXPECT_RECTF_EQ(RectF(117.f, 36.f, 18.f, 30.f), t.InverseMapRect(r));
}

TEST(AxisTransform2dTest, Scaling) {
  {
    AxisTransform2d t(1.25f, Vector2dF(3.75f, 55.f));
    EXPECT_EQ(AxisTransform2d(1.5625f, Vector2dF(3.75f, 55.f)),
              PreScaleAxisTransform2d(t, 1.25));
    t.PreScale(1.25);
    EXPECT_EQ(AxisTransform2d(1.5625f, Vector2dF(3.75f, 55.f)), t);
  }

  {
    AxisTransform2d t(1.25f, Vector2dF(3.75f, 55.f));
    EXPECT_EQ(AxisTransform2d(1.5625f, Vector2dF(4.6875f, 68.75f)),
              PostScaleAxisTransform2d(t, 1.25));
    t.PostScale(1.25);
    EXPECT_EQ(AxisTransform2d(1.5625f, Vector2dF(4.6875f, 68.75f)), t);
  }
}

TEST(AxisTransform2dTest, Translating) {
  Vector2dF tr(3.f, -5.f);
  {
    AxisTransform2d t(1.25f, Vector2dF(3.75f, 55.f));
    EXPECT_EQ(AxisTransform2d(1.25f, Vector2dF(7.5f, 48.75f)),
              PreTranslateAxisTransform2d(t, tr));
    t.PreTranslate(tr);
    EXPECT_EQ(AxisTransform2d(1.25f, Vector2dF(7.5f, 48.75f)), t);
  }

  {
    AxisTransform2d t(1.25f, Vector2dF(3.75f, 55.f));
    EXPECT_EQ(AxisTransform2d(1.25f, Vector2dF(6.75f, 50.f)),
              PostTranslateAxisTransform2d(t, tr));
    t.PostTranslate(tr);
    EXPECT_EQ(AxisTransform2d(1.25f, Vector2dF(6.75f, 50.f)), t);
  }
}

TEST(AxisTransform2dTest, Concat) {
  AxisTransform2d pre(1.25f, Vector2dF(3.75f, 55.f));
  AxisTransform2d post(0.5f, Vector2dF(10.f, 5.f));
  AxisTransform2d expectation(0.625f, Vector2dF(11.875f, 32.5f));
  EXPECT_EQ(expectation, ConcatAxisTransform2d(post, pre));

  AxisTransform2d post_concat = pre;
  post_concat.PostConcat(post);
  EXPECT_EQ(expectation, post_concat);

  AxisTransform2d pre_concat = post;
  pre_concat.PreConcat(pre);
  EXPECT_EQ(expectation, pre_concat);
}

TEST(AxisTransform2dTest, Inverse) {
  AxisTransform2d t(1.25f, Vector2dF(3.75f, 55.f));
  AxisTransform2d inv_inplace = t;
  inv_inplace.Invert();
  AxisTransform2d inv_out_of_place = InvertAxisTransform2d(t);

  EXPECT_AXIS_TRANSFORM2D_EQ(inv_inplace, inv_out_of_place);
  EXPECT_AXIS_TRANSFORM2D_EQ(AxisTransform2d(),
                             ConcatAxisTransform2d(t, inv_inplace));
  EXPECT_AXIS_TRANSFORM2D_EQ(AxisTransform2d(),
                             ConcatAxisTransform2d(inv_inplace, t));
}

}  // namespace
}  // namespace gfx