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