Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / gfx / geometry / vector2d.cc
blobd9f57fd3b10922c73ce977e2a42fa469a0950fbd
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.
5 #include "ui/gfx/geometry/vector2d.h"
7 #include <cmath>
9 #include "base/strings/stringprintf.h"
11 namespace gfx {
13 bool Vector2d::IsZero() const {
14 return x_ == 0 && y_ == 0;
17 void Vector2d::Add(const Vector2d& other) {
18 x_ += other.x_;
19 y_ += other.y_;
22 void Vector2d::Subtract(const Vector2d& other) {
23 x_ -= other.x_;
24 y_ -= other.y_;
27 int64 Vector2d::LengthSquared() const {
28 return static_cast<int64>(x_) * x_ + static_cast<int64>(y_) * y_;
31 float Vector2d::Length() const {
32 return static_cast<float>(std::sqrt(static_cast<double>(LengthSquared())));
35 std::string Vector2d::ToString() const {
36 return base::StringPrintf("[%d %d]", x_, y_);
39 } // namespace gfx