summaryrefslogtreecommitdiff
path: root/include/basegfx/tuple/b2dtuple.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/b2dtuple.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/b2dtuple.hxx')
-rw-r--r--include/basegfx/tuple/b2dtuple.hxx121
1 files changed, 4 insertions, 117 deletions
diff --git a/include/basegfx/tuple/b2dtuple.hxx b/include/basegfx/tuple/b2dtuple.hxx
index 0c7b7f463261..c523501b9639 100644
--- a/include/basegfx/tuple/b2dtuple.hxx
+++ b/include/basegfx/tuple/b2dtuple.hxx
@@ -22,7 +22,7 @@
#include <sal/types.h>
#include <basegfx/numeric/ftools.hxx>
#include <basegfx/basegfxdllapi.h>
-#include <basegfx/utils/common.hxx>
+#include <basegfx/tuple/Tuple2D.hxx>
namespace basegfx
{
@@ -36,12 +36,8 @@ namespace basegfx
@derive Use this class to implement Points or Vectors
which are based on two double values
*/
- class SAL_WARN_UNUSED B2DTuple
+ class SAL_WARN_UNUSED B2DTuple : public Tuple2D<double>
{
- protected:
- double mfX;
- double mfY;
-
public:
/** Create a 2D Tuple
@@ -49,8 +45,7 @@ namespace basegfx
The tuple is initialized to (0.0, 0.0)
*/
B2DTuple()
- : mfX(0.0),
- mfY(0.0)
+ : Tuple2D(0.0, 0.0)
{}
/** Create a 2D Tuple
@@ -64,8 +59,7 @@ namespace basegfx
of the 2D Tuple.
*/
B2DTuple(double fX, double fY)
- : mfX( fX ),
- mfY( fY )
+ : Tuple2D(fX, fY)
{}
/** Create a copy of a 2D integer Tuple
@@ -75,120 +69,13 @@ namespace basegfx
*/
BASEGFX_DLLPUBLIC explicit B2DTuple(const B2ITuple& rTup);
- /// Get X-Coordinate of 2D Tuple
- double getX() const
- {
- return mfX;
- }
-
- /// Get Y-Coordinate of 2D Tuple
- double getY() const
- {
- return mfY;
- }
-
- /// Set X-Coordinate of 2D Tuple
- void setX(double fX)
- {
- mfX = fX;
- }
-
- /// Set Y-Coordinate of 2D Tuple
- void setY(double fY)
- {
- mfY = fY;
- }
-
- double get(Axis2D eAxis)
- {
- return eAxis == Axis2D::X ? getX() : getY();
- }
-
- void set(Axis2D eAxis, double fValue)
- {
- if (eAxis == Axis2D::X)
- setX(fValue);
- else
- setY(fValue);
- }
-
- // comparators with tolerance
-
- bool equalZero() const
- {
- return (this == &getEmptyTuple() ||
- (fTools::equalZero(mfX) && fTools::equalZero(mfY)));
- }
-
- bool equal(const B2DTuple& rTup) const
- {
- return (
- this == &rTup ||
- (fTools::equal(mfX, rTup.mfX) &&
- fTools::equal(mfY, rTup.mfY)));
- }
-
// operators
-
- B2DTuple& operator+=( const B2DTuple& rTup )
- {
- mfX += rTup.mfX;
- mfY += rTup.mfY;
- return *this;
- }
-
- B2DTuple& operator-=( const B2DTuple& rTup )
- {
- mfX -= rTup.mfX;
- mfY -= rTup.mfY;
- return *this;
- }
-
- B2DTuple& operator/=( const B2DTuple& rTup )
- {
- mfX /= rTup.mfX;
- mfY /= rTup.mfY;
- return *this;
- }
-
- B2DTuple& operator*=( const B2DTuple& rTup )
- {
- mfX *= rTup.mfX;
- mfY *= rTup.mfY;
- return *this;
- }
-
- B2DTuple& operator*=(double t)
- {
- mfX *= t;
- mfY *= t;
- return *this;
- }
-
- B2DTuple& operator/=(double t)
- {
- const double fVal(1.0 / t);
- mfX *= fVal;
- mfY *= fVal;
- return *this;
- }
-
B2DTuple operator-(void) const
{
return B2DTuple(-mfX, -mfY);
}
- bool operator==( const B2DTuple& rTup ) const
- {
- return mfX == rTup.mfX && mfY == rTup.mfY;
- }
-
- bool operator!=( const B2DTuple& rTup ) const
- {
- return mfX != rTup.mfX || mfY != rTup.mfY;
- }
-
BASEGFX_DLLPUBLIC static const B2DTuple& getEmptyTuple();
};