Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef _BGFX_TUPLE_B2ITUPLE_HXX
21 : #define _BGFX_TUPLE_B2ITUPLE_HXX
22 :
23 : #include <sal/types.h>
24 : #include <basegfx/basegfxdllapi.h>
25 :
26 : namespace basegfx
27 : {
28 : /** Base class for all Points/Vectors with two sal_Int32 values
29 :
30 : This class provides all methods common to Point
31 : avd Vector classes which are derived from here.
32 :
33 : @derive Use this class to implement Points or Vectors
34 : which are based on two sal_Int32 values
35 : */
36 : class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED B2ITuple
37 : {
38 : protected:
39 : sal_Int32 mnX;
40 : sal_Int32 mnY;
41 :
42 : public:
43 : /** Create a 2D Tuple
44 :
45 : The tuple is initialized to (0, 0)
46 : */
47 0 : B2ITuple()
48 : : mnX(0),
49 0 : mnY(0)
50 0 : {}
51 :
52 : /** Create a 2D Tuple
53 :
54 : @param fX
55 : This parameter is used to initialize the X-coordinate
56 : of the 2D Tuple.
57 :
58 : @param fY
59 : This parameter is used to initialize the Y-coordinate
60 : of the 2D Tuple.
61 : */
62 750368 : B2ITuple(sal_Int32 fX, sal_Int32 fY)
63 : : mnX( fX ),
64 750368 : mnY( fY )
65 750368 : {}
66 :
67 : /** Create a copy of a 2D Tuple
68 :
69 : @param rTup
70 : The 2D Tuple which will be copied.
71 : */
72 348547 : B2ITuple(const B2ITuple& rTup)
73 : : mnX( rTup.mnX ),
74 348547 : mnY( rTup.mnY )
75 348547 : {}
76 :
77 1259901 : ~B2ITuple()
78 1259901 : {}
79 :
80 : /// Get X-Coordinate of 2D Tuple
81 1792654 : sal_Int32 getX() const
82 : {
83 1792654 : return mnX;
84 : }
85 :
86 : /// Get Y-Coordinate of 2D Tuple
87 1771294 : sal_Int32 getY() const
88 : {
89 1771294 : return mnY;
90 : }
91 :
92 : /// Set X-Coordinate of 2D Tuple
93 0 : void setX(sal_Int32 fX)
94 : {
95 0 : mnX = fX;
96 0 : }
97 :
98 : /// Set Y-Coordinate of 2D Tuple
99 0 : void setY(sal_Int32 fY)
100 : {
101 0 : mnY = fY;
102 0 : }
103 :
104 : /// Array-access to 2D Tuple
105 : const sal_Int32& operator[] (int nPos) const
106 : {
107 : // Here, normally one if(...) should be used. In the assumption that
108 : // both sal_Int32 members can be accessed as an array a shortcut is used here.
109 : // if(0 == nPos) return mnX; return mnY;
110 : return *((&mnX) + nPos);
111 : }
112 :
113 : /// Array-access to 2D Tuple
114 : sal_Int32& operator[] (int nPos)
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 : // operators
123 : //////////////////////////////////////////////////////////////////////
124 :
125 16890 : B2ITuple& operator+=( const B2ITuple& rTup )
126 : {
127 16890 : mnX += rTup.mnX;
128 16890 : mnY += rTup.mnY;
129 16890 : return *this;
130 : }
131 :
132 : B2ITuple& operator-=( const B2ITuple& rTup )
133 : {
134 : mnX -= rTup.mnX;
135 : mnY -= rTup.mnY;
136 : return *this;
137 : }
138 :
139 : B2ITuple& operator/=( const B2ITuple& rTup )
140 : {
141 : mnX /= rTup.mnX;
142 : mnY /= rTup.mnY;
143 : return *this;
144 : }
145 :
146 : B2ITuple& operator*=( const B2ITuple& rTup )
147 : {
148 : mnX *= rTup.mnX;
149 : mnY *= rTup.mnY;
150 : return *this;
151 : }
152 :
153 : B2ITuple& operator*=(sal_Int32 t)
154 : {
155 : mnX *= t;
156 : mnY *= t;
157 : return *this;
158 : }
159 :
160 : B2ITuple& operator/=(sal_Int32 t)
161 : {
162 : mnX /= t;
163 : mnY /= t;
164 : return *this;
165 : }
166 :
167 : B2ITuple operator-(void) const
168 : {
169 : return B2ITuple(-mnX, -mnY);
170 : }
171 :
172 : bool equalZero() const { return mnX == 0 && mnY == 0; }
173 :
174 1060 : bool operator==( const B2ITuple& rTup ) const
175 : {
176 1060 : return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY);
177 : }
178 :
179 1056 : bool operator!=( const B2ITuple& rTup ) const
180 : {
181 1056 : return !(*this == rTup);
182 : }
183 :
184 16935 : B2ITuple& operator=( const B2ITuple& rTup )
185 : {
186 16935 : mnX = rTup.mnX;
187 16935 : mnY = rTup.mnY;
188 16935 : return *this;
189 : }
190 : };
191 :
192 : // external operators
193 : //////////////////////////////////////////////////////////////////////////
194 : class B2DTuple;
195 :
196 : BASEGFX_DLLPUBLIC B2ITuple operator+(const B2ITuple& rTupA, const B2ITuple& rTupB);
197 : BASEGFX_DLLPUBLIC B2ITuple operator-(const B2ITuple& rTupA, const B2ITuple& rTupB);
198 : BASEGFX_DLLPUBLIC B2ITuple operator/(const B2ITuple& rTupA, const B2ITuple& rTupB);
199 : BASEGFX_DLLPUBLIC B2ITuple operator*(const B2ITuple& rTupA, const B2ITuple& rTupB);
200 : BASEGFX_DLLPUBLIC B2ITuple operator*(const B2ITuple& rTup, sal_Int32 t);
201 : BASEGFX_DLLPUBLIC B2ITuple operator*(sal_Int32 t, const B2ITuple& rTup);
202 : BASEGFX_DLLPUBLIC B2ITuple operator/(const B2ITuple& rTup, sal_Int32 t);
203 : BASEGFX_DLLPUBLIC B2ITuple operator/(sal_Int32 t, const B2ITuple& rTup);
204 : } // end of namespace basegfx
205 :
206 : #endif /* _BGFX_TUPLE_B2ITUPLE_HXX */
207 :
208 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|