• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
  • platform
  • graphics
IntRect.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26#include "config.h"
27#include "IntRect.h"
28
29#include "FloatRect.h"
30#include <algorithm>
31
32using std::max;
33using std::min;
34
35namespace WebCore {
36
37IntRect::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())))
40{
41}
42
43bool IntRect::intersects(const IntRect& other) const
44{
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();
49}
50
51bool IntRect::contains(const IntRect& other) const
52{
53 return x() <= other.x() && right() >= other.right()
54 && y() <= other.y() && bottom() >= other.bottom();
55}
56
57void IntRect::intersect(const IntRect& other)
58{
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());
63
64 // Return a clean empty rectangle for non-intersecting cases.
65 if (l >= r || t >= b) {
66 l = 0;
67 t = 0;
68 r = 0;
69 b = 0;
70 }
71
72 m_location.setX(l);
73 m_location.setY(t);
74 m_size.setWidth(r - l);
75 m_size.setHeight(b - t);
76}
77
78void IntRect::unite(const IntRect& other)
79{
80 // Handle empty special cases first.
81 if (other.isEmpty())
82 return;
83 if (isEmpty()) {
84 *this = other;
85 return;
86 }
87
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());
92
93 m_location.setX(l);
94 m_location.setY(t);
95 m_size.setWidth(r - l);
96 m_size.setHeight(b - t);
97}
98
99void IntRect::scale(float s)
100{
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));
105}
106
107}
FloatRect.h
IntRect.h
WebCore::FloatRect
Definition: FloatRect.h:59
WebCore::IntPoint
Definition: IntPoint.h:64
WebCore::IntPoint::setX
void setX(int x)
Definition: IntPoint.h:72
WebCore::IntPoint::setY
void setY(int y)
Definition: IntPoint.h:73
WebCore::IntRect
Definition: IntRect.h:65
WebCore::IntRect::IntRect
IntRect()
Definition: IntRect.h:67
WebCore::IntRect::unite
void unite(const IntRect &)
Definition: IntRect.cpp:78
WebCore::IntRect::intersects
bool intersects(const IntRect &) const
Definition: IntRect.cpp:43
WebCore::IntRect::x
int x() const
Definition: IntRect.h:81
WebCore::IntRect::intersect
void intersect(const IntRect &)
Definition: IntRect.cpp:57
WebCore::IntRect::isEmpty
bool isEmpty() const
Definition: IntRect.h:98
WebCore::IntRect::scale
void scale(float s)
Definition: IntRect.cpp:99
WebCore::IntRect::y
int y() const
Definition: IntRect.h:82
WebCore::IntRect::height
int height() const
Definition: IntRect.h:84
WebCore::IntRect::contains
bool contains(const IntRect &) const
Definition: IntRect.cpp:51
WebCore::IntRect::bottom
int bottom() const
Definition: IntRect.h:101
WebCore::IntRect::right
int right() const
Definition: IntRect.h:100
WebCore::IntRect::width
int width() const
Definition: IntRect.h:83
WebCore::IntSize
Definition: IntSize.h:57
WebCore::IntSize::setHeight
void setHeight(int height)
Definition: IntSize.h:66
WebCore::IntSize::setWidth
void setWidth(int width)
Definition: IntSize.h:65
WebCore
Definition: CSSHelper.h:7
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal