OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "ui/gfx/vector2d_f.h" | |
6 | |
7 #include <cmath> | |
8 | |
9 #include "base/strings/stringprintf.h" | |
10 | |
11 namespace gfx { | |
12 | |
13 std::string Vector2dF::ToString() const { | |
14 return base::StringPrintf("[%f %f]", x_, y_); | |
15 } | |
16 | |
17 bool Vector2dF::IsZero() const { | |
18 return x_ == 0 && y_ == 0; | |
19 } | |
20 | |
21 void Vector2dF::Add(const Vector2dF& other) { | |
22 x_ += other.x_; | |
23 y_ += other.y_; | |
24 } | |
25 | |
26 void Vector2dF::Subtract(const Vector2dF& other) { | |
27 x_ -= other.x_; | |
28 y_ -= other.y_; | |
29 } | |
30 | |
31 double Vector2dF::LengthSquared() const { | |
32 return static_cast<double>(x_) * x_ + static_cast<double>(y_) * y_; | |
33 } | |
34 | |
35 float Vector2dF::Length() const { | |
36 return static_cast<float>(std::sqrt(LengthSquared())); | |
37 } | |
38 | |
39 void Vector2dF::Scale(float x_scale, float y_scale) { | |
40 x_ *= x_scale; | |
41 y_ *= y_scale; | |
42 } | |
43 | |
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(); | |
47 } | |
48 | |
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(); | |
52 } | |
53 | |
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; | |
58 } | |
59 | |
60 } // namespace gfx | |
OLD | NEW |