]>
git.saurik.com Git - iphone-api.git/blob - WebCore/IntPoint.h
2 * Copyright (C) 2004, 2005, 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.
30 #include <wtf/Platform.h>
33 typedef struct CGPoint CGPoint
;
38 typedef struct tagPOINT POINT
;
39 typedef struct tagPOINTS POINTS
;
45 typedef struct _GdkPoint GdkPoint
;
64 IntPoint() : m_x(0), m_y(0) { }
65 IntPoint(int x
, int y
) : m_x(x
), m_y(y
) { }
67 int x() const { return m_x
; }
68 int y() const { return m_y
; }
70 void setX(int x
) { m_x
= x
; }
71 void setY(int y
) { m_y
= y
; }
73 void move(int dx
, int dy
) { m_x
+= dx
; m_y
+= dy
; }
75 IntPoint
expandedTo(const IntPoint
& other
) const
77 return IntPoint(m_x
> other
.m_x
? m_x
: other
.m_x
,
78 m_y
> other
.m_y
? m_y
: other
.m_y
);
81 IntPoint
shrunkTo(const IntPoint
& other
) const
83 return IntPoint(m_x
< other
.m_x
? m_x
: other
.m_x
,
84 m_y
< other
.m_y
? m_y
: other
.m_y
);
87 void clampNegativeToZero()
89 *this = expandedTo(IntPoint());
93 explicit IntPoint(const CGPoint
&); // don't do this implicitly since it's lossy
94 operator CGPoint() const;
99 IntPoint(const POINT
&);
100 operator POINT() const;
101 IntPoint(const POINTS
&);
102 operator POINTS() const;
104 IntPoint(const QPoint
&);
105 operator QPoint() const;
107 IntPoint(const GdkPoint
&);
108 operator GdkPoint() const;
110 #if PLATFORM(SYMBIAN)
111 IntPoint(const TPoint
&);
112 operator TPoint() const;
116 IntPoint(const wxPoint
&);
117 operator wxPoint() const;
121 IntPoint(const SkIPoint
&);
122 operator SkIPoint() const;
123 operator SkPoint() const;
130 inline IntPoint
& operator+=(IntPoint
& a
, const IntSize
& b
)
132 a
.move(b
.width(), b
.height());
136 inline IntPoint
& operator-=(IntPoint
& a
, const IntSize
& b
)
138 a
.move(-b
.width(), -b
.height());
142 inline IntPoint
operator+(const IntPoint
& a
, const IntSize
& b
)
144 return IntPoint(a
.x() + b
.width(), a
.y() + b
.height());
147 inline IntSize
operator-(const IntPoint
& a
, const IntPoint
& b
)
149 return IntSize(a
.x() - b
.x(), a
.y() - b
.y());
152 inline IntPoint
operator-(const IntPoint
& a
, const IntSize
& b
)
154 return IntPoint(a
.x() - b
.width(), a
.y() - b
.height());
157 inline bool operator==(const IntPoint
& a
, const IntPoint
& b
)
159 return a
.x() == b
.x() && a
.y() == b
.y();
162 inline bool operator!=(const IntPoint
& a
, const IntPoint
& b
)
164 return a
.x() != b
.x() || a
.y() != b
.y();
167 } // namespace WebCore