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.
5 #include "base/basictypes.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/gfx/geometry/point3_f.h"
11 TEST(Point3Test
, VectorArithmetic
) {
12 gfx::Point3F
a(1.6f
, 5.1f
, 3.2f
);
13 gfx::Vector3dF
v1(3.1f
, -3.2f
, 9.3f
);
14 gfx::Vector3dF
v2(-8.1f
, 1.2f
, 3.3f
);
17 gfx::Point3F expected
;
20 { gfx::Point3F(4.7f
, 1.9f
, 12.5f
), a
+ v1
},
21 { gfx::Point3F(-1.5f
, 8.3f
, -6.1f
), a
- v1
},
24 { a
, a
+ gfx::Vector3dF() },
25 { gfx::Point3F(12.8f
, 0.7f
, 9.2f
), a
+ v1
- v2
},
26 { gfx::Point3F(-9.6f
, 9.5f
, -2.8f
), a
- v1
+ v2
}
29 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(tests
); ++i
)
30 EXPECT_EQ(tests
[i
].expected
.ToString(),
31 tests
[i
].actual
.ToString());
34 EXPECT_EQ(Point3F(4.7f
, 1.9f
, 12.5f
).ToString(), a
.ToString());
37 EXPECT_EQ(Point3F(12.8f
, 0.7f
, 9.2f
).ToString(), a
.ToString());
40 TEST(Point3Test
, VectorFromPoints
) {
41 gfx::Point3F
a(1.6f
, 5.2f
, 3.2f
);
42 gfx::Vector3dF
v1(3.1f
, -3.2f
, 9.3f
);
44 gfx::Point3F
b(a
+ v1
);
45 EXPECT_EQ((b
- a
).ToString(), v1
.ToString());
48 TEST(Point3Test
, Scale
) {
49 EXPECT_EQ(Point3F().ToString(), ScalePoint(Point3F(), 2.f
).ToString());
50 EXPECT_EQ(Point3F().ToString(),
51 ScalePoint(Point3F(), 2.f
, 2.f
, 2.f
).ToString());
53 EXPECT_EQ(Point3F(2.f
, -2.f
, 4.f
).ToString(),
54 ScalePoint(Point3F(1.f
, -1.f
, 2.f
), 2.f
).ToString());
55 EXPECT_EQ(Point3F(2.f
, -3.f
, 8.f
).ToString(),
56 ScalePoint(Point3F(1.f
, -1.f
, 2.f
), 2.f
, 3.f
, 4.f
).ToString());
60 zero
.Scale(6.f
, 3.f
, 1.5f
);
61 EXPECT_EQ(Point3F().ToString(), zero
.ToString());
63 Point3F
point(1.f
, -1.f
, 2.f
);
65 point
.Scale(6.f
, 3.f
, 1.5f
);
66 EXPECT_EQ(Point3F(12.f
, -6.f
, 6.f
).ToString(), point
.ToString());