• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KHTML

IntRect.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003, 2006 Apple Computer, Inc.  All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  * 1. Redistributions of source code must retain the above copyright
00008  *    notice, this list of conditions and the following disclaimer.
00009  * 2. Redistributions in binary form must reproduce the above copyright
00010  *    notice, this list of conditions and the following disclaimer in the
00011  *    documentation and/or other materials provided with the distribution.
00012  *
00013  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
00014  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00015  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00016  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
00017  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00018  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00019  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00020  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00021  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00023  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00024  */
00025 
00026 #include "config.h"
00027 #include "IntRect.h"
00028 
00029 #include "FloatRect.h"
00030 #include <algorithm>
00031 
00032 using std::max;
00033 using std::min;
00034 
00035 namespace WebCore {
00036 
00037 IntRect::IntRect(const FloatRect& r)
00038     : m_location(IntPoint(static_cast<int>(r.x()), static_cast<int>(r.y())))
00039     , m_size(IntSize(static_cast<int>(r.width()), static_cast<int>(r.height())))
00040 {
00041 }
00042 
00043 bool IntRect::intersects(const IntRect& other) const
00044 {
00045     // Checking emptiness handles negative widths as well as zero.
00046     return !isEmpty() && !other.isEmpty()
00047         && x() < other.right() && other.x() < right()
00048         && y() < other.bottom() && other.y() < bottom();
00049 }
00050 
00051 bool IntRect::contains(const IntRect& other) const
00052 {
00053     return x() <= other.x() && right() >= other.right()
00054         && y() <= other.y() && bottom() >= other.bottom();
00055 }
00056 
00057 void IntRect::intersect(const IntRect& other)
00058 {
00059     int l = max(x(), other.x());
00060     int t = max(y(), other.y());
00061     int r = min(right(), other.right());
00062     int b = min(bottom(), other.bottom());
00063 
00064     // Return a clean empty rectangle for non-intersecting cases.
00065     if (l >= r || t >= b) {
00066         l = 0;
00067         t = 0;
00068         r = 0;
00069         b = 0;
00070     }
00071 
00072     m_location.setX(l);
00073     m_location.setY(t);
00074     m_size.setWidth(r - l);
00075     m_size.setHeight(b - t);
00076 }
00077 
00078 void IntRect::unite(const IntRect& other)
00079 {
00080     // Handle empty special cases first.
00081     if (other.isEmpty())
00082         return;
00083     if (isEmpty()) {
00084         *this = other;
00085         return;
00086     }
00087 
00088     int l = min(x(), other.x());
00089     int t = min(y(), other.y());
00090     int r = max(right(), other.right());
00091     int b = max(bottom(), other.bottom());
00092 
00093     m_location.setX(l);
00094     m_location.setY(t);
00095     m_size.setWidth(r - l);
00096     m_size.setHeight(b - t);
00097 }
00098 
00099 void IntRect::scale(float s)
00100 {
00101     m_location.setX((int)(x() * s));
00102     m_location.setY((int)(y() * s));
00103     m_size.setWidth((int)(width() * s));
00104     m_size.setHeight((int)(height() * s));
00105 }
00106 
00107 }

KHTML

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal