]>
git.saurik.com Git - iphone-api.git/blob - WebCore/FloatRect.h
2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2005 Nokia. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 #include "FloatPoint.h"
32 #include <CoreGraphics/CGGeometry.h>
35 typedef struct CGRect CGRect
;
50 #if PLATFORM(WX) && USE(WXGC)
65 FloatRect(const FloatPoint
& location
, const FloatSize
& size
)
66 : m_location(location
), m_size(size
) { }
67 FloatRect(float x
, float y
, float width
, float height
)
68 : m_location(FloatPoint(x
, y
)), m_size(FloatSize(width
, height
)) { }
69 FloatRect(const IntRect
&);
71 static FloatRect
narrowPrecision(double x
, double y
, double width
, double height
);
73 FloatPoint
location() const { return m_location
; }
74 FloatSize
size() const { return m_size
; }
76 void setLocation(const FloatPoint
& location
) { m_location
= location
; }
77 void setSize(const FloatSize
& size
) { m_size
= size
; }
79 float x() const { return m_location
.x(); }
80 float y() const { return m_location
.y(); }
81 float width() const { return m_size
.width(); }
82 float height() const { return m_size
.height(); }
84 void setX(float x
) { m_location
.setX(x
); }
85 void setY(float y
) { m_location
.setY(y
); }
86 void setWidth(float width
) { m_size
.setWidth(width
); }
87 void setHeight(float height
) { m_size
.setHeight(height
); }
89 bool isEmpty() const { return m_size
.isEmpty(); }
91 float right() const { return x() + width(); }
92 float bottom() const { return y() + height(); }
94 void move(const FloatSize
& delta
) { m_location
+= delta
; }
95 void move(float dx
, float dy
) { m_location
.move(dx
, dy
); }
97 bool intersects(const FloatRect
&) const;
98 bool contains(const FloatRect
&) const;
100 void intersect(const FloatRect
&);
101 void unite(const FloatRect
&);
103 // Note, this doesn't match what IntRect::contains(IntPoint&) does; the int version
104 // is really checking for containment of 1x1 rect, but that doesn't make sense with floats.
105 bool contains(float px
, float py
) const
106 { return px
>= x() && px
<= right() && py
>= y() && py
<= bottom(); }
107 bool contains(const FloatPoint
& point
) const { return contains(point
.x(), point
.y()); }
110 void inflateX(float dx
) {
111 m_location
.setX(m_location
.x() - dx
);
112 m_size
.setWidth(m_size
.width() + dx
+ dx
);
114 void inflateY(float dy
) {
115 m_location
.setY(m_location
.y() - dy
);
116 m_size
.setHeight(m_size
.height() + dy
+ dy
);
118 void inflate(float d
) { inflateX(d
); inflateY(d
); }
122 FloatRect(const CGRect
&);
123 operator CGRect() const;
128 FloatRect(const QRectF
&);
129 operator QRectF() const;
131 #if PLATFORM(SYMBIAN)
132 FloatRect(const TRect
&);
133 operator TRect() const;
137 #if PLATFORM(WX) && USE(WXGC)
138 FloatRect(const wxRect2DDouble
&);
139 operator wxRect2DDouble() const;
143 FloatRect(const SkRect
&);
144 operator SkRect() const;
148 FloatPoint m_location
;
152 inline FloatRect
intersection(const FloatRect
& a
, const FloatRect
& b
)
159 inline FloatRect
unionRect(const FloatRect
& a
, const FloatRect
& b
)
167 inline bool operator==(const FloatRect
& a
, const FloatRect
& b
)
169 return a
.location() == b
.location() && a
.size() == b
.size();
172 inline bool operator!=(const FloatRect
& a
, const FloatRect
& b
)
174 return a
.location() != b
.location() || a
.size() != b
.size();
177 IntRect
enclosingIntRect(const FloatRect
&);
179 // Map rect r from srcRect to an equivalent rect in destRect.
180 FloatRect
mapRect(const FloatRect
& r
, const FloatRect
& srcRect
, const FloatRect
& destRect
);