KHTML
FloatPoint.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. 00003 * Copyright (C) 2005 Nokia. All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 00015 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00016 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00017 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 00018 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00019 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00020 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00021 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00022 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00023 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00024 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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
KDE 4.6 API Reference