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 "ui/gfx/point3_f.h"
7 #include "base/basictypes.h"
8 #include "testing/gtest/include/gtest/gtest.h"
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
);
18 gfx::Point3F expected
;
21 { gfx::Point3F(4.7f
, 1.9f
, 12.5f
), a
+ v1
},
22 { gfx::Point3F(-1.5f
, 8.3f
, -6.1f
), a
- 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
}
30 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(tests
); ++i
)
31 EXPECT_EQ(tests
[i
].expected
.ToString(),
32 tests
[i
].actual
.ToString());
35 EXPECT_EQ(Point3F(4.7f
, 1.9f
, 12.5f
).ToString(), a
.ToString());
38 EXPECT_EQ(Point3F(12.8f
, 0.7f
, 9.2f
).ToString(), a
.ToString());
41 TEST(Point3Test
, VectorFromPoints
) {
42 gfx::Point3F
a(1.6f
, 5.2f
, 3.2f
);
43 gfx::Vector3dF
v1(3.1f
, -3.2f
, 9.3f
);
45 gfx::Point3F
b(a
+ v1
);
46 EXPECT_EQ((b
- a
).ToString(), v1
.ToString());
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());
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());
61 zero
.Scale(6.f
, 3.f
, 1.5f
);
62 EXPECT_EQ(Point3F().ToString(), zero
.ToString());
64 Point3F
point(1.f
, -1.f
, 2.f
);
66 point
.Scale(6.f
, 3.f
, 1.5f
);
67 EXPECT_EQ(Point3F(12.f
, -6.f
, 6.f
).ToString(), point
.ToString());