• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "ui/gfx/point3_f.h"
6 
7 #include "base/basictypes.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 
10 namespace gfx {
11 
TEST(Point3Test,VectorArithmetic)12 TEST(Point3Test, VectorArithmetic) {
13   gfx::Point3F a(1.6f, 5.1f, 3.2f);
14   gfx::Vector3dF v1(3.1f, -3.2f, 9.3f);
15   gfx::Vector3dF v2(-8.1f, 1.2f, 3.3f);
16 
17   static const struct {
18     gfx::Point3F expected;
19     gfx::Point3F actual;
20   } tests[] = {
21     { gfx::Point3F(4.7f, 1.9f, 12.5f), a + v1 },
22     { gfx::Point3F(-1.5f, 8.3f, -6.1f), a - v1 },
23     { a, a - v1 + v1 },
24     { a, a + v1 - v1 },
25     { a, a + gfx::Vector3dF() },
26     { gfx::Point3F(12.8f, 0.7f, 9.2f), a + v1 - v2 },
27     { gfx::Point3F(-9.6f, 9.5f, -2.8f), a - v1 + v2 }
28   };
29 
30   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i)
31     EXPECT_EQ(tests[i].expected.ToString(),
32               tests[i].actual.ToString());
33 
34   a += v1;
35   EXPECT_EQ(Point3F(4.7f, 1.9f, 12.5f).ToString(), a.ToString());
36 
37   a -= v2;
38   EXPECT_EQ(Point3F(12.8f, 0.7f, 9.2f).ToString(), a.ToString());
39 }
40 
TEST(Point3Test,VectorFromPoints)41 TEST(Point3Test, VectorFromPoints) {
42   gfx::Point3F a(1.6f, 5.2f, 3.2f);
43   gfx::Vector3dF v1(3.1f, -3.2f, 9.3f);
44 
45   gfx::Point3F b(a + v1);
46   EXPECT_EQ((b - a).ToString(), v1.ToString());
47 }
48 
TEST(Point3Test,Scale)49 TEST(Point3Test, Scale) {
50   EXPECT_EQ(Point3F().ToString(), ScalePoint(Point3F(), 2.f).ToString());
51   EXPECT_EQ(Point3F().ToString(),
52             ScalePoint(Point3F(), 2.f, 2.f, 2.f).ToString());
53 
54   EXPECT_EQ(Point3F(2.f, -2.f, 4.f).ToString(),
55             ScalePoint(Point3F(1.f, -1.f, 2.f), 2.f).ToString());
56   EXPECT_EQ(Point3F(2.f, -3.f, 8.f).ToString(),
57             ScalePoint(Point3F(1.f, -1.f, 2.f), 2.f, 3.f, 4.f).ToString());
58 
59   Point3F zero;
60   zero.Scale(2.f);
61   zero.Scale(6.f, 3.f, 1.5f);
62   EXPECT_EQ(Point3F().ToString(), zero.ToString());
63 
64   Point3F point(1.f, -1.f, 2.f);
65   point.Scale(2.f);
66   point.Scale(6.f, 3.f, 1.5f);
67   EXPECT_EQ(Point3F(12.f, -6.f, 6.f).ToString(), point.ToString());
68 }
69 
70 }  // namespace gfx
71