diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-09-08 11:12:27 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-09-11 17:16:59 +0200 |
commit | c747486335c089baf440b8f040d3ffdc14aa5049 (patch) | |
tree | 0d173f69ac82099cfb8bde3ac2831a682665391d /include | |
parent | 5f5f2f8107b6176654bfb9a30c21b7d5e0c62c6f (diff) |
basegfx: replace typedef with a class B2DSize based on Size2D
Change-Id: Id8b3c2bcf0bf4be5aba2812b0edda479bc20c6a9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139683
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/basegfx/point/b2dpoint.hxx | 6 | ||||
-rw-r--r-- | include/basegfx/tuple/Size2D.hxx | 2 | ||||
-rw-r--r-- | include/basegfx/utils/canvastools.hxx | 3 | ||||
-rw-r--r-- | include/basegfx/vector/b2dsize.hxx | 69 | ||||
-rw-r--r-- | include/vcl/canvastools.hxx | 4 |
5 files changed, 76 insertions, 8 deletions
diff --git a/include/basegfx/point/b2dpoint.hxx b/include/basegfx/point/b2dpoint.hxx index 3bd6af90af9c..6252352fdebe 100644 --- a/include/basegfx/point/b2dpoint.hxx +++ b/include/basegfx/point/b2dpoint.hxx @@ -23,6 +23,7 @@ #include <basegfx/tuple/b2dtuple.hxx> #include <basegfx/point/b2ipoint.hxx> +#include <basegfx/vector/b2dsize.hxx> #include <basegfx/basegfxdllapi.h> namespace basegfx @@ -77,6 +78,11 @@ namespace basegfx : B2DTuple(rTuple) {} + /** create a point from a size object */ + explicit B2DPoint(Size2D<double> const& rSize) + : B2DTuple(rSize.getWidth(), rSize.getHeight()) + {} + /** *=operator to allow usage from B2DPoint, too */ B2DPoint& operator*=( const B2DPoint& rPnt ) diff --git a/include/basegfx/tuple/Size2D.hxx b/include/basegfx/tuple/Size2D.hxx index 87bd95330bb8..d4e2a2a784bc 100644 --- a/include/basegfx/tuple/Size2D.hxx +++ b/include/basegfx/tuple/Size2D.hxx @@ -22,7 +22,7 @@ public: { } - Size2D(Tuple2D<double> const& rTuple) + Size2D(Tuple2D<TYPE> const& rTuple) : Tuple2D<TYPE>(rTuple.getX(), rTuple.getY()) { } diff --git a/include/basegfx/utils/canvastools.hxx b/include/basegfx/utils/canvastools.hxx index 9b2f44dd3e14..228a1b0f504a 100644 --- a/include/basegfx/utils/canvastools.hxx +++ b/include/basegfx/utils/canvastools.hxx @@ -60,6 +60,7 @@ namespace basegfx class B2IRange; class B2DPolygon; class B2DPolyPolygon; + class B2DSize; } namespace basegfx::unotools @@ -119,7 +120,7 @@ namespace basegfx::unotools // Geometry conversions - BASEGFX_DLLPUBLIC css::geometry::RealSize2D size2DFromB2DSize( const ::basegfx::B2DVector& ); + BASEGFX_DLLPUBLIC css::geometry::RealSize2D size2DFromB2DSize( const ::basegfx::B2DSize& ); BASEGFX_DLLPUBLIC css::geometry::RealPoint2D point2DFromB2DPoint( const ::basegfx::B2DPoint& ); BASEGFX_DLLPUBLIC css::geometry::RealRectangle2D rectangle2DFromB2DRectangle( const ::basegfx::B2DRange& ); BASEGFX_DLLPUBLIC css::geometry::RealRectangle3D rectangle3DFromB3DRectangle( const ::basegfx::B3DRange& ); diff --git a/include/basegfx/vector/b2dsize.hxx b/include/basegfx/vector/b2dsize.hxx index 1179126991e0..e15158fbf9fd 100644 --- a/include/basegfx/vector/b2dsize.hxx +++ b/include/basegfx/vector/b2dsize.hxx @@ -19,15 +19,74 @@ #pragma once -#include <basegfx/vector/b2dvector.hxx> +#include <basegfx/tuple/Size2D.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/vector/b2isize.hxx> +#include <basegfx/numeric/ftools.hxx> +#include <basegfx/basegfxdllapi.h> namespace basegfx { -// syntactic sugar: a B2DVector exactly models a Size object, -// thus, for interface clarity, we provide an alias name +class B2DSize : public Size2D<double> +{ +public: + B2DSize() + : Size2D(0.0, 0.0) + { + } + + B2DSize(double fX, double fY) + : Size2D(fX, fY) + { + } + + B2DSize(Size2D<double> const& rSize) + : Size2D(rSize) + { + } + + explicit B2DSize(B2ISize const& rSize) + : Size2D(rSize.getX(), rSize.getY()) + { + } + + /** Transform size by given transformation matrix. */ + B2DSize& operator*=(const B2DHomMatrix& rMatrix) + { + const double fTempX(rMatrix.get(0, 0) * getWidth() + rMatrix.get(0, 1) * getHeight()); + const double fTempY(rMatrix.get(1, 0) * getWidth() + rMatrix.get(1, 1) * getHeight()); + setWidth(fTempX); + setHeight(fTempY); + return *this; + } -/// Alias name for interface clarity (not everybody is aware of the identity) -typedef B2DVector B2DSize; + using Size2D<double>::operator+=; + using Size2D<double>::operator-=; + using Size2D<double>::operator*=; + using Size2D<double>::operator/=; + using Size2D<double>::operator-; + + double getLength() const + { + if (fTools::equalZero(getWidth())) + { + return fabs(getHeight()); + } + else if (fTools::equalZero(getHeight())) + { + return fabs(getWidth()); + } + + return hypot(getWidth(), getHeight()); + } +}; + +inline B2DSize operator*(B2DHomMatrix const& rMatrix, B2DSize const& rSize) +{ + B2DSize aRes(rSize); + aRes *= rMatrix; + return aRes; +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/canvastools.hxx b/include/vcl/canvastools.hxx index 5a46886e59b4..778a092261a1 100644 --- a/include/vcl/canvastools.hxx +++ b/include/vcl/canvastools.hxx @@ -40,6 +40,7 @@ namespace basegfx class B2DRange; class B2IPoint; class B2IRange; + class B2DSize; } namespace com::sun::star::geometry @@ -150,7 +151,8 @@ namespace vcl::unotools Point VCL_DLLPUBLIC pointFromB2DPoint( const basegfx::B2DPoint& ); tools::Rectangle VCL_DLLPUBLIC rectangleFromB2DRectangle( const basegfx::B2DRange& ); - basegfx::B2DVector VCL_DLLPUBLIC b2DSizeFromSize( const Size& ); + VCL_DLLPUBLIC basegfx::B2DSize b2DSizeFromSize(const Size& rSize); + VCL_DLLPUBLIC basegfx::B2DVector b2DVectorFromSize(const Size& rSize); basegfx::B2DPoint VCL_DLLPUBLIC b2DPointFromPoint( const Point& ); basegfx::B2DRange VCL_DLLPUBLIC b2DRectangleFromRectangle( const tools::Rectangle& ); |