Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: ui/gfx/vector2d_f.cc

Issue 11269022: Add Vector2d classes that represent offsets, instead of using Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more vector use fixes Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/stringprintf.h"
10
11 namespace gfx {
12
13 Vector2dF::Vector2dF()
14 : x_(0),
15 y_(0) {
16 }
17
18 Vector2dF::Vector2dF(float x, float y)
19 : x_(x),
20 y_(y) {
21 }
22
23 std::string Vector2dF::ToString() const {
24 return base::StringPrintf("[%f %f]", x_, y_);
25 }
26
27 bool Vector2dF::IsZero() const {
28 return x_ == 0 && y_ == 0;
29 }
30
31 void Vector2dF::Grow(float x, float y) {
32 x_ += x;
33 y_ += y;
34 }
35
36 void Vector2dF::Add(const Vector2dF& other) {
37 x_ += other.x_;
38 y_ += other.y_;
39 }
40
41 void Vector2dF::Subtract(const Vector2dF& other) {
42 x_ -= other.x_;
43 y_ -= other.y_;
44 }
45
46 float Vector2dF::LengthSquared() const {
47 return x_ * x_ + y_ * y_;
48 }
49
50 float Vector2dF::Length() const {
51 return static_cast<float>(std::sqrt(
52 static_cast<double>(x_) * x_ + static_cast<double>(y_) * y_));
53 }
54
55 void Vector2dF::Scale(float x_scale, float y_scale) {
56 x_ *= x_scale;
57 y_ *= y_scale;
58 }
59
60 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698