OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/geometry/vector3d_f.h" | 5 #include "ui/gfx/geometry/vector3d_f.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 | 10 |
11 namespace { | 11 namespace { |
12 const float kRadiansToDegrees = 180.0f / 3.14159265f; | 12 const float kRadiansToDegrees = 180.0f / 3.14159265f; |
13 } | 13 } |
14 | 14 |
15 namespace gfx { | 15 namespace gfx { |
16 | 16 |
17 Vector3dF::Vector3dF() | |
18 : x_(0), | |
19 y_(0), | |
20 z_(0) { | |
21 } | |
22 | |
23 Vector3dF::Vector3dF(float x, float y, float z) | |
24 : x_(x), | |
25 y_(y), | |
26 z_(z) { | |
27 } | |
28 | |
29 Vector3dF::Vector3dF(const Vector2dF& other) | |
30 : x_(other.x()), | |
31 y_(other.y()), | |
32 z_(0) { | |
33 } | |
34 | |
35 std::string Vector3dF::ToString() const { | 17 std::string Vector3dF::ToString() const { |
36 return base::StringPrintf("[%f %f %f]", x_, y_, z_); | 18 return base::StringPrintf("[%f %f %f]", x_, y_, z_); |
37 } | 19 } |
38 | 20 |
39 bool Vector3dF::IsZero() const { | 21 bool Vector3dF::IsZero() const { |
40 return x_ == 0 && y_ == 0 && z_ == 0; | 22 return x_ == 0 && y_ == 0 && z_ == 0; |
41 } | 23 } |
42 | 24 |
43 void Vector3dF::Add(const Vector3dF& other) { | 25 void Vector3dF::Add(const Vector3dF& other) { |
44 x_ += other.x_; | 26 x_ += other.x_; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 86 |
105 // If the dot product of this cross product is normal, it means that the | 87 // If the dot product of this cross product is normal, it means that the |
106 // shortest angle between |base| and |other| was counterclockwise with respect | 88 // shortest angle between |base| and |other| was counterclockwise with respect |
107 // to the surface represented by |normal| and this angle must be reversed. | 89 // to the surface represented by |normal| and this angle must be reversed. |
108 if (gfx::DotProduct(cross, normal) > 0.0f) | 90 if (gfx::DotProduct(cross, normal) > 0.0f) |
109 angle = 360.0f - angle; | 91 angle = 360.0f - angle; |
110 return angle; | 92 return angle; |
111 } | 93 } |
112 | 94 |
113 } // namespace gfx | 95 } // namespace gfx |
OLD | NEW |