pleyo.com

/src/trunk2/BAL/Interfaces/graphics/FloatRect.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003, 2006, 2007 Apple Inc.  All rights reserved.
00003  * Copyright (C) 2005 Nokia.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  *
00014  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
00015  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
00018  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025  */
00026 
00027 #ifndef FloatRect_h
00028 #define FloatRect_h
00029 
00030 #include "FloatPoint.h"
00031 
00032 #if PLATFORM(CG)
00033 typedef struct CGRect CGRect;
00034 #endif
00035 
00036 #if PLATFORM(MAC)
00037 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
00038 typedef struct CGRect NSRect;
00039 #else
00040 typedef struct _NSRect NSRect;
00041 #endif
00042 #endif
00043 
00044 #if PLATFORM(QT)
00045 class QRectF;
00046 #endif
00047 
00048 namespace WebCore {
00049 
00050 class IntRect;
00051 
00052 class FloatRect {
00053 public:
00054     FloatRect() { }
00055     FloatRect(const FloatPoint& location, const FloatSize& size)
00056         : m_location(location), m_size(size) { }
00057     FloatRect(float x, float y, float width, float height)
00058         : m_location(FloatPoint(x, y)), m_size(FloatSize(width, height)) { }
00059     FloatRect(const IntRect&);
00060 
00061     static FloatRect narrowPrecision(double x, double y, double width, double height);
00062 
00063     FloatPoint location() const { return m_location; }
00064     FloatSize size() const { return m_size; }
00065 
00066     void setLocation(const FloatPoint& location) { m_location = location; }
00067     void setSize(const FloatSize& size) { m_size = size; }
00068 
00069     float x() const { return m_location.x(); }
00070     float y() const { return m_location.y(); }
00071     float width() const { return m_size.width(); }
00072     float height() const { return m_size.height(); }
00073 
00074     void setX(float x) { m_location.setX(x); }
00075     void setY(float y) { m_location.setY(y); }
00076     void setWidth(float width) { m_size.setWidth(width); }
00077     void setHeight(float height) { m_size.setHeight(height); }
00078 
00079     bool isEmpty() const { return m_size.isEmpty(); }
00080 
00081     float right() const { return x() + width(); }
00082     float bottom() const { return y() + height(); }
00083 
00084     void move(const FloatSize& delta) { m_location += delta; } 
00085     void move(float dx, float dy) { m_location.move(dx, dy); } 
00086 
00087     bool intersects(const FloatRect&) const;
00088     bool contains(const FloatRect&) const;
00089 
00090     void intersect(const FloatRect&);
00091     void unite(const FloatRect&);
00092 
00093     // Note, this doesn't match what IntRect::contains(IntPoint&) does; the int version
00094     // is really checking for containment of 1x1 rect, but that doesn't make sense with floats.
00095     bool contains(float px, float py) const
00096         { return px >= x() && px <= right() && py >= y() && py <= bottom(); }
00097     bool contains(const FloatPoint& point) const { return contains(point.x(), point.y()); }
00098 
00099 
00100     void inflateX(float dx) {
00101         m_location.setX(m_location.x() - dx);
00102         m_size.setWidth(m_size.width() + dx + dx);
00103     }
00104     void inflateY(float dy) {
00105         m_location.setY(m_location.y() - dy);
00106         m_size.setHeight(m_size.height() + dy + dy);
00107     }
00108     void inflate(float d) { inflateX(d); inflateY(d); }
00109     void scale(float s);
00110 
00111 #if PLATFORM(CG)
00112     FloatRect(const CGRect&);
00113     operator CGRect() const;
00114 #endif
00115 
00116 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00117     FloatRect(const NSRect&);
00118     operator NSRect() const;
00119 #endif
00120 
00121 #if PLATFORM(QT)
00122     FloatRect(const QRectF&);
00123     operator QRectF() const;
00124 #endif
00125 #if PLATFORM(SYMBIAN)
00126     FloatRect(const TRect&);
00127     operator TRect() const;
00128     TRect rect() const;
00129 #endif
00130 
00131 private:
00132     FloatPoint m_location;
00133     FloatSize m_size;
00134 };
00135 
00136 inline FloatRect intersection(const FloatRect& a, const FloatRect& b)
00137 {
00138     FloatRect c = a;
00139     c.intersect(b);
00140     return c;
00141 }
00142 
00143 inline FloatRect unionRect(const FloatRect& a, const FloatRect& b)
00144 {
00145     FloatRect c = a;
00146     c.unite(b);
00147     return c;
00148 }
00149 
00150 inline bool operator==(const FloatRect& a, const FloatRect& b)
00151 {
00152     return a.location() == b.location() && a.size() == b.size();
00153 }
00154 
00155 inline bool operator!=(const FloatRect& a, const FloatRect& b)
00156 {
00157     return a.location() != b.location() || a.size() != b.size();
00158 }
00159 
00160 IntRect enclosingIntRect(const FloatRect&);
00161 
00162 }
00163 
00164 #endif

Generated on Wed Nov 21 20:04:17 2007 for Origyn Web Browser by Doxygen 1.5.3

pleyo.com
pleyo.com