2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "FloatRect.h"
37 IntRect::IntRect(const FloatRect& r)
38 : m_location(IntPoint(static_cast<int>(r.x()), static_cast<int>(r.y())))
39 , m_size(IntSize(static_cast<int>(r.width()), static_cast<int>(r.height())))
43 bool IntRect::intersects(const IntRect& other) const
45 // Checking emptiness handles negative widths as well as zero.
46 return !isEmpty() && !other.isEmpty()
47 && x() < other.right() && other.x() < right()
48 && y() < other.bottom() && other.y() < bottom();
51 bool IntRect::contains(const IntRect& other) const
53 return x() <= other.x() && right() >= other.right()
54 && y() <= other.y() && bottom() >= other.bottom();
57 void IntRect::intersect(const IntRect& other)
59 int l = max(x(), other.x());
60 int t = max(y(), other.y());
61 int r = min(right(), other.right());
62 int b = min(bottom(), other.bottom());
64 // Return a clean empty rectangle for non-intersecting cases.
65 if (l >= r || t >= b) {
74 m_size.setWidth(r - l);
75 m_size.setHeight(b - t);
78 void IntRect::unite(const IntRect& other)
80 // Handle empty special cases first.
88 int l = min(x(), other.x());
89 int t = min(y(), other.y());
90 int r = max(right(), other.right());
91 int b = max(bottom(), other.bottom());
95 m_size.setWidth(r - l);
96 m_size.setHeight(b - t);
99 void IntRect::scale(float s)
101 m_location.setX((int)(x() * s));
102 m_location.setY((int)(y() * s));
103 m_size.setWidth((int)(width() * s));
104 m_size.setHeight((int)(height() * s));