KHTML
FloatPoint.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef FloatPoint_h
00028 #define FloatPoint_h
00029
00030 #include "FloatSize.h"
00031 #include <wtf/Platform.h>
00032
00033 #if PLATFORM(CG)
00034 typedef struct CGPoint CGPoint;
00035 #endif
00036
00037 #if PLATFORM(MAC)
00038 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
00039 typedef struct CGPoint NSPoint;
00040 #else
00041 typedef struct _NSPoint NSPoint;
00042 #endif
00043 #endif
00044
00045 #if PLATFORM(QT)
00046 #include "qglobal.h"
00047 QT_BEGIN_NAMESPACE
00048 class QPointF;
00049 QT_END_NAMESPACE
00050 #endif
00051
00052 #if PLATFORM(SYMBIAN)
00053 class TPoint;
00054 #endif
00055
00056 namespace WebCore {
00057
00058 class AffineTransform;
00059 class IntPoint;
00060
00061 class FloatPoint {
00062 public:
00063 FloatPoint() : m_x(0), m_y(0) { }
00064 FloatPoint(float x, float y) : m_x(x), m_y(y) { }
00065 FloatPoint(const IntPoint&);
00066
00067 static FloatPoint narrowPrecision(double x, double y);
00068
00069 float x() const { return m_x; }
00070 float y() const { return m_y; }
00071
00072 void setX(float x) { m_x = x; }
00073 void setY(float y) { m_y = y; }
00074 void move(float dx, float dy) { m_x += dx; m_y += dy; }
00075
00076 #if PLATFORM(CG)
00077 FloatPoint(const CGPoint&);
00078 operator CGPoint() const;
00079 #endif
00080
00081 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00082 FloatPoint(const NSPoint&);
00083 operator NSPoint() const;
00084 #endif
00085
00086 #if PLATFORM(QT)
00087 FloatPoint(const QPointF&);
00088 operator QPointF() const;
00089 #endif
00090
00091 #if PLATFORM(SYMBIAN)
00092 operator TPoint() const;
00093 FloatPoint(const TPoint& );
00094 #endif
00095
00096 FloatPoint matrixTransform(const AffineTransform&) const;
00097
00098 private:
00099 float m_x, m_y;
00100 };
00101
00102
00103 inline FloatPoint& operator+=(FloatPoint& a, const FloatSize& b)
00104 {
00105 a.move(b.width(), b.height());
00106 return a;
00107 }
00108
00109 inline FloatPoint& operator-=(FloatPoint& a, const FloatSize& b)
00110 {
00111 a.move(-b.width(), -b.height());
00112 return a;
00113 }
00114
00115 inline FloatPoint operator+(const FloatPoint& a, const FloatSize& b)
00116 {
00117 return FloatPoint(a.x() + b.width(), a.y() + b.height());
00118 }
00119
00120 inline FloatSize operator-(const FloatPoint& a, const FloatPoint& b)
00121 {
00122 return FloatSize(a.x() - b.x(), a.y() - b.y());
00123 }
00124
00125 inline FloatPoint operator-(const FloatPoint& a, const FloatSize& b)
00126 {
00127 return FloatPoint(a.x() - b.width(), a.y() - b.height());
00128 }
00129
00130 inline bool operator==(const FloatPoint& a, const FloatPoint& b)
00131 {
00132 return a.x() == b.x() && a.y() == b.y();
00133 }
00134
00135 inline bool operator!=(const FloatPoint& a, const FloatPoint& b)
00136 {
00137 return a.x() != b.x() || a.y() != b.y();
00138 }
00139
00140 }
00141
00142 #endif