From d991795635784675f6659dc47265088b1803cd52 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Tue, 19 Nov 2024 14:25:01 +0100 Subject: [PATCH] canvas: simplify calcTransformedRectBounds Change-Id: Ia0314a985ae2183727587ad254faec12ee49b66c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176769 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- canvas/source/tools/canvascustomspritehelper.cxx | 6 ++---- canvas/source/tools/canvastools.cxx | 9 +++------ canvas/source/vcl/canvashelper.cxx | 3 +-- canvas/source/vcl/canvashelper_texturefill.cxx | 15 +++++---------- canvas/source/vcl/impltools.cxx | 3 +-- cppcanvas/source/mtfrenderer/mtftools.cxx | 4 +--- include/canvas/canvastools.hxx | 7 ++----- .../source/engine/shapes/viewappletshape.cxx | 6 ++---- .../source/engine/shapes/viewbackgroundshape.cxx | 3 +-- slideshow/source/engine/shapes/viewmediashape.cxx | 7 ++----- slideshow/source/engine/shapes/viewshape.cxx | 8 ++------ slideshow/source/engine/slide/slideimpl.cxx | 3 +-- slideshow/source/engine/slideview.cxx | 9 +++------ slideshow/source/engine/tools.cxx | 6 +----- 14 files changed, 27 insertions(+), 62 deletions(-) diff --git a/canvas/source/tools/canvascustomspritehelper.cxx b/canvas/source/tools/canvascustomspritehelper.cxx index 2517e05be947..d6aa4e06f0f5 100644 --- a/canvas/source/tools/canvascustomspritehelper.cxx +++ b/canvas/source/tools/canvascustomspritehelper.cxx @@ -70,8 +70,7 @@ namespace canvas // rectangular area which is actually covered by the sprite. // coordinates are relative to the sprite origin. - ::basegfx::B2DRectangle aSpriteRectPixel; - ::canvas::tools::calcTransformedRectBounds( aSpriteRectPixel, + ::basegfx::B2DRectangle aSpriteRectPixel = ::canvas::tools::calcTransformedRectBounds( aBounds, maTransform ); @@ -413,8 +412,7 @@ namespace canvas // transform bounds at origin, as the sprite transformation is // formulated that way - ::basegfx::B2DRectangle aTransformedBounds; - return ::canvas::tools::calcTransformedRectBounds( aTransformedBounds, + return ::canvas::tools::calcTransformedRectBounds( rBounds, aTransform ); } diff --git a/canvas/source/tools/canvastools.cxx b/canvas/source/tools/canvastools.cxx index 18d103cc1228..cf72e8fed401 100644 --- a/canvas/source/tools/canvastools.cxx +++ b/canvas/source/tools/canvastools.cxx @@ -821,9 +821,7 @@ namespace canvas::tools } // transform by given transformation - ::basegfx::B2DRectangle aTransformedRect; - - calcTransformedRectBounds( aTransformedRect, + ::basegfx::B2DRectangle aTransformedRect = calcTransformedRectBounds( i_srcRect, i_transformation ); @@ -837,11 +835,10 @@ namespace canvas::tools return o_transform; } - ::basegfx::B2DRange& calcTransformedRectBounds( ::basegfx::B2DRange& outRect, - const ::basegfx::B2DRange& inRect, + ::basegfx::B2DRange calcTransformedRectBounds( const ::basegfx::B2DRange& inRect, const ::basegfx::B2DHomMatrix& transformation ) { - outRect.reset(); + ::basegfx::B2DRange outRect; if( inRect.isEmpty() ) return outRect; diff --git a/canvas/source/vcl/canvashelper.cxx b/canvas/source/vcl/canvashelper.cxx index f398f6734f1a..a35a93bc1dba 100644 --- a/canvas/source/vcl/canvashelper.cxx +++ b/canvas/source/vcl/canvashelper.cxx @@ -795,8 +795,7 @@ namespace vclcanvas // modify output position, to account for the fact // that transformBitmap() always normalizes its output // bitmap into the smallest enclosing box. - ::basegfx::B2DRectangle aDestRect; - ::canvas::tools::calcTransformedRectBounds( aDestRect, + ::basegfx::B2DRectangle aDestRect = ::canvas::tools::calcTransformedRectBounds( ::basegfx::B2DRectangle(0, 0, aBmpSize.Width(), diff --git a/canvas/source/vcl/canvashelper_texturefill.cxx b/canvas/source/vcl/canvashelper_texturefill.cxx index f9501cf8d426..2a1ec6b88c9a 100644 --- a/canvas/source/vcl/canvashelper_texturefill.cxx +++ b/canvas/source/vcl/canvashelper_texturefill.cxx @@ -574,9 +574,8 @@ namespace vclcanvas // extra-verbosity { ::basegfx::B2DRectangle aRect(0.0, 0.0, 1.0, 1.0); - ::basegfx::B2DRectangle aTextureDeviceRect; ::basegfx::B2DHomMatrix aTextureTransform; - ::canvas::tools::calcTransformedRectBounds( aTextureDeviceRect, + ::basegfx::B2DRectangle aTextureDeviceRect = ::canvas::tools::calcTransformedRectBounds( aRect, aTextureTransform ); rOutDev.SetLineColor( COL_RED ); @@ -699,8 +698,7 @@ namespace vclcanvas aTotalTransform *= aTextureTransform; const ::basegfx::B2DRectangle aRect(0.0, 0.0, 1.0, 1.0); - ::basegfx::B2DRectangle aTextureDeviceRect; - ::canvas::tools::calcTransformedRectBounds( aTextureDeviceRect, + ::basegfx::B2DRectangle aTextureDeviceRect = ::canvas::tools::calcTransformedRectBounds( aRect, aTotalTransform ); @@ -806,8 +804,7 @@ namespace vclcanvas // modify output position, to account for the fact // that transformBitmap() always normalizes its output // bitmap into the smallest enclosing box. - ::basegfx::B2DRectangle aDestRect; - ::canvas::tools::calcTransformedRectBounds( aDestRect, + ::basegfx::B2DRectangle aDestRect = ::canvas::tools::calcTransformedRectBounds( ::basegfx::B2DRectangle(0, 0, aBmpSize.Width, @@ -867,8 +864,7 @@ namespace vclcanvas // Finally, the bound rect is transformed back to // device coordinate space, were we determine the // start point from it. - ::basegfx::B2DRectangle aTextureSpacePolygonRect; - ::canvas::tools::calcTransformedRectBounds( aTextureSpacePolygonRect, + ::basegfx::B2DRectangle aTextureSpacePolygonRect = ::canvas::tools::calcTransformedRectBounds( vcl::unotools::b2DRectangleFromRectangle(aPolygonDeviceRect), aInverseTextureTransform ); @@ -891,8 +887,7 @@ namespace vclcanvas nY1 + 1.0 ); // and convert back to device space - ::basegfx::B2DRectangle aSingleDeviceTextureRect; - ::canvas::tools::calcTransformedRectBounds( aSingleDeviceTextureRect, + ::basegfx::B2DRectangle aSingleDeviceTextureRect = ::canvas::tools::calcTransformedRectBounds( aSingleTextureRect, aPureTotalTransform ); diff --git a/canvas/source/vcl/impltools.cxx b/canvas/source/vcl/impltools.cxx index 854e8c1618e3..7b431bdf7258 100644 --- a/canvas/source/vcl/impltools.cxx +++ b/canvas/source/vcl/impltools.cxx @@ -223,13 +223,12 @@ namespace vclcanvas::tools // deleted from the transformation; this can be handled by // an offset when painting the bitmap const Size aBmpSize( rBitmap.GetSizePixel() ); - ::basegfx::B2DRectangle aDestRect; // calc effective transformation for bitmap const ::basegfx::B2DRectangle aSrcRect( 0, 0, aBmpSize.Width(), aBmpSize.Height() ); - ::canvas::tools::calcTransformedRectBounds( aDestRect, + ::basegfx::B2DRectangle aDestRect = ::canvas::tools::calcTransformedRectBounds( aSrcRect, rTransform ); diff --git a/cppcanvas/source/mtfrenderer/mtftools.cxx b/cppcanvas/source/mtfrenderer/mtftools.cxx index dce2973bebca..e0ed0e94f222 100644 --- a/cppcanvas/source/mtfrenderer/mtftools.cxx +++ b/cppcanvas/source/mtfrenderer/mtftools.cxx @@ -634,9 +634,7 @@ namespace cppcanvas::tools viewState, renderState ); - ::basegfx::B2DRange aTransformedBounds; - return ::canvas::tools::calcTransformedRectBounds( aTransformedBounds, - rBounds, + return ::canvas::tools::calcTransformedRectBounds(rBounds, aTransform ); } diff --git a/include/canvas/canvastools.hxx b/include/canvas/canvastools.hxx index c82f0541a6db..72660839a110 100644 --- a/include/canvas/canvastools.hxx +++ b/include/canvas/canvastools.hxx @@ -176,18 +176,15 @@ namespace canvas specified input rectangle, and returns the bounding box of the resulting output area. - @param o_Rect - Output rectangle - @param i_Rect Input rectangle @param i_Transformation Transformation to apply to the input rectangle - @return a reference to the resulting rectangle + @return the resulting rectangle */ - CANVASTOOLS_DLLPUBLIC ::basegfx::B2DRange& calcTransformedRectBounds( ::basegfx::B2DRange& o_Rect, + CANVASTOOLS_DLLPUBLIC ::basegfx::B2DRange calcTransformedRectBounds( const ::basegfx::B2DRange& i_Rect, const ::basegfx::B2DHomMatrix& i_Transformation ); diff --git a/slideshow/source/engine/shapes/viewappletshape.cxx b/slideshow/source/engine/shapes/viewappletshape.cxx index faf7d7719184..460d0170c633 100644 --- a/slideshow/source/engine/shapes/viewappletshape.cxx +++ b/slideshow/source/engine/shapes/viewappletshape.cxx @@ -164,8 +164,7 @@ namespace slideshow::internal // resize surrounding window and applet to current shape size // ========================================================== - ::basegfx::B2DRange aTmpRange; - ::canvas::tools::calcTransformedRectBounds( aTmpRange, + ::basegfx::B2DRange aTmpRange = ::canvas::tools::calcTransformedRectBounds( rBounds, mpViewLayer->getTransformation() ); const ::basegfx::B2IRange aPixelBounds( @@ -230,8 +229,7 @@ namespace slideshow::internal if( !mxFrame.is() ) return false; - ::basegfx::B2DRange aTmpRange; - ::canvas::tools::calcTransformedRectBounds( aTmpRange, + ::basegfx::B2DRange aTmpRange = ::canvas::tools::calcTransformedRectBounds( rBounds, mpViewLayer->getTransformation() ); const ::basegfx::B2IRange aPixelBounds( diff --git a/slideshow/source/engine/shapes/viewbackgroundshape.cxx b/slideshow/source/engine/shapes/viewbackgroundshape.cxx index f961eabb7107..978ade81db84 100644 --- a/slideshow/source/engine/shapes/viewbackgroundshape.cxx +++ b/slideshow/source/engine/shapes/viewbackgroundshape.cxx @@ -61,8 +61,7 @@ namespace slideshow::internal // buffered bitmap is invalid, re-create // determine transformed page bounds - ::basegfx::B2DRectangle aTmpRect; - ::canvas::tools::calcTransformedRectBounds( aTmpRect, + ::basegfx::B2DRectangle aTmpRect = ::canvas::tools::calcTransformedRectBounds( maBounds, aCanvasTransform ); diff --git a/slideshow/source/engine/shapes/viewmediashape.cxx b/slideshow/source/engine/shapes/viewmediashape.cxx index bf683d17a341..ec19f11b66f8 100644 --- a/slideshow/source/engine/shapes/viewmediashape.cxx +++ b/slideshow/source/engine/shapes/viewmediashape.cxx @@ -228,8 +228,7 @@ namespace slideshow::internal maWindowOffset.Y = aRect.Y; } - ::basegfx::B2DRange aTmpRange; - ::canvas::tools::calcTransformedRectBounds( aTmpRange, + ::basegfx::B2DRange aTmpRange = ::canvas::tools::calcTransformedRectBounds( rNewBounds, mpViewLayer->getTransformation() ); const ::basegfx::B2IRange aRangePix( @@ -422,9 +421,7 @@ namespace slideshow::internal if( pWindow ) { - ::basegfx::B2DRange aTmpRange; - ::canvas::tools::calcTransformedRectBounds( aTmpRange, - rBounds, + ::basegfx::B2DRange aTmpRange = ::canvas::tools::calcTransformedRectBounds( rBounds, mpViewLayer->getTransformation() ); const ::basegfx::B2IRange aRangePix( ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange )); diff --git a/slideshow/source/engine/shapes/viewshape.cxx b/slideshow/source/engine/shapes/viewshape.cxx index 836e0bd97928..b29afe8e4642 100644 --- a/slideshow/source/engine/shapes/viewshape.cxx +++ b/slideshow/source/engine/shapes/viewshape.cxx @@ -248,8 +248,7 @@ namespace slideshow::internal // transformation might result in smaller // overall bounds. - ::basegfx::B2DRectangle aBoundsPixel; - ::canvas::tools::calcTransformedRectBounds( aBoundsPixel, + ::basegfx::B2DRectangle aBoundsPixel = ::canvas::tools::calcTransformedRectBounds( rUntransformedArea, rCanvasTransformation ); @@ -339,11 +338,9 @@ namespace slideshow::internal // char scaling). NOTE: to cancel the shape translation, // contained in rSpriteBoundsPixel, this is _without_ any // translational component. - ::basegfx::B2DRectangle aLogShapeBounds; const ::basegfx::B2DRectangle aNominalShapeBoundsPixel( shapeArea2AreaPixel( aCanvasTransform, ::canvas::tools::calcTransformedRectBounds( - aLogShapeBounds, ::basegfx::B2DRectangle(0.0,0.0,1.0,1.0), aNonTranslationalShapeTransformation ) ) ); @@ -582,8 +579,7 @@ namespace slideshow::internal // area_ in device pixel const ::basegfx::B2DHomMatrix aCanvasTransform( rDestinationCanvas->getTransformation() ); - ::basegfx::B2DRectangle aTmpRect; - ::canvas::tools::calcTransformedRectBounds( aTmpRect, + ::basegfx::B2DRectangle aTmpRect = ::canvas::tools::calcTransformedRectBounds( rUpdateBounds, aCanvasTransform ); diff --git a/slideshow/source/engine/slide/slideimpl.cxx b/slideshow/source/engine/slide/slideimpl.cxx index 6b7d92e78648..6e758c995711 100644 --- a/slideshow/source/engine/slide/slideimpl.cxx +++ b/slideshow/source/engine/slide/slideimpl.cxx @@ -72,8 +72,7 @@ basegfx::B2IVector getSlideSizePixel(const basegfx::B2DVector& rSlideSize, { const basegfx::B2DRange aRect(0, 0, rSlideSize.getX(), rSlideSize.getY()); - basegfx::B2DRange aTmpRect; - canvas::tools::calcTransformedRectBounds(aTmpRect, aRect, rTransformation); + basegfx::B2DRange aTmpRect = canvas::tools::calcTransformedRectBounds(aRect, rTransformation); // #i42440# Returned slide size is one pixel too small, as // rendering happens one pixel to the right and below the diff --git a/slideshow/source/engine/slideview.cxx b/slideshow/source/engine/slideview.cxx index 3e6d0b6ab624..44f7c3a0e4d3 100644 --- a/slideshow/source/engine/slideview.cxx +++ b/slideshow/source/engine/slideview.cxx @@ -213,8 +213,7 @@ void clearRect( ::cppcanvas::CanvasSharedPtr const& pCanvas, basegfx::B2IRange getLayerBoundsPixel( basegfx::B2DRange const& rLayerBounds, basegfx::B2DHomMatrix const& rTransformation ) { - ::basegfx::B2DRange aTmpRect; - ::canvas::tools::calcTransformedRectBounds( aTmpRect, + ::basegfx::B2DRange aTmpRect = ::canvas::tools::calcTransformedRectBounds( rLayerBounds, rTransformation ); @@ -464,8 +463,7 @@ public: virtual css::geometry::IntegerSize2D getTranslationOffset() const override { - basegfx::B2DRectangle aTmpRect; - canvas::tools::calcTransformedRectBounds( aTmpRect, + basegfx::B2DRectangle aTmpRect = canvas::tools::calcTransformedRectBounds( maLayerBounds, maTransformation ); geometry::IntegerSize2D offset(0, 0); @@ -514,8 +512,7 @@ private: { // Offset given transformation by left, top border of given // range (after transformation through given transformation) - basegfx::B2DRectangle aTmpRect; - canvas::tools::calcTransformedRectBounds( aTmpRect, + basegfx::B2DRectangle aTmpRect = canvas::tools::calcTransformedRectBounds( maLayerBounds, maTransformation ); diff --git a/slideshow/source/engine/tools.cxx b/slideshow/source/engine/tools.cxx index 6f19dad8a405..4e55fe430d5d 100644 --- a/slideshow/source/engine/tools.cxx +++ b/slideshow/source/engine/tools.cxx @@ -561,11 +561,8 @@ namespace slideshow::internal aTransform *= rShapeTransform; - ::basegfx::B2DRectangle aRes; - // apply shape transformation to unit rect return ::canvas::tools::calcTransformedRectBounds( - aRes, rUnitBounds, aTransform ); } @@ -764,8 +761,7 @@ namespace slideshow::internal const basegfx::B2DRange aRect( 0,0, rSlideSize.getX(), rSlideSize.getY() ); - basegfx::B2DRange aTmpRect; - canvas::tools::calcTransformedRectBounds( aTmpRect, + basegfx::B2DRange aTmpRect = canvas::tools::calcTransformedRectBounds( aRect, pView->getTransformation() );