summaryrefslogtreecommitdiff
path: root/include/basegfx/tuple/b2ituple.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/b2ituple.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/b2ituple.hxx')
-rw-r--r--include/basegfx/tuple/b2ituple.hxx119
1 files changed, 7 insertions, 112 deletions
diff --git a/include/basegfx/tuple/b2ituple.hxx b/include/basegfx/tuple/b2ituple.hxx
index b8f6c3e96386..e3f195596a37 100644
--- a/include/basegfx/tuple/b2ituple.hxx
+++ b/include/basegfx/tuple/b2ituple.hxx
@@ -21,6 +21,7 @@
#include <sal/types.h>
#include <basegfx/basegfxdllapi.h>
+#include <basegfx/tuple/Tuple2D.hxx>
namespace basegfx
{
@@ -32,143 +33,37 @@ namespace basegfx
@derive Use this class to implement Points or Vectors
which are based on two sal_Int32 values
*/
- class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2ITuple
+ class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2ITuple : public Tuple2D<sal_Int32>
{
- protected:
- sal_Int32 mnX;
- sal_Int32 mnY;
-
public:
/** Create a 2D Tuple
The tuple is initialized to (0, 0)
*/
B2ITuple()
- : 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.
*/
- B2ITuple(sal_Int32 fX, sal_Int32 fY)
- : mnX( fX ),
- mnY( fY )
+ B2ITuple(sal_Int32 nX, sal_Int32 nY)
+ : Tuple2D(nX, nY)
{}
- /// Get X-Coordinate of 2D Tuple
- sal_Int32 getX() const
- {
- return mnX;
- }
-
- /// Get Y-Coordinate of 2D Tuple
- sal_Int32 getY() const
- {
- return mnY;
- }
-
- /// Set X-Coordinate of 2D Tuple
- void setX(sal_Int32 fX)
- {
- mnX = fX;
- }
-
- /// Set Y-Coordinate of 2D Tuple
- void setY(sal_Int32 fY)
- {
- mnY = fY;
- }
-
- /// Array-access to 2D Tuple
- const sal_Int32& operator[] (int nPos) const
- {
- // Here, normally one if(...) should be used. In the assumption that
- // both sal_Int32 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_Int32& operator[] (int nPos)
- {
- // Here, normally one if(...) should be used. In the assumption that
- // both sal_Int32 members can be accessed as an array a shortcut is used here.
- // if(0 == nPos) return mnX; return mnY;
- return *((&mnX) + nPos);
- }
-
// operators
-
- B2ITuple& operator+=( const B2ITuple& rTup )
- {
- mnX += rTup.mnX;
- mnY += rTup.mnY;
- return *this;
- }
-
- B2ITuple& operator-=( const B2ITuple& rTup )
- {
- mnX -= rTup.mnX;
- mnY -= rTup.mnY;
- return *this;
- }
-
- B2ITuple& operator/=( const B2ITuple& rTup )
- {
- mnX /= rTup.mnX;
- mnY /= rTup.mnY;
- return *this;
- }
-
- B2ITuple& operator*=( const B2ITuple& rTup )
- {
- mnX *= rTup.mnX;
- mnY *= rTup.mnY;
- return *this;
- }
-
- B2ITuple& operator*=(sal_Int32 t)
- {
- mnX *= t;
- mnY *= t;
- return *this;
- }
-
- B2ITuple& operator/=(sal_Int32 t)
- {
- mnX /= t;
- mnY /= t;
- return *this;
- }
-
B2ITuple operator-(void) const
{
return B2ITuple(-mnX, -mnY);
}
-
- bool equalZero() const
- {
- return mnX == 0 && mnY == 0;
- }
-
- bool operator==( const B2ITuple& rTup ) const
- {
- return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY);
- }
-
- bool operator!=( const B2ITuple& rTup ) const
- {
- return !(*this == rTup);
- }
};
// external operators