2 * Copyright (C) 2003, 2006 Apple Computer, 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"
34 typedef struct CGRect CGRect;
36 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
37 typedef struct CGRect NSRect;
39 typedef struct _NSRect NSRect;
55 FloatRect(const FloatPoint& location, const FloatSize& size)
56 : m_location(location), m_size(size) { }
57 FloatRect(float x, float y, float width, float height)
58 : m_location(FloatPoint(x, y)), m_size(FloatSize(width, height)) { }
59 FloatRect(const IntRect&);
61 FloatPoint location() const { return m_location; }
62 FloatSize size() const { return m_size; }
64 void setLocation(const FloatPoint& location) { m_location = location; }
65 void setSize(const FloatSize& size) { m_size = size; }
67 float x() const { return m_location.x(); }
68 float y() const { return m_location.y(); }
69 float width() const { return m_size.width(); }
70 float height() const { return m_size.height(); }
72 void setX(float x) { m_location.setX(x); }
73 void setY(float y) { m_location.setY(y); }
74 void setWidth(float width) { m_size.setWidth(width); }
75 void setHeight(float height) { m_size.setHeight(height); }
77 bool isEmpty() const { return m_size.isEmpty(); }
79 float right() const { return x() + width(); }
80 float bottom() const { return y() + height(); }
82 void move(const FloatSize& delta) { m_location += delta; }
83 void move(float dx, float dy) { m_location.move(dx, dy); }
85 bool intersects(const FloatRect&) const;
86 bool contains(const FloatRect&) const;
88 void intersect(const FloatRect&);
89 void unite(const FloatRect&);
91 void inflateX(float dx) {
92 m_location.setX(m_location.x() - dx);
93 m_size.setWidth(m_size.width() + dx + dx);
95 void inflateY(float dy) {
96 m_location.setY(m_location.y() - dy);
97 m_size.setHeight(m_size.height() + dy + dy);
99 void inflate(float d) { inflateX(d); inflateY(d); }
104 FloatRect(const CGRect&);
105 operator CGRect() const;
107 #ifndef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
108 FloatRect(const NSRect&);
109 operator NSRect() const;
113 FloatRect(const QRectF&);
114 operator QRectF() const;
118 FloatPoint m_location;
122 inline FloatRect intersection(const FloatRect& a, const FloatRect& b)
129 inline FloatRect unionRect(const FloatRect& a, const FloatRect& b)
136 inline bool operator==(const FloatRect& a, const FloatRect& b)
138 return a.location() == b.location() && a.size() == b.size();
141 inline bool operator!=(const FloatRect& a, const FloatRect& b)
143 return a.location() != b.location() || a.size() != b.size();
146 IntRect enclosingIntRect(const FloatRect&);