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/vector2d_f.h"
9 #include "base/strings/stringprintf.h"
13 std::string
Vector2dF::ToString() const {
14 return base::StringPrintf("[%f %f]", x_
, y_
);
17 bool Vector2dF::IsZero() const {
18 return x_
== 0 && y_
== 0;
21 void Vector2dF::Add(const Vector2dF
& other
) {
26 void Vector2dF::Subtract(const Vector2dF
& other
) {
31 double Vector2dF::LengthSquared() const {
32 return static_cast<double>(x_
) * x_
+ static_cast<double>(y_
) * y_
;
35 float Vector2dF::Length() const {
36 return static_cast<float>(std::sqrt(LengthSquared()));
39 void Vector2dF::Scale(float x_scale
, float y_scale
) {
44 double CrossProduct(const Vector2dF
& lhs
, const Vector2dF
& rhs
) {
45 return static_cast<double>(lhs
.x()) * rhs
.y() -
46 static_cast<double>(lhs
.y()) * rhs
.x();
49 double DotProduct(const Vector2dF
& lhs
, const Vector2dF
& rhs
) {
50 return static_cast<double>(lhs
.x()) * rhs
.x() +
51 static_cast<double>(lhs
.y()) * rhs
.y();
54 Vector2dF
ScaleVector2d(const Vector2dF
& v
, float x_scale
, float y_scale
) {
55 Vector2dF
scaled_v(v
);
56 scaled_v
.Scale(x_scale
, y_scale
);