KHtml

FloatRect.h
1 /*
2  * Copyright (C) 2003, 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 FloatRect_h
28 #define FloatRect_h
29 
30 #include "FloatPoint.h"
31 #include "IntRect.h"
32 
33 #if PLATFORM(CG)
34 typedef struct CGRect CGRect;
35 #endif
36 
37 #if PLATFORM(MAC)
38 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
39 typedef struct CGRect NSRect;
40 #else
41 typedef struct _NSRect NSRect;
42 #endif
43 #endif
44 
45 #if PLATFORM(QT)
46 QT_BEGIN_NAMESPACE
47 class QRectF;
48 QT_END_NAMESPACE
49 #endif
50 
51 #if PLATFORM(WX) && USE(WXGC)
52 class wxRect2DDouble;
53 #endif
54 
55 namespace WebCore
56 {
57 
58 class IntRect;
59 
60 class FloatRect
61 {
62 public:
63  FloatRect() { }
64  FloatRect(const FloatPoint &location, const FloatSize &size)
65  : m_location(location), m_size(size) { }
66  FloatRect(float x, float y, float width, float height)
67  : m_location(FloatPoint(x, y)), m_size(FloatSize(width, height)) { }
68  FloatRect(const IntRect &);
69 
70  static FloatRect narrowPrecision(double x, double y, double width, double height);
71 
72  FloatPoint location() const
73  {
74  return m_location;
75  }
76  FloatSize size() const
77  {
78  return m_size;
79  }
80 
81  void setLocation(const FloatPoint &location)
82  {
83  m_location = location;
84  }
85  void setSize(const FloatSize &size)
86  {
87  m_size = size;
88  }
89 
90  float x() const
91  {
92  return m_location.x();
93  }
94  float y() const
95  {
96  return m_location.y();
97  }
98  float width() const
99  {
100  return m_size.width();
101  }
102  float height() const
103  {
104  return m_size.height();
105  }
106 
107  void setX(float x)
108  {
109  m_location.setX(x);
110  }
111  void setY(float y)
112  {
113  m_location.setY(y);
114  }
115  void setWidth(float width)
116  {
117  m_size.setWidth(width);
118  }
119  void setHeight(float height)
120  {
121  m_size.setHeight(height);
122  }
123 
124  bool isEmpty() const
125  {
126  return m_size.isEmpty();
127  }
128 
129  float right() const
130  {
131  return x() + width();
132  }
133  float bottom() const
134  {
135  return y() + height();
136  }
137 
138  void move(const FloatSize &delta)
139  {
140  m_location += delta;
141  }
142  void move(float dx, float dy)
143  {
144  m_location.move(dx, dy);
145  }
146 
147  bool intersects(const FloatRect &) const;
148  bool contains(const FloatRect &) const;
149 
150  void intersect(const FloatRect &);
151  void unite(const FloatRect &);
152 
153  // Note, this doesn't match what IntRect::contains(IntPoint&) does; the int version
154  // is really checking for containment of 1x1 rect, but that doesn't make sense with floats.
155  bool contains(float px, float py) const
156  {
157  return px >= x() && px <= right() && py >= y() && py <= bottom();
158  }
159  bool contains(const FloatPoint &point) const
160  {
161  return contains(point.x(), point.y());
162  }
163 
164  void inflateX(float dx)
165  {
166  m_location.setX(m_location.x() - dx);
167  m_size.setWidth(m_size.width() + dx + dx);
168  }
169  void inflateY(float dy)
170  {
171  m_location.setY(m_location.y() - dy);
172  m_size.setHeight(m_size.height() + dy + dy);
173  }
174  void inflate(float d)
175  {
176  inflateX(d);
177  inflateY(d);
178  }
179  void scale(float s);
180 
181 #if PLATFORM(CG)
182  FloatRect(const CGRect &);
183  operator CGRect() const;
184 #endif
185 
186 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
187  FloatRect(const NSRect &);
188  operator NSRect() const;
189 #endif
190 
191 #if PLATFORM(QT)
192  FloatRect(const QRectF &);
193  operator QRectF() const;
194 #endif
195 #if PLATFORM(SYMBIAN)
196  FloatRect(const TRect &);
197  operator TRect() const;
198  TRect rect() const;
199 #endif
200 
201 #if PLATFORM(WX) && USE(WXGC)
202  FloatRect(const wxRect2DDouble &);
203  operator wxRect2DDouble() const;
204 #endif
205 
206 private:
207  FloatPoint m_location;
208  FloatSize m_size;
209 };
210 
211 inline FloatRect intersection(const FloatRect &a, const FloatRect &b)
212 {
213  FloatRect c = a;
214  c.intersect(b);
215  return c;
216 }
217 
218 inline FloatRect unionRect(const FloatRect &a, const FloatRect &b)
219 {
220  FloatRect c = a;
221  c.unite(b);
222  return c;
223 }
224 
225 inline bool operator==(const FloatRect &a, const FloatRect &b)
226 {
227  return a.location() == b.location() && a.size() == b.size();
228 }
229 
230 inline bool operator!=(const FloatRect &a, const FloatRect &b)
231 {
232  return a.location() != b.location() || a.size() != b.size();
233 }
234 
235 IntRect enclosingIntRect(const FloatRect &);
236 
237 }
238 
239 #endif
QTextStream & right(QTextStream &stream)
QVariant location(const QVariant &res)
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
KIOCORE_EXPORT CopyJob * move(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)
bool operator!=(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:47:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.