Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _BGFX_TUPLE_B2ITUPLE_HXX
30 : : #define _BGFX_TUPLE_B2ITUPLE_HXX
31 : :
32 : : #include <sal/types.h>
33 : : #include <basegfx/basegfxdllapi.h>
34 : :
35 : : namespace basegfx
36 : : {
37 : : /** Base class for all Points/Vectors with two sal_Int32 values
38 : :
39 : : This class provides all methods common to Point
40 : : avd Vector classes which are derived from here.
41 : :
42 : : @derive Use this class to implement Points or Vectors
43 : : which are based on two sal_Int32 values
44 : : */
45 : : class BASEGFX_DLLPUBLIC B2ITuple
46 : : {
47 : : protected:
48 : : sal_Int32 mnX;
49 : : sal_Int32 mnY;
50 : :
51 : : public:
52 : : /** Create a 2D Tuple
53 : :
54 : : The tuple is initialized to (0, 0)
55 : : */
56 : 0 : B2ITuple()
57 : : : mnX(0),
58 : 0 : mnY(0)
59 : 0 : {}
60 : :
61 : : /** Create a 2D Tuple
62 : :
63 : : @param fX
64 : : This parameter is used to initialize the X-coordinate
65 : : of the 2D Tuple.
66 : :
67 : : @param fY
68 : : This parameter is used to initialize the Y-coordinate
69 : : of the 2D Tuple.
70 : : */
71 : 86031705 : B2ITuple(sal_Int32 fX, sal_Int32 fY)
72 : : : mnX( fX ),
73 : 86031705 : mnY( fY )
74 : 86031705 : {}
75 : :
76 : : /** Create a copy of a 2D Tuple
77 : :
78 : : @param rTup
79 : : The 2D Tuple which will be copied.
80 : : */
81 : 19212221 : B2ITuple(const B2ITuple& rTup)
82 : : : mnX( rTup.mnX ),
83 : 19212221 : mnY( rTup.mnY )
84 : 19212221 : {}
85 : :
86 : 124256725 : ~B2ITuple()
87 : 124256725 : {}
88 : :
89 : : /// Get X-Coordinate of 2D Tuple
90 : 157827388 : sal_Int32 getX() const
91 : : {
92 : 157827388 : return mnX;
93 : : }
94 : :
95 : : /// Get Y-Coordinate of 2D Tuple
96 : 157506303 : sal_Int32 getY() const
97 : : {
98 : 157506303 : return mnY;
99 : : }
100 : :
101 : : /// Set X-Coordinate of 2D Tuple
102 : 38 : void setX(sal_Int32 fX)
103 : : {
104 : 38 : mnX = fX;
105 : 38 : }
106 : :
107 : : /// Set Y-Coordinate of 2D Tuple
108 : 38 : void setY(sal_Int32 fY)
109 : : {
110 : 38 : mnY = fY;
111 : 38 : }
112 : :
113 : : /// Array-access to 2D Tuple
114 : : const sal_Int32& operator[] (int nPos) const
115 : : {
116 : : // Here, normally one if(...) should be used. In the assumption that
117 : : // both sal_Int32 members can be accessed as an array a shortcut is used here.
118 : : // if(0 == nPos) return mnX; return mnY;
119 : : return *((&mnX) + nPos);
120 : : }
121 : :
122 : : /// Array-access to 2D Tuple
123 : : sal_Int32& operator[] (int nPos)
124 : : {
125 : : // Here, normally one if(...) should be used. In the assumption that
126 : : // both sal_Int32 members can be accessed as an array a shortcut is used here.
127 : : // if(0 == nPos) return mnX; return mnY;
128 : : return *((&mnX) + nPos);
129 : : }
130 : :
131 : : // operators
132 : : //////////////////////////////////////////////////////////////////////
133 : :
134 : 1938794 : B2ITuple& operator+=( const B2ITuple& rTup )
135 : : {
136 : 1938794 : mnX += rTup.mnX;
137 : 1938794 : mnY += rTup.mnY;
138 : 1938794 : return *this;
139 : : }
140 : :
141 : : B2ITuple& operator-=( const B2ITuple& rTup )
142 : : {
143 : : mnX -= rTup.mnX;
144 : : mnY -= rTup.mnY;
145 : : return *this;
146 : : }
147 : :
148 : : B2ITuple& operator/=( const B2ITuple& rTup )
149 : : {
150 : : mnX /= rTup.mnX;
151 : : mnY /= rTup.mnY;
152 : : return *this;
153 : : }
154 : :
155 : : B2ITuple& operator*=( const B2ITuple& rTup )
156 : : {
157 : : mnX *= rTup.mnX;
158 : : mnY *= rTup.mnY;
159 : : return *this;
160 : : }
161 : :
162 : : B2ITuple& operator*=(sal_Int32 t)
163 : : {
164 : : mnX *= t;
165 : : mnY *= t;
166 : : return *this;
167 : : }
168 : :
169 : : B2ITuple& operator/=(sal_Int32 t)
170 : : {
171 : : mnX /= t;
172 : : mnY /= t;
173 : : return *this;
174 : : }
175 : :
176 : : B2ITuple operator-(void) const
177 : : {
178 : : return B2ITuple(-mnX, -mnY);
179 : : }
180 : :
181 : : bool equalZero() const { return mnX == 0 && mnY == 0; }
182 : :
183 : 266578 : bool operator==( const B2ITuple& rTup ) const
184 : : {
185 [ + - ][ + + ]: 266578 : return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY);
[ + + ]
186 : : }
187 : :
188 : 266558 : bool operator!=( const B2ITuple& rTup ) const
189 : : {
190 : 266558 : return !(*this == rTup);
191 : : }
192 : :
193 : 1625938 : B2ITuple& operator=( const B2ITuple& rTup )
194 : : {
195 : 1625938 : mnX = rTup.mnX;
196 : 1625938 : mnY = rTup.mnY;
197 : 1625938 : return *this;
198 : : }
199 : : };
200 : :
201 : : // external operators
202 : : //////////////////////////////////////////////////////////////////////////
203 : : class B2DTuple;
204 : :
205 : : BASEGFX_DLLPUBLIC B2ITuple operator+(const B2ITuple& rTupA, const B2ITuple& rTupB);
206 : : BASEGFX_DLLPUBLIC B2ITuple operator-(const B2ITuple& rTupA, const B2ITuple& rTupB);
207 : : BASEGFX_DLLPUBLIC B2ITuple operator/(const B2ITuple& rTupA, const B2ITuple& rTupB);
208 : : BASEGFX_DLLPUBLIC B2ITuple operator*(const B2ITuple& rTupA, const B2ITuple& rTupB);
209 : : BASEGFX_DLLPUBLIC B2ITuple operator*(const B2ITuple& rTup, sal_Int32 t);
210 : : BASEGFX_DLLPUBLIC B2ITuple operator*(sal_Int32 t, const B2ITuple& rTup);
211 : : BASEGFX_DLLPUBLIC B2ITuple operator/(const B2ITuple& rTup, sal_Int32 t);
212 : : BASEGFX_DLLPUBLIC B2ITuple operator/(sal_Int32 t, const B2ITuple& rTup);
213 : : } // end of namespace basegfx
214 : :
215 : : #endif /* _BGFX_TUPLE_B2ITUPLE_HXX */
216 : :
217 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|