summaryrefslogtreecommitdiffstats
path: root/ui/gfx/point_f.h
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-11 09:32:12 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-11 09:32:12 +0000
commit54a337516820c79a368a8bbca2aa2da9944cfb5c (patch)
tree14850789dc739e6618de5f51e04a9a35ccc82ed2 /ui/gfx/point_f.h
parente5c45f6c5f6778f1da0053ccbb8d95a15bdbcc14 (diff)
downloadchromium_src-54a337516820c79a368a8bbca2aa2da9944cfb5c.zip
chromium_src-54a337516820c79a368a8bbca2aa2da9944cfb5c.tar.gz
chromium_src-54a337516820c79a368a8bbca2aa2da9944cfb5c.tar.bz2
Revert r131737 "Use template for Point/Size/Rect and remove duplicates "
TBR=oshima@chromium.org BUG=114664 TEST=none Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=131737 Review URL: https://chromiumcodereview.appspot.com/10020034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131738 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/point_f.h')
-rw-r--r--ui/gfx/point_f.h66
1 files changed, 61 insertions, 5 deletions
diff --git a/ui/gfx/point_f.h b/ui/gfx/point_f.h
index 5d29c48..877195b 100644
--- a/ui/gfx/point_f.h
+++ b/ui/gfx/point_f.h
@@ -8,8 +8,8 @@
#include <string>
+#include "build/build_config.h"
#include "ui/base/ui_export.h"
-#include "ui/gfx/point_base.h"
#if !defined(ENABLE_DIP)
#error "This class should be used only when DIP feature is enabled"
@@ -18,18 +18,74 @@
namespace gfx {
class Point;
-// A floating version of gfx::Point.
-class UI_EXPORT PointF : public PointBase<PointF, float> {
+// A floating versino of gfx::Point. This is copied, instead of using
+// template, to avoid conflict with m19 branch.
+// TODO(oshima): Merge this to ui/gfx/point.h using template.
+class UI_EXPORT PointF {
public:
PointF();
PointF(float x, float y);
- explicit PointF(Point& point);
- virtual ~PointF() {}
+ PointF(Point& point);
+ ~PointF() {}
+
+ float x() const { return x_; }
+ float y() const { return y_; }
+
+ void SetPoint(float x, float y) {
+ x_ = x;
+ y_ = y;
+ }
+
+ void set_x(float x) { x_ = x; }
+ void set_y(float y) { y_ = y; }
+
+ void Offset(float delta_x, float delta_y) {
+ x_ += delta_x;
+ y_ += delta_y;
+ }
+
+ PointF Add(const PointF& other) const{
+ PointF copy = *this;
+ copy.Offset(other.x_, other.y_);
+ return copy;
+ }
+
+ PointF Subtract(const PointF& other) const {
+ PointF copy = *this;
+ copy.Offset(-other.x_, -other.y_);
+ return copy;
+ }
+
+ PointF Middle(const PointF& other) const {
+ return PointF((x_ + other.x_) / 2, (y_ + other.y_) / 2);
+ }
+
+ bool operator==(const PointF& rhs) const {
+ return x_ == rhs.x_ && y_ == rhs.y_;
+ }
+
+ bool operator!=(const PointF& rhs) const {
+ return !(*this == rhs);
+ }
+
+ // 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 Points in sets, or sorted
+ // vectors.
+ bool operator<(const PointF& rhs) const {
+ return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_);
+ }
Point ToPoint() const;
// Returns a string representation of point.
std::string ToString() const;
+
+ private:
+ float x_;
+ float y_;
};
} // namespace gfx