Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Unified Diff: ui/gfx/vector2d_f.h

Issue 11269022: Add Vector2d classes that represent offsets, instead of using Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..2a451f9ff283e73df1e47889fa3d1927f61edd08
--- /dev/null
+++ b/ui/gfx/vector2d_f.h
@@ -0,0 +1,53 @@
+// 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 <string>
+
+#include "ui/base/ui_export.h"
+
+namespace gfx {
+
+class UI_EXPORT Vector2dF {
+ public:
+ Vector2dF();
+ Vector2dF(float x, float y);
+
+ float x() const { return m_x; }
+ void set_x(float x) { m_x = x; }
+
+ float y() const { return m_y; }
+ void set_y(float y) { m_y = y; }
+
+ void Grow(float x, float y) {
+ m_x += x;
+ m_y += y;
+ }
+
+ void Add(const Vector2dF& other) {
+ m_x += other.m_x;
+ m_y += other.m_y;
+ }
+
+ std::string ToString() const;
+
+ private:
+ float m_x;
tfarina 2012/10/25 00:40:20 nit: please remember that we are in chromium code,
+ float m_y;
+};
+
+inline Vector2dF operator-(const Vector2dF& v) {
+ return Vector2dF(-v.x(), -v.y());
+}
+
+} // namespace gfx
+
+#endif // UI_GFX_VECTOR2D_F_H_
« ui/gfx/vector2d.h ('K') | « ui/gfx/vector2d.cc ('k') | ui/gfx/vector2d_f.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698