diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-05-12 19:00:32 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-06-17 01:55:56 +0200 |
commit | c703b2d22c3f45825d9c9d790c3b5a4b6f97e776 (patch) | |
tree | 74736ac1b3cc558c2fa37c028a6d8180bc749180 /include/basegfx/tuple/b3ituple.hxx | |
parent | e337b9d92c6d5184e160df66885f53ebc4835218 (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/b3ituple.hxx')
-rw-r--r-- | include/basegfx/tuple/b3ituple.hxx | 87 |
1 files changed, 4 insertions, 83 deletions
diff --git a/include/basegfx/tuple/b3ituple.hxx b/include/basegfx/tuple/b3ituple.hxx index 7fe49ea92e93..72c9fa81402a 100644 --- a/include/basegfx/tuple/b3ituple.hxx +++ b/include/basegfx/tuple/b3ituple.hxx @@ -21,6 +21,7 @@ #include <sal/types.h> #include <basegfx/basegfxdllapi.h> +#include <basegfx/tuple/Tuple3D.hxx> namespace basegfx { @@ -32,22 +33,15 @@ namespace basegfx @derive Use this class to implement Points or Vectors which are based on three sal_Int32 values */ - class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B3ITuple + class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B3ITuple : public Tuple3D<sal_Int32> { - protected: - sal_Int32 mnX; - sal_Int32 mnY; - sal_Int32 mnZ; - public: /** Create a 3D Tuple The tuple is initialized to (0, 0, 0) */ B3ITuple() - : mnX(0), - mnY(0), - mnZ(0) + : Tuple3D(0, 0, 0) {} /** Create a 3D Tuple @@ -65,23 +59,9 @@ namespace basegfx of the 3D Tuple. */ B3ITuple(sal_Int32 nX, sal_Int32 nY, sal_Int32 nZ) - : mnX(nX), - mnY(nY), - mnZ(nZ) + : Tuple3D(nX, nY, nZ) {} - /// get X-Coordinate of 3D Tuple - sal_Int32 getX() const - { - return mnX; - } - - /// get Y-Coordinate of 3D Tuple - sal_Int32 getY() const - { - return mnY; - } - /// Array-access to 3D Tuple const sal_Int32& operator[] (int nPos) const { @@ -102,69 +82,10 @@ namespace basegfx // operators - - B3ITuple& operator+=( const B3ITuple& rTup ) - { - mnX += rTup.mnX; - mnY += rTup.mnY; - mnZ += rTup.mnZ; - return *this; - } - - B3ITuple& operator-=( const B3ITuple& rTup ) - { - mnX -= rTup.mnX; - mnY -= rTup.mnY; - mnZ -= rTup.mnZ; - return *this; - } - - B3ITuple& operator/=( const B3ITuple& rTup ) - { - mnX /= rTup.mnX; - mnY /= rTup.mnY; - mnZ /= rTup.mnZ; - return *this; - } - - B3ITuple& operator*=( const B3ITuple& rTup ) - { - mnX *= rTup.mnX; - mnY *= rTup.mnY; - mnZ *= rTup.mnZ; - return *this; - } - - B3ITuple& operator*=(sal_Int32 t) - { - mnX *= t; - mnY *= t; - mnZ *= t; - return *this; - } - - B3ITuple& operator/=(sal_Int32 t) - { - mnX /= t; - mnY /= t; - mnZ /= t; - return *this; - } - B3ITuple operator-(void) const { return B3ITuple(-mnX, -mnY, -mnZ); } - - bool operator==( const B3ITuple& rTup ) const - { - return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY && rTup.mnZ == mnZ); - } - - bool operator!=( const B3ITuple& rTup ) const - { - return !(*this == rTup); - } }; } // end of namespace basegfx |