summaryrefslogtreecommitdiff
path: root/include/basegfx/tuple/b3dtuple.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/b3dtuple.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/b3dtuple.hxx')
-rw-r--r--include/basegfx/tuple/b3dtuple.hxx109
1 files changed, 6 insertions, 103 deletions
diff --git a/include/basegfx/tuple/b3dtuple.hxx b/include/basegfx/tuple/b3dtuple.hxx
index 791cc5f3e667..bb8f4b4067c3 100644
--- a/include/basegfx/tuple/b3dtuple.hxx
+++ b/include/basegfx/tuple/b3dtuple.hxx
@@ -23,6 +23,7 @@
#include <sal/types.h>
#include <basegfx/numeric/ftools.hxx>
#include <basegfx/basegfxdllapi.h>
+#include <basegfx/tuple/Tuple3D.hxx>
namespace basegfx
{
@@ -36,22 +37,15 @@ namespace basegfx
@derive Use this class to implement Points or Vectors
which are based on three double values
*/
- class SAL_WARN_UNUSED UNLESS_MERGELIBS(BASEGFX_DLLPUBLIC) B3DTuple
+ class SAL_WARN_UNUSED UNLESS_MERGELIBS(BASEGFX_DLLPUBLIC) B3DTuple : public Tuple3D<double>
{
- protected:
- double mfX;
- double mfY;
- double mfZ;
-
public:
/** Create a 3D Tuple
The tuple is initialized to (0.0, 0.0, 0.0)
*/
B3DTuple()
- : mfX(0.0),
- mfY(0.0),
- mfZ(0.0)
+ : Tuple3D(0.0, 0.0, 0.0)
{}
/** Create a 3D Tuple
@@ -69,47 +63,9 @@ namespace basegfx
of the 3D Tuple.
*/
B3DTuple(double fX, double fY, double fZ)
- : mfX(fX),
- mfY(fY),
- mfZ(fZ)
+ : Tuple3D(fX, fY, fZ)
{}
- /// get X-Coordinate of 3D Tuple
- double getX() const
- {
- return mfX;
- }
-
- /// get Y-Coordinate of 3D Tuple
- double getY() const
- {
- return mfY;
- }
-
- /// get Z-Coordinate of 3D Tuple
- double getZ() const
- {
- return mfZ;
- }
-
- /// set X-Coordinate of 3D Tuple
- void setX(double fX)
- {
- mfX = fX;
- }
-
- /// set Y-Coordinate of 3D Tuple
- void setY(double fY)
- {
- mfY = fY;
- }
-
- /// set Z-Coordinate of 3D Tuple
- void setZ(double fZ)
- {
- mfZ = fZ;
- }
-
/// Array-access to 3D Tuple
const double& operator[] (int nPos) const
{
@@ -150,70 +106,17 @@ namespace basegfx
// operators
-
- B3DTuple& operator+=( const B3DTuple& rTup )
- {
- mfX += rTup.mfX;
- mfY += rTup.mfY;
- mfZ += rTup.mfZ;
- return *this;
- }
-
- B3DTuple& operator-=( const B3DTuple& rTup )
- {
- mfX -= rTup.mfX;
- mfY -= rTup.mfY;
- mfZ -= rTup.mfZ;
- return *this;
- }
-
- B3DTuple& operator/=( const B3DTuple& rTup )
- {
- mfX /= rTup.mfX;
- mfY /= rTup.mfY;
- mfZ /= rTup.mfZ;
- return *this;
- }
-
- B3DTuple& operator*=( const B3DTuple& rTup )
- {
- mfX *= rTup.mfX;
- mfY *= rTup.mfY;
- mfZ *= rTup.mfZ;
- return *this;
- }
-
- B3DTuple& operator*=(double t)
- {
- mfX *= t;
- mfY *= t;
- mfZ *= t;
- return *this;
- }
-
- B3DTuple& operator/=(double t)
- {
- const double fVal(1.0 / t);
- mfX *= fVal;
- mfY *= fVal;
- mfZ *= fVal;
- return *this;
- }
-
B3DTuple operator-(void) const
{
return B3DTuple(-mfX, -mfY, -mfZ);
}
- bool operator==( const B3DTuple& rTup ) const
+ bool operator==(const B3DTuple& rTup) const
{
return mfX == rTup.mfX && mfY == rTup.mfY && mfZ == rTup.mfZ;
}
- bool operator!=( const B3DTuple& rTup ) const
- {
- return mfX != rTup.mfX || mfY != rTup.mfY || mfZ != rTup.mfZ;
- }
+ bool operator!=(const B3DTuple& rTup) const { return !operator==(rTup); }
void correctValues(const double fCompareValue = 0.0)
{