summaryrefslogtreecommitdiff
path: root/include/basegfx/tuple/b2i64tuple.hxx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-05-12 19:00:32 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-06-17 01:55:56 +0200
commitc703b2d22c3f45825d9c9d790c3b5a4b6f97e776 (patch)
tree74736ac1b3cc558c2fa37c028a6d8180bc749180 /include/basegfx/tuple/b2i64tuple.hxx
parente337b9d92c6d5184e160df66885f53ebc4835218 (diff)
basegfx: generalise tuples with template class Tuple2D and Tuple3D
B2DTuple2D, B2ITuple2D and B2I64Tuple share a lot in common so we can generalise it as a template class. The same goes for the 3D variants - B3DTuple and B3ITuple. This is the initial attempt, but doesn't yet generalise all that is possible. Add some tests for the tuple variants that test the behaviour of overloaded operators and other common methods. Change-Id: Iee5ed15d58ea88e65ee7854bd05a87ceab22023d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117104 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'include/basegfx/tuple/b2i64tuple.hxx')
-rw-r--r--include/basegfx/tuple/b2i64tuple.hxx105
1 files changed, 8 insertions, 97 deletions
diff --git a/include/basegfx/tuple/b2i64tuple.hxx b/include/basegfx/tuple/b2i64tuple.hxx
index 5f2350b66ac1..70838572f321 100644
--- a/include/basegfx/tuple/b2i64tuple.hxx
+++ b/include/basegfx/tuple/b2i64tuple.hxx
@@ -21,7 +21,7 @@
#include <sal/types.h>
#include <basegfx/basegfxdllapi.h>
-
+#include <basegfx/tuple/Tuple2D.hxx>
namespace basegfx
{
@@ -33,34 +33,29 @@ namespace basegfx
@derive Use this class to implement Points or Vectors
which are based on two sal_Int64 values
*/
- class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2I64Tuple final
+ class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2I64Tuple : public Tuple2D<sal_Int64>
{
- sal_Int64 mnX;
- sal_Int64 mnY;
-
public:
/** Create a 2D Tuple
The tuple is initialized to (0, 0)
*/
B2I64Tuple()
- : mnX(0),
- mnY(0)
+ : Tuple2D(0, 0)
{}
/** Create a 2D Tuple
- @param fX
+ @param nX
This parameter is used to initialize the X-coordinate
of the 2D Tuple.
- @param fY
+ @param nY
This parameter is used to initialize the Y-coordinate
of the 2D Tuple.
*/
- B2I64Tuple(sal_Int64 fX, sal_Int64 fY)
- : mnX( fX ),
- mnY( fY )
+ B2I64Tuple(sal_Int64 nX, sal_Int64 nY)
+ : Tuple2D(nX, nY)
{}
/** Create a copy of a 2D Tuple
@@ -69,100 +64,16 @@ namespace basegfx
The 2D Tuple which will be copied.
*/
B2I64Tuple(const B2I64Tuple& rTup)
- : mnX( rTup.mnX ),
- mnY( rTup.mnY )
+ : Tuple2D(rTup.mnX, rTup.mnY)
{}
- /// Get X-Coordinate of 2D Tuple
- sal_Int64 getX() const
- {
- return mnX;
- }
-
- /// Get Y-Coordinate of 2D Tuple
- sal_Int64 getY() const
- {
- return mnY;
- }
-
- /// Array-access to 2D Tuple
- const sal_Int64& operator[] (int nPos) const
- {
- // Here, normally one if(...) should be used. In the assumption that
- // both sal_Int64 members can be accessed as an array a shortcut is used here.
- // if(0 == nPos) return mnX; return mnY;
- return *((&mnX) + nPos);
- }
-
- /// Array-access to 2D Tuple
- sal_Int64& operator[] (int nPos)
- {
- // Here, normally one if(...) should be used. In the assumption that
- // both sal_Int64 members can be accessed as an array a shortcut is used here.
- // if(0 == nPos) return mnX; return mnY;
- return *((&mnX) + nPos);
- }
-
// operators
-
- B2I64Tuple& operator+=( const B2I64Tuple& rTup )
- {
- mnX += rTup.mnX;
- mnY += rTup.mnY;
- return *this;
- }
-
- B2I64Tuple& operator-=( const B2I64Tuple& rTup )
- {
- mnX -= rTup.mnX;
- mnY -= rTup.mnY;
- return *this;
- }
-
- B2I64Tuple& operator/=( const B2I64Tuple& rTup )
- {
- mnX /= rTup.mnX;
- mnY /= rTup.mnY;
- return *this;
- }
-
- B2I64Tuple& operator*=( const B2I64Tuple& rTup )
- {
- mnX *= rTup.mnX;
- mnY *= rTup.mnY;
- return *this;
- }
-
- B2I64Tuple& operator*=(sal_Int64 t)
- {
- mnX *= t;
- mnY *= t;
- return *this;
- }
-
- B2I64Tuple& operator/=(sal_Int64 t)
- {
- mnX /= t;
- mnY /= t;
- return *this;
- }
-
B2I64Tuple operator-(void) const
{
return B2I64Tuple(-mnX, -mnY);
}
- bool operator==( const B2I64Tuple& rTup ) const
- {
- return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY);
- }
-
- bool operator!=( const B2I64Tuple& rTup ) const
- {
- return !(*this == rTup);
- }
-
B2I64Tuple& operator=( const B2I64Tuple& rTup )
{
mnX = rTup.mnX;