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/geometry/vector3d_f.h"
9 #include "base/strings/stringprintf.h"
13 Vector3dF::Vector3dF()
19 Vector3dF::Vector3dF(float x
, float y
, float z
)
25 Vector3dF::Vector3dF(const Vector2dF
& other
)
31 std::string
Vector3dF::ToString() const {
32 return base::StringPrintf("[%f %f %f]", x_
, y_
, z_
);
35 bool Vector3dF::IsZero() const {
36 return x_
== 0 && y_
== 0 && z_
== 0;
39 void Vector3dF::Add(const Vector3dF
& other
) {
45 void Vector3dF::Subtract(const Vector3dF
& other
) {
51 double Vector3dF::LengthSquared() const {
52 return static_cast<double>(x_
) * x_
+ static_cast<double>(y_
) * y_
+
53 static_cast<double>(z_
) * z_
;
56 float Vector3dF::Length() const {
57 return static_cast<float>(std::sqrt(LengthSquared()));
60 void Vector3dF::Scale(float x_scale
, float y_scale
, float z_scale
) {
66 void Vector3dF::Cross(const Vector3dF
& other
) {
67 float x
= y_
* other
.z() - z_
* other
.y();
68 float y
= z_
* other
.x() - x_
* other
.z();
69 float z
= x_
* other
.y() - y_
* other
.x();
75 float DotProduct(const Vector3dF
& lhs
, const Vector3dF
& rhs
) {
76 return lhs
.x() * rhs
.x() + lhs
.y() * rhs
.y() + lhs
.z() * rhs
.z();
79 Vector3dF
ScaleVector3d(const Vector3dF
& v
,
83 Vector3dF
scaled_v(v
);
84 scaled_v
.Scale(x_scale
, y_scale
, z_scale
);