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 _BGFX_TUPLE_B2I64TUPLE_HXX
21 #define _BGFX_TUPLE_B2I64TUPLE_HXX
23 #include <sal/types.h>
24 #include <basegfx/tuple/b2dtuple.hxx>
25 #include <basegfx/basegfxdllapi.h>
30 /** Base class for all Points/Vectors with two sal_Int64 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_Int64 values
38 class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED B2I64Tuple
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 B2I64Tuple(sal_Int64 fX
, sal_Int64 fY
)
69 /** Create a copy of a 2D Tuple
72 The 2D Tuple which will be copied.
74 B2I64Tuple(const B2I64Tuple
& rTup
)
82 /// Get X-Coordinate of 2D Tuple
83 sal_Int64
getX() const
88 /// Get Y-Coordinate of 2D Tuple
89 sal_Int64
getY() const
94 /// Set X-Coordinate of 2D Tuple
95 void setX(sal_Int64 fX
)
100 /// Set Y-Coordinate of 2D Tuple
101 void setY(sal_Int64 fY
)
106 /// Array-access to 2D Tuple
107 const sal_Int64
& operator[] (int nPos
) const
109 // Here, normally one if(...) should be used. In the assumption that
110 // both sal_Int64 members can be accessed as an array a shortcut is used here.
111 // if(0 == nPos) return mnX; return mnY;
112 return *((&mnX
) + nPos
);
115 /// Array-access to 2D Tuple
116 sal_Int64
& operator[] (int nPos
)
118 // Here, normally one if(...) should be used. In the assumption that
119 // both sal_Int64 members can be accessed as an array a shortcut is used here.
120 // if(0 == nPos) return mnX; return mnY;
121 return *((&mnX
) + nPos
);
125 //////////////////////////////////////////////////////////////////////
127 B2I64Tuple
& operator+=( const B2I64Tuple
& rTup
)
134 B2I64Tuple
& operator-=( const B2I64Tuple
& rTup
)
141 B2I64Tuple
& operator/=( const B2I64Tuple
& rTup
)
148 B2I64Tuple
& operator*=( const B2I64Tuple
& rTup
)
155 B2I64Tuple
& operator*=(sal_Int64 t
)
162 B2I64Tuple
& operator/=(sal_Int64 t
)
169 B2I64Tuple
operator-(void) const
171 return B2I64Tuple(-mnX
, -mnY
);
174 bool equalZero() const { return mnX
== 0 && mnY
== 0; }
176 bool operator==( const B2I64Tuple
& rTup
) const
178 return this == &rTup
|| (rTup
.mnX
== mnX
&& rTup
.mnY
== mnY
);
181 bool operator!=( const B2I64Tuple
& rTup
) const
183 return !(*this == rTup
);
186 B2I64Tuple
& operator=( const B2I64Tuple
& rTup
)
194 // external operators
195 //////////////////////////////////////////////////////////////////////////
197 inline B2I64Tuple
minimum(const B2I64Tuple
& rTupA
, const B2I64Tuple
& rTupB
)
200 (rTupB
.getX() < rTupA
.getX()) ? rTupB
.getX() : rTupA
.getX(),
201 (rTupB
.getY() < rTupA
.getY()) ? rTupB
.getY() : rTupA
.getY());
205 inline B2I64Tuple
maximum(const B2I64Tuple
& rTupA
, const B2I64Tuple
& rTupB
)
208 (rTupB
.getX() > rTupA
.getX()) ? rTupB
.getX() : rTupA
.getX(),
209 (rTupB
.getY() > rTupA
.getY()) ? rTupB
.getY() : rTupA
.getY());
213 inline B2I64Tuple
absolute(const B2I64Tuple
& rTup
)
216 (0 > rTup
.getX()) ? -rTup
.getX() : rTup
.getX(),
217 (0 > rTup
.getY()) ? -rTup
.getY() : rTup
.getY());
221 inline B2DTuple
interpolate(const B2I64Tuple
& rOld1
, const B2I64Tuple
& rOld2
, double t
)
224 ((rOld2
.getX() - rOld1
.getX()) * t
) + rOld1
.getX(),
225 ((rOld2
.getY() - rOld1
.getY()) * t
) + rOld1
.getY());
229 inline B2DTuple
average(const B2I64Tuple
& rOld1
, const B2I64Tuple
& rOld2
)
232 (rOld1
.getX() + rOld2
.getX()) * 0.5,
233 (rOld1
.getY() + rOld2
.getY()) * 0.5);
237 inline B2DTuple
average(const B2I64Tuple
& rOld1
, const B2I64Tuple
& rOld2
, const B2I64Tuple
& rOld3
)
240 (rOld1
.getX() + rOld2
.getX() + rOld3
.getX()) * (1.0 / 3.0),
241 (rOld1
.getY() + rOld2
.getY() + rOld3
.getY()) * (1.0 / 3.0));
245 inline B2I64Tuple
operator+(const B2I64Tuple
& rTupA
, const B2I64Tuple
& rTupB
)
247 B2I64Tuple
aSum(rTupA
);
252 inline B2I64Tuple
operator-(const B2I64Tuple
& rTupA
, const B2I64Tuple
& rTupB
)
254 B2I64Tuple
aSub(rTupA
);
259 inline B2I64Tuple
operator/(const B2I64Tuple
& rTupA
, const B2I64Tuple
& rTupB
)
261 B2I64Tuple
aDiv(rTupA
);
266 inline B2I64Tuple
operator*(const B2I64Tuple
& rTupA
, const B2I64Tuple
& rTupB
)
268 B2I64Tuple
aMul(rTupA
);
273 inline B2I64Tuple
operator*(const B2I64Tuple
& rTup
, sal_Int64 t
)
275 B2I64Tuple
aNew(rTup
);
280 inline B2I64Tuple
operator*(sal_Int64 t
, const B2I64Tuple
& rTup
)
282 B2I64Tuple
aNew(rTup
);
287 inline B2I64Tuple
operator/(const B2I64Tuple
& rTup
, sal_Int64 t
)
289 B2I64Tuple
aNew(rTup
);
294 inline B2I64Tuple
operator/(sal_Int64 t
, const B2I64Tuple
& rTup
)
296 B2I64Tuple
aNew(t
, t
);
297 B2I64Tuple
aTmp(rTup
);
301 } // end of namespace basegfx
303 #endif /* _BGFX_TUPLE_B2I64TUPLE_HXX */
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */