Remove WebKitTestRunner::setClientWindowRect.
[chromium-blink-merge.git] / ui / gfx / vector2d_f.cc
blob2ad267074b3b57c0620ac12a037b96d34c4b96cd
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/vector2d_f.h"
7 #include <cmath>
9 #include "base/strings/stringprintf.h"
11 namespace gfx {
13 std::string Vector2dF::ToString() const {
14 return base::StringPrintf("[%f %f]", x_, y_);
17 bool Vector2dF::IsZero() const {
18 return x_ == 0 && y_ == 0;
21 void Vector2dF::Add(const Vector2dF& other) {
22 x_ += other.x_;
23 y_ += other.y_;
26 void Vector2dF::Subtract(const Vector2dF& other) {
27 x_ -= other.x_;
28 y_ -= other.y_;
31 double Vector2dF::LengthSquared() const {
32 return static_cast<double>(x_) * x_ + static_cast<double>(y_) * y_;
35 float Vector2dF::Length() const {
36 return static_cast<float>(std::sqrt(LengthSquared()));
39 void Vector2dF::Scale(float x_scale, float y_scale) {
40 x_ *= x_scale;
41 y_ *= y_scale;
44 double CrossProduct(const Vector2dF& lhs, const Vector2dF& rhs) {
45 return static_cast<double>(lhs.x()) * rhs.y() -
46 static_cast<double>(lhs.y()) * rhs.x();
49 double DotProduct(const Vector2dF& lhs, const Vector2dF& rhs) {
50 return static_cast<double>(lhs.x()) * rhs.x() +
51 static_cast<double>(lhs.y()) * rhs.y();
54 Vector2dF ScaleVector2d(const Vector2dF& v, float x_scale, float y_scale) {
55 Vector2dF scaled_v(v);
56 scaled_v.Scale(x_scale, y_scale);
57 return scaled_v;
60 } // namespace gfx