| Index: ui/gfx/vector2d_f.h
|
| diff --git a/ui/gfx/vector2d_f.h b/ui/gfx/vector2d_f.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..abdc9bd8eeff7ca6bf6774d7016fac19efc56248
|
| --- /dev/null
|
| +++ b/ui/gfx/vector2d_f.h
|
| @@ -0,0 +1,90 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +// Defines a simple float vector class. This class is used to indicate a
|
| +// distance in two dimentions between two points. Subtracting two points should
|
| +// produce a vector, and adding a vector to a point produces the point at the
|
| +// vector's distance from the original point.
|
| +
|
| +#ifndef UI_GFX_VECTOR2D_F_H_
|
| +#define UI_GFX_VECTOR2D_F_H_
|
| +
|
| +#include <cmath>
|
| +#include <string>
|
| +
|
| +#include "ui/base/ui_export.h"
|
| +
|
| +namespace gfx {
|
| +
|
| +class UI_EXPORT Vector2dF {
|
| + public:
|
| + Vector2dF();
|
| + Vector2dF(float x, float y);
|
| +
|
| + float x() const { return x_; }
|
| + void set_x(float x) { x_ = x; }
|
| +
|
| + float y() const { return y_; }
|
| + void set_y(float y) { y_ = y; }
|
| +
|
| + bool IsZero() const { return x_ == 0 && y_ == 0; }
|
| +
|
| + void Grow(float x, float y) {
|
| + x_ += x;
|
| + y_ += y;
|
| + }
|
| +
|
| + void Add(const Vector2dF& other) {
|
| + x_ += other.x_;
|
| + y_ += other.y_;
|
| + }
|
| +
|
| + void Scale(float scale) {
|
| + Scale(scale, scale);
|
| + }
|
| +
|
| + void Scale(float x_scale, float y_scale) {
|
| + x_ *= x_scale;
|
| + y_ *= y_scale;
|
| + }
|
| +
|
| + float LengthSquared() const {
|
| + return x_ * x_ + y_ * y_;
|
| + }
|
| +
|
| + float Length() const {
|
| + return static_cast<float>(std::sqrt(
|
| + static_cast<double>(x_) * x_ + static_cast<double>(y_) * y_));
|
| + }
|
| +
|
| + std::string ToString() const;
|
| +
|
| + private:
|
| + float x_;
|
| + float y_;
|
| +};
|
| +
|
| +inline bool operator==(const Vector2dF& lhs, const Vector2dF& rhs) {
|
| + return lhs.x() == rhs.x() && lhs.y() == rhs.y();
|
| +}
|
| +
|
| +inline Vector2dF operator-(const Vector2dF& v) {
|
| + return Vector2dF(-v.x(), -v.y());
|
| +}
|
| +
|
| +inline Vector2dF operator+(const Vector2dF& lhs, const Vector2dF& rhs) {
|
| + Vector2dF result = lhs;
|
| + result.Add(rhs);
|
| + return result;
|
| +}
|
| +
|
| +inline Vector2dF operator-(const Vector2dF& lhs, const Vector2dF& rhs) {
|
| + Vector2dF result = lhs;
|
| + result.Add(-rhs);
|
| + return result;
|
| +}
|
| +
|
| +} // namespace gfx
|
| +
|
| +#endif // UI_GFX_VECTOR2D_F_H_
|
|
|