1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_BASEGFX_TUPLE_B2ITUPLE_HXX
21 #define INCLUDED_BASEGFX_TUPLE_B2ITUPLE_HXX
23 #include <sal/types.h>
24 #include <basegfx/numeric/ftools.hxx>
26 #include <basegfx/basegfxdllapi.h>
30 /** Base class for all Points/Vectors with two sal_Int32 values
32 This class provides all methods common to Point
33 avd Vector classes which are derived from here.
35 @derive Use this class to implement Points or Vectors
36 which are based on two sal_Int32 values
38 class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2ITuple
47 The tuple is initialized to (0, 0)
57 This parameter is used to initialize the X-coordinate
61 This parameter is used to initialize the Y-coordinate
64 B2ITuple(sal_Int32 fX
, sal_Int32 fY
)
69 /// Get X-Coordinate of 2D Tuple
70 sal_Int32
getX() const
75 /// Get Y-Coordinate of 2D Tuple
76 sal_Int32
getY() const
81 /// Set X-Coordinate of 2D Tuple
82 void setX(sal_Int32 fX
)
87 /// Set Y-Coordinate of 2D Tuple
88 void setY(sal_Int32 fY
)
93 /// Array-access to 2D Tuple
94 const sal_Int32
& operator[] (int nPos
) const
96 // Here, normally one if(...) should be used. In the assumption that
97 // both sal_Int32 members can be accessed as an array a shortcut is used here.
98 // if(0 == nPos) return mnX; return mnY;
99 return *((&mnX
) + nPos
);
102 /// Array-access to 2D Tuple
103 sal_Int32
& operator[] (int nPos
)
105 // Here, normally one if(...) should be used. In the assumption that
106 // both sal_Int32 members can be accessed as an array a shortcut is used here.
107 // if(0 == nPos) return mnX; return mnY;
108 return *((&mnX
) + nPos
);
114 B2ITuple
& operator+=( const B2ITuple
& rTup
)
121 B2ITuple
& operator-=( const B2ITuple
& rTup
)
128 B2ITuple
& operator/=( const B2ITuple
& rTup
)
135 B2ITuple
& operator*=( const B2ITuple
& rTup
)
142 B2ITuple
& operator*=(sal_Int32 t
)
149 B2ITuple
& operator/=(sal_Int32 t
)
156 B2ITuple
operator-(void) const
158 return B2ITuple(-mnX
, -mnY
);
161 bool equalZero() const
163 return mnX
== 0 && mnY
== 0;
166 bool operator==( const B2ITuple
& rTup
) const
168 return this == &rTup
|| (rTup
.mnX
== mnX
&& rTup
.mnY
== mnY
);
171 bool operator!=( const B2ITuple
& rTup
) const
173 return !(*this == rTup
);
177 // external operators
180 inline B2ITuple
operator+(const B2ITuple
& rTupA
, const B2ITuple
& rTupB
)
182 B2ITuple
aSum(rTupA
);
187 inline B2ITuple
operator-(const B2ITuple
& rTupA
, const B2ITuple
& rTupB
)
189 B2ITuple
aSub(rTupA
);
194 inline B2ITuple
operator*(sal_Int32 t
, const B2ITuple
& rTup
)
201 } // end of namespace basegfx
203 #endif // INCLUDED_BASEGFX_TUPLE_B2ITUPLE_HXX
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */