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

Unified Diff: ui/gfx/geometry/point_f.h

Issue 642343003: gfx: De-templatize the gfx::Point and gfx::PointF classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: inlines-point: rebase Created 6 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
« no previous file with comments | « ui/gfx/geometry/point_base.h ('k') | ui/gfx/geometry/point_f.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/geometry/point_f.h
diff --git a/ui/gfx/geometry/point_f.h b/ui/gfx/geometry/point_f.h
index a0b6d33a283a589cac62325f1fafb2f93fa41cad..f900c1ceae727cf408afff98b81e4d30ae3ae5ad 100644
--- a/ui/gfx/geometry/point_f.h
+++ b/ui/gfx/geometry/point_f.h
@@ -8,19 +8,60 @@
#include <iosfwd>
#include <string>
-#include "ui/gfx/geometry/point_base.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/gfx_export.h"
namespace gfx {
// A floating version of gfx::Point.
-class GFX_EXPORT PointF : public PointBase<PointF, float, Vector2dF> {
+class GFX_EXPORT PointF {
public:
- PointF() : PointBase<PointF, float, Vector2dF>(0, 0) {}
- PointF(float x, float y) : PointBase<PointF, float, Vector2dF>(x, y) {}
+ PointF() : x_(0.f), y_(0.f) {}
+ PointF(float x, float y) : x_(x), y_(y) {}
~PointF() {}
+ float x() const { return x_; }
+ float y() const { return y_; }
+ void set_x(float x) { x_ = x; }
+ void set_y(float y) { y_ = y; }
+
+ void SetPoint(float x, float y) {
+ x_ = x;
+ y_ = y;
+ }
+
+ void Offset(float delta_x, float delta_y) {
+ x_ += delta_x;
+ y_ += delta_y;
+ }
+
+ void operator+=(const Vector2dF& vector) {
+ x_ += vector.x();
+ y_ += vector.y();
+ }
+
+ void operator-=(const Vector2dF& vector) {
+ x_ -= vector.x();
+ y_ -= vector.y();
+ }
+
+ void SetToMin(const PointF& other);
+ void SetToMax(const PointF& other);
+
+ bool IsOrigin() const { return x_ == 0 && y_ == 0; }
+
+ Vector2dF OffsetFromOrigin() const { return Vector2dF(x_, y_); }
+
+ // A point is less than another point if its y-value is closer
+ // to the origin. If the y-values are the same, then point with
+ // the x-value closer to the origin is considered less than the
+ // other.
+ // This comparison is required to use PointF in sets, or sorted
+ // vectors.
+ bool operator<(const PointF& rhs) const {
+ return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_);
+ }
+
void Scale(float scale) {
Scale(scale, scale);
}
@@ -31,6 +72,10 @@ class GFX_EXPORT PointF : public PointBase<PointF, float, Vector2dF> {
// Returns a string representation of point.
std::string ToString() const;
+
+ private:
+ float x_;
+ float y_;
};
inline bool operator==(const PointF& lhs, const PointF& rhs) {
@@ -67,10 +112,6 @@ inline PointF ScalePoint(const PointF& p, float scale) {
return ScalePoint(p, scale, scale);
}
-#if !defined(COMPILER_MSVC) && !defined(__native_client__)
-extern template class PointBase<PointF, float, Vector2dF>;
-#endif
-
// This is declared here for use in gtest-based unit tests but is defined in
// the gfx_test_support target. Depend on that to use this in your unit test.
// This should not be used in production code - call ToString() instead.
« no previous file with comments | « ui/gfx/geometry/point_base.h ('k') | ui/gfx/geometry/point_f.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698