Revert 187797 "Added tests for page launcher extensions in the a..."
[chromium-blink-merge.git] / ui / gfx / vector3d_f.cc
blob02f0378832491261cca41986fefe7abedee86502
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/vector3d_f.h"
7 #include <cmath>
9 #include "base/stringprintf.h"
11 namespace gfx {
13 Vector3dF::Vector3dF()
14 : x_(0),
15 y_(0),
16 z_(0) {
19 Vector3dF::Vector3dF(float x, float y, float z)
20 : x_(x),
21 y_(y),
22 z_(z) {
25 Vector3dF::Vector3dF(const Vector2dF& other)
26 : x_(other.x()),
27 y_(other.y()),
28 z_(0) {
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) {
40 x_ += other.x_;
41 y_ += other.y_;
42 z_ += other.z_;
45 void Vector3dF::Subtract(const Vector3dF& other) {
46 x_ -= other.x_;
47 y_ -= other.y_;
48 z_ -= other.z_;
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) {
61 x_ *= x_scale;
62 y_ *= y_scale;
63 z_ *= 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();
70 x_ = x;
71 y_ = y;
72 z_ = z;
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,
80 float x_scale,
81 float y_scale,
82 float z_scale) {
83 Vector3dF scaled_v(v);
84 scaled_v.Scale(x_scale, y_scale, z_scale);
85 return scaled_v;
88 } // namespace gfx