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

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

Powered by Google App Engine
This is Rietveld 408576698