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