diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-05 18:25:28 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-05 18:25:28 +0000 |
commit | d23f84d28a54b80d57d946963b9c91b5f332a062 (patch) | |
tree | 3238a48aad214238b190e80e353ba80ba5cd3090 /ui | |
parent | 1423b89d2d0002555f06533539719ae3a7db6009 (diff) | |
download | chromium_src-d23f84d28a54b80d57d946963b9c91b5f332a062.zip chromium_src-d23f84d28a54b80d57d946963b9c91b5f332a062.tar.gz chromium_src-d23f84d28a54b80d57d946963b9c91b5f332a062.tar.bz2 |
Make adding and subtracting gfx:: point types simpler.
1) Removed iffy flooring conversion from Float types to Int types.
2) Added methods to convert from Int to Float types so you can do things like
add a Point to a PointF and viceversa.
3) Added operator+ and operator- for point types. This had to be done in both
Point and PointF headers to allow (Point+PointF) to compile.
4) Move the PointF::~PointF() destructor to the .cc file to be consistent with
other types.
5) Remove the unimplemented PointF::PointF(Point) constructor from the header.
BUG=152473
R=sky,jamesr
Review URL: https://codereview.chromium.org/10993094
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160426 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gfx/point.h | 13 | ||||
-rw-r--r-- | ui/gfx/point_f.cc | 8 | ||||
-rw-r--r-- | ui/gfx/point_f.h | 14 | ||||
-rw-r--r-- | ui/gfx/rect.h | 2 | ||||
-rw-r--r-- | ui/gfx/size.h | 5 | ||||
-rw-r--r-- | ui/gfx/size_f.cc | 8 | ||||
-rw-r--r-- | ui/gfx/size_f.h | 3 |
7 files changed, 29 insertions, 24 deletions
diff --git a/ui/gfx/point.h b/ui/gfx/point.h index dfb227d..4bf9d55 100644 --- a/ui/gfx/point.h +++ b/ui/gfx/point.h @@ -7,6 +7,7 @@ #include "ui/base/ui_export.h" #include "ui/gfx/point_base.h" +#include "ui/gfx/point_f.h" #if defined(OS_WIN) typedef unsigned long DWORD; @@ -43,10 +44,22 @@ class UI_EXPORT Point : public PointBase<Point, int> { CGPoint ToCGPoint() const; #endif + PointF ToPointF() const { + return PointF(x(), y()); + } + // Returns a string representation of point. std::string ToString() const; }; +inline Point operator+(Point lhs, Point rhs) { + return lhs.Add(rhs); +} + +inline Point operator-(Point lhs, Point rhs) { + return lhs.Subtract(rhs); +} + #if !defined(COMPILER_MSVC) extern template class PointBase<Point, int>; #endif diff --git a/ui/gfx/point_f.cc b/ui/gfx/point_f.cc index bdc4a66..3d814c5 100644 --- a/ui/gfx/point_f.cc +++ b/ui/gfx/point_f.cc @@ -4,10 +4,7 @@ #include "ui/gfx/point_f.h" -#include <cmath> - #include "base/stringprintf.h" -#include "ui/gfx/point.h" namespace gfx { @@ -19,10 +16,7 @@ PointF::PointF() : PointBase<PointF, float>(0, 0) { PointF::PointF(float x, float y) : PointBase<PointF, float>(x, y) { } -Point PointF::ToPoint() const { - return Point(static_cast<int>(std::floor(x())), - static_cast<int>(std::floor(y()))); -} +PointF::~PointF() {} std::string PointF::ToString() const { return base::StringPrintf("%f,%f", x(), y()); diff --git a/ui/gfx/point_f.h b/ui/gfx/point_f.h index e1871d8..ff1c4df 100644 --- a/ui/gfx/point_f.h +++ b/ui/gfx/point_f.h @@ -11,22 +11,26 @@ #include "ui/gfx/point_base.h" namespace gfx { -class Point; // A floating version of gfx::Point. class UI_EXPORT PointF : public PointBase<PointF, float> { public: PointF(); PointF(float x, float y); - explicit PointF(Point& point); - ~PointF() {} - - Point ToPoint() const; + ~PointF(); // Returns a string representation of point. std::string ToString() const; }; +inline PointF operator+(PointF lhs, PointF rhs) { + return lhs.Add(rhs); +} + +inline PointF operator-(PointF lhs, PointF rhs) { + return lhs.Subtract(rhs); +} + #if !defined(COMPILER_MSVC) extern template class PointBase<PointF, float>; #endif diff --git a/ui/gfx/rect.h b/ui/gfx/rect.h index 64f35b1..36f822c 100644 --- a/ui/gfx/rect.h +++ b/ui/gfx/rect.h @@ -68,7 +68,7 @@ class UI_EXPORT Rect : public RectBase<Rect, Point, Size, Insets, int> { CGRect ToCGRect() const; #endif - RectF ToRectF() const WARN_UNUSED_RESULT { + RectF ToRectF() const { return RectF(origin().x(), origin().y(), size().width(), size().height()); } diff --git a/ui/gfx/size.h b/ui/gfx/size.h index 2d01eee..8a53b97 100644 --- a/ui/gfx/size.h +++ b/ui/gfx/size.h @@ -10,6 +10,7 @@ #include "build/build_config.h" #include "ui/base/ui_export.h" #include "ui/gfx/size_base.h" +#include "ui/gfx/size_f.h" #if defined(OS_WIN) typedef struct tagSIZE SIZE; @@ -42,6 +43,10 @@ class UI_EXPORT Size : public SizeBase<Size, int> { CGSize ToCGSize() const; #endif + SizeF ToSizeF() const { + return SizeF(width(), height()); + } + std::string ToString() const; }; diff --git a/ui/gfx/size_f.cc b/ui/gfx/size_f.cc index 862c992..96c1867 100644 --- a/ui/gfx/size_f.cc +++ b/ui/gfx/size_f.cc @@ -4,11 +4,8 @@ #include "ui/gfx/size_f.h" -#include <cmath> - #include "base/logging.h" #include "base/stringprintf.h" -#include "ui/gfx/size.h" namespace gfx { @@ -23,11 +20,6 @@ SizeF::SizeF(float width, float height) : SizeBase<SizeF, float>(0, 0) { SizeF::~SizeF() {} -Size SizeF::ToSize() const { - return Size(static_cast<int>(std::floor(width())), - static_cast<int>(std::floor(height()))); -} - std::string SizeF::ToString() const { return base::StringPrintf("%fx%f", width(), height()); } diff --git a/ui/gfx/size_f.h b/ui/gfx/size_f.h index 5911500..c377395 100644 --- a/ui/gfx/size_f.h +++ b/ui/gfx/size_f.h @@ -8,7 +8,6 @@ #include <string> #include "ui/base/ui_export.h" -#include "ui/gfx/size.h" #include "ui/gfx/size_base.h" namespace gfx { @@ -20,8 +19,6 @@ class UI_EXPORT SizeF : public SizeBase<SizeF, float> { SizeF(float width, float height); ~SizeF(); - Size ToSize() const; - std::string ToString() const; }; |