tagging audio streams and changing audio sink to pulseaudio
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / FloatPoint.h
1 /*
2  * Copyright (C) 2004, 2006, 2007 Apple Inc.  All rights reserved.
3  * Copyright (C) 2005 Nokia.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #ifndef FloatPoint_h
28 #define FloatPoint_h
29
30 #include "FloatSize.h"
31 #include "IntPoint.h"
32 #include <wtf/MathExtras.h>
33
34 #if PLATFORM(BLACKBERRY)
35 namespace BlackBerry {
36 namespace Platform {
37 class FloatPoint;
38 }
39 }
40 #endif
41
42 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
43 typedef struct CGPoint CGPoint;
44 #endif
45
46 #if PLATFORM(MAC) || (PLATFORM(CHROMIUM) && OS(DARWIN))
47 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
48 typedef struct CGPoint NSPoint;
49 #else
50 typedef struct _NSPoint NSPoint;
51 #endif
52 #endif
53
54 #if PLATFORM(QT)
55 #include "qglobal.h"
56 QT_BEGIN_NAMESPACE
57 class QPointF;
58 QT_END_NAMESPACE
59 #endif
60
61 #if USE(SKIA)
62 struct SkPoint;
63 #endif
64
65 namespace WebCore {
66
67 class AffineTransform;
68 class TransformationMatrix;
69 class IntPoint;
70 class IntSize;
71 class FractionalLayoutPoint;
72 class FractionalLayoutSize;
73
74 class FloatPoint {
75 public:
76     FloatPoint() : m_x(0), m_y(0) { }
77     FloatPoint(float x, float y) : m_x(x), m_y(y) { }
78     FloatPoint(const IntPoint&);
79     FloatPoint(const FractionalLayoutPoint&);
80
81     static FloatPoint zero() { return FloatPoint(); }
82
83     static FloatPoint narrowPrecision(double x, double y);
84
85     float x() const { return m_x; }
86     float y() const { return m_y; }
87
88     void setX(float x) { m_x = x; }
89     void setY(float y) { m_y = y; }
90     void set(float x, float y)
91     {
92         m_x = x;
93         m_y = y;
94     }
95     void move(float dx, float dy)
96     {
97         m_x += dx;
98         m_y += dy;
99     }
100     void move(const IntSize& a)
101     {
102         m_x += a.width();
103         m_y += a.height();
104     }
105     void move(const FractionalLayoutSize&);
106     void move(const FloatSize& a)
107     {
108         m_x += a.width();
109         m_y += a.height();
110     }
111     void moveBy(const IntPoint& a)
112     {
113         m_x += a.x();
114         m_y += a.y();
115     }
116     void moveBy(const FractionalLayoutPoint&);
117     void moveBy(const FloatPoint& a)
118     {
119         m_x += a.x();
120         m_y += a.y();
121     }
122     void scale(float sx, float sy)
123     {
124         m_x *= sx;
125         m_y *= sy;
126     }
127
128     void normalize();
129
130     float dot(const FloatPoint& a) const
131     {
132         return m_x * a.x() + m_y * a.y();
133     }
134
135     float length() const;
136     float lengthSquared() const
137     {
138         return m_x * m_x + m_y * m_y;
139     }
140
141     FloatPoint expandedTo(const FloatPoint& other) const
142     {
143         return FloatPoint(std::max(m_x, other.m_x), std::max(m_y, other.m_y));
144     }
145
146     FloatPoint transposedPoint() const
147     {
148         return FloatPoint(m_y, m_x);
149     }
150
151 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
152     FloatPoint(const CGPoint&);
153     operator CGPoint() const;
154 #endif
155
156 #if (PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)) \
157         || (PLATFORM(CHROMIUM) && OS(DARWIN))
158     FloatPoint(const NSPoint&);
159     operator NSPoint() const;
160 #endif
161
162 #if PLATFORM(QT)
163     FloatPoint(const QPointF&);
164     operator QPointF() const;
165 #endif
166
167 #if PLATFORM(BLACKBERRY)
168     FloatPoint(const BlackBerry::Platform::FloatPoint&);
169     operator BlackBerry::Platform::FloatPoint() const;
170 #endif
171
172 #if USE(SKIA)
173     operator SkPoint() const;
174     FloatPoint(const SkPoint&);
175 #endif
176
177     FloatPoint matrixTransform(const TransformationMatrix&) const;
178     FloatPoint matrixTransform(const AffineTransform&) const;
179
180 private:
181     float m_x, m_y;
182 };
183
184
185 inline FloatPoint& operator+=(FloatPoint& a, const FloatSize& b)
186 {
187     a.move(b.width(), b.height());
188     return a;
189 }
190
191 inline FloatPoint& operator+=(FloatPoint& a, const FloatPoint& b)
192 {
193     a.move(b.x(), b.y());
194     return a;
195 }
196
197 inline FloatPoint& operator-=(FloatPoint& a, const FloatSize& b)
198 {
199     a.move(-b.width(), -b.height());
200     return a;
201 }
202
203 inline FloatPoint operator+(const FloatPoint& a, const FloatSize& b)
204 {
205     return FloatPoint(a.x() + b.width(), a.y() + b.height());
206 }
207
208 inline FloatPoint operator+(const FloatPoint& a, const FloatPoint& b)
209 {
210     return FloatPoint(a.x() + b.x(), a.y() + b.y());
211 }
212
213 inline FloatSize operator-(const FloatPoint& a, const FloatPoint& b)
214 {
215     return FloatSize(a.x() - b.x(), a.y() - b.y());
216 }
217
218 inline FloatPoint operator-(const FloatPoint& a, const FloatSize& b)
219 {
220     return FloatPoint(a.x() - b.width(), a.y() - b.height());
221 }
222
223 inline FloatPoint operator-(const FloatPoint& a)
224 {
225     return FloatPoint(-a.x(), -a.y());
226 }
227
228 inline bool operator==(const FloatPoint& a, const FloatPoint& b)
229 {
230     return a.x() == b.x() && a.y() == b.y();
231 }
232
233 inline bool operator!=(const FloatPoint& a, const FloatPoint& b)
234 {
235     return a.x() != b.x() || a.y() != b.y();
236 }
237
238 inline float operator*(const FloatPoint& a, const FloatPoint& b)
239 {
240     // dot product
241     return a.dot(b);
242 }
243
244 inline IntPoint roundedIntPoint(const FloatPoint& p)
245 {
246     return IntPoint(static_cast<int>(roundf(p.x())), static_cast<int>(roundf(p.y())));
247 }
248
249 inline IntPoint flooredIntPoint(const FloatPoint& p)
250 {
251     return IntPoint(static_cast<int>(p.x()), static_cast<int>(p.y()));
252 }
253
254 inline IntSize flooredIntSize(const FloatPoint& p)
255 {
256     return IntSize(static_cast<int>(p.x()), static_cast<int>(p.y()));
257 }
258
259 float findSlope(const FloatPoint& p1, const FloatPoint& p2, float& c);
260
261 // Find point where lines through the two pairs of points intersect. Returns false if the lines don't intersect.
262 bool findIntersection(const FloatPoint& p1, const FloatPoint& p2, const FloatPoint& d1, const FloatPoint& d2, FloatPoint& intersection);
263
264 }
265
266 #endif