office-gobmx/chart2/source/tools/BaseGFXHelper.cxx
Caolán McNamara a4dfd23e44 cid#1557694 COPY_INSTEAD_OF_MOVE
and

cid#1557162 COPY_INSTEAD_OF_MOVE
cid#1556896 COPY_INSTEAD_OF_MOVE
cid#1556893 COPY_INSTEAD_OF_MOVE
cid#1556873 COPY_INSTEAD_OF_MOVE
cid#1556872 COPY_INSTEAD_OF_MOVE
cid#1556789 COPY_INSTEAD_OF_MOVE
cid#1556570 COPY_INSTEAD_OF_MOVE
cid#1556519 COPY_INSTEAD_OF_MOVE
cid#1556516 COPY_INSTEAD_OF_MOVE
cid#1556451 COPY_INSTEAD_OF_MOVE
cid#1556396 COPY_INSTEAD_OF_MOVE
cid#1556237 COPY_INSTEAD_OF_MOVE
cid#1556113 COPY_INSTEAD_OF_MOVE
cid#1556094 COPY_INSTEAD_OF_MOVE
cid#1555991 COPY_INSTEAD_OF_MOVE
cid#1555982 COPY_INSTEAD_OF_MOVE
cid#1555885 COPY_INSTEAD_OF_MOVE
cid#1555702 COPY_INSTEAD_OF_MOVE
cid#1555610 COPY_INSTEAD_OF_MOVE
cid#1555450 COPY_INSTEAD_OF_MOVE
cid#1555327 COPY_INSTEAD_OF_MOVE
cid#1555145 COPY_INSTEAD_OF_MOVE

Change-Id: I38cc1a38e8cb2c33f33e0fc3afd34a0fb39e5ec1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172028
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2024-08-19 15:15:54 +02:00

236 lines
7.6 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <BaseGFXHelper.hxx>
#include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
#include <com/sun/star/awt/Rectangle.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::drawing;
using namespace ::basegfx;
namespace chart::BaseGFXHelper
{
::basegfx::B3DRange getBoundVolume( const drawing::PolyPolygonShape3D& rPolyPoly )
{
::basegfx::B3DRange aRet;
bool bInited = false;
sal_Int32 nPolyCount = rPolyPoly.SequenceX.getLength();
for(sal_Int32 nPoly = 0; nPoly < nPolyCount; nPoly++)
{
sal_Int32 nPointCount = rPolyPoly.SequenceX[nPoly].getLength();
for( sal_Int32 nPoint = 0; nPoint < nPointCount; nPoint++)
{
if(!bInited)
{
aRet = ::basegfx::B3DRange(::basegfx::B3DTuple(
rPolyPoly.SequenceX[nPoly][nPoint]
, rPolyPoly.SequenceY[nPoly][nPoint]
, rPolyPoly.SequenceZ[nPoly][nPoint]));
bInited = true;
}
else
{
aRet.expand( ::basegfx::B3DTuple(
rPolyPoly.SequenceX[nPoly][nPoint]
, rPolyPoly.SequenceY[nPoly][nPoint]
, rPolyPoly.SequenceZ[nPoly][nPoint]));
}
}
}
return aRet;
}
::basegfx::B3DRange getBoundVolume( const std::vector<std::vector<css::drawing::Position3D>>& rPolyPoly )
{
::basegfx::B3DRange aRet;
bool bInited = false;
sal_Int32 nPolyCount = rPolyPoly.size();
for(sal_Int32 nPoly = 0; nPoly < nPolyCount; nPoly++)
{
sal_Int32 nPointCount = rPolyPoly[nPoly].size();
for( sal_Int32 nPoint = 0; nPoint < nPointCount; nPoint++)
{
if(!bInited)
{
aRet = ::basegfx::B3DRange(::basegfx::B3DTuple(
rPolyPoly[nPoly][nPoint].PositionX
, rPolyPoly[nPoly][nPoint].PositionY
, rPolyPoly[nPoly][nPoint].PositionZ));
bInited = true;
}
else
{
aRet.expand( ::basegfx::B3DTuple(
rPolyPoly[nPoly][nPoint].PositionX
, rPolyPoly[nPoly][nPoint].PositionY
, rPolyPoly[nPoly][nPoint].PositionZ));
}
}
}
return aRet;
}
B2IRectangle makeRectangle( const awt::Point& rPos, const awt::Size& rSize )
{
return B2IRectangle(rPos.X,rPos.Y,rPos.X+rSize.Width,rPos.Y+rSize.Height);
}
B2IRectangle makeRectangle( const awt::Rectangle& rRect )
{
return B2IRectangle(rRect.X, rRect.Y, rRect.X+rRect.Width, rRect.Y+rRect.Height);
}
awt::Point B2IRectangleToAWTPoint( const ::basegfx::B2IRectangle& rB2IRectangle )
{
return awt::Point( rB2IRectangle.getMinX(), rB2IRectangle.getMinY() );
}
awt::Size B2IRectangleToAWTSize( const ::basegfx::B2IRectangle& rB2IRectangle )
{
return awt::Size( static_cast< sal_Int32 >( rB2IRectangle.getWidth()),
static_cast< sal_Int32 >( rB2IRectangle.getHeight()));
}
awt::Rectangle toAwtRectangle(const basegfx::B2IRectangle& rRectangle)
{
return awt::Rectangle(rRectangle.getMinX(), rRectangle.getMinY(),
rRectangle.getWidth(), rRectangle.getHeight());
}
B3DVector Direction3DToB3DVector( const Direction3D& rDirection )
{
return B3DVector(
rDirection.DirectionX
, rDirection.DirectionY
, rDirection.DirectionZ
);
}
Direction3D B3DVectorToDirection3D( const B3DVector& rB3DVector )
{
return Direction3D(
rB3DVector.getX()
, rB3DVector.getY()
, rB3DVector.getZ()
);
}
B3DVector Position3DToB3DVector( const Position3D& rPosition )
{
return B3DVector(
rPosition.PositionX
, rPosition.PositionY
, rPosition.PositionZ
);
}
Position3D B3DVectorToPosition3D( const B3DVector& rB3DVector )
{
return Position3D(
rB3DVector.getX()
, rB3DVector.getY()
, rB3DVector.getZ()
);
}
B3DHomMatrix HomogenMatrixToB3DHomMatrix( const HomogenMatrix & rHomogenMatrix )
{
B3DHomMatrix aResult;
aResult.set( 0, 0, rHomogenMatrix.Line1.Column1 );
aResult.set( 0, 1, rHomogenMatrix.Line1.Column2 );
aResult.set( 0, 2, rHomogenMatrix.Line1.Column3 );
aResult.set( 0, 3, rHomogenMatrix.Line1.Column4 );
aResult.set( 1, 0, rHomogenMatrix.Line2.Column1 );
aResult.set( 1, 1, rHomogenMatrix.Line2.Column2 );
aResult.set( 1, 2, rHomogenMatrix.Line2.Column3 );
aResult.set( 1, 3, rHomogenMatrix.Line2.Column4 );
aResult.set( 2, 0, rHomogenMatrix.Line3.Column1 );
aResult.set( 2, 1, rHomogenMatrix.Line3.Column2 );
aResult.set( 2, 2, rHomogenMatrix.Line3.Column3 );
aResult.set( 2, 3, rHomogenMatrix.Line3.Column4 );
aResult.set( 3, 0, rHomogenMatrix.Line4.Column1 );
aResult.set( 3, 1, rHomogenMatrix.Line4.Column2 );
aResult.set( 3, 2, rHomogenMatrix.Line4.Column3 );
aResult.set( 3, 3, rHomogenMatrix.Line4.Column4 );
return aResult;
}
HomogenMatrix B3DHomMatrixToHomogenMatrix( const B3DHomMatrix & rB3DMatrix )
{
HomogenMatrix aResult;
aResult.Line1.Column1 = rB3DMatrix.get( 0, 0 );
aResult.Line1.Column2 = rB3DMatrix.get( 0, 1 );
aResult.Line1.Column3 = rB3DMatrix.get( 0, 2 );
aResult.Line1.Column4 = rB3DMatrix.get( 0, 3 );
aResult.Line2.Column1 = rB3DMatrix.get( 1, 0 );
aResult.Line2.Column2 = rB3DMatrix.get( 1, 1 );
aResult.Line2.Column3 = rB3DMatrix.get( 1, 2 );
aResult.Line2.Column4 = rB3DMatrix.get( 1, 3 );
aResult.Line3.Column1 = rB3DMatrix.get( 2, 0 );
aResult.Line3.Column2 = rB3DMatrix.get( 2, 1 );
aResult.Line3.Column3 = rB3DMatrix.get( 2, 2 );
aResult.Line3.Column4 = rB3DMatrix.get( 2, 3 );
aResult.Line4.Column1 = rB3DMatrix.get( 3, 0 );
aResult.Line4.Column2 = rB3DMatrix.get( 3, 1 );
aResult.Line4.Column3 = rB3DMatrix.get( 3, 2 );
aResult.Line4.Column4 = rB3DMatrix.get( 3, 3 );
return aResult;
}
B3DTuple GetRotationFromMatrix( const B3DHomMatrix & rB3DMatrix )
{
B3DTuple aScale, aTranslation, aRotation, aShearing;
rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
return aRotation;
}
B3DTuple GetScaleFromMatrix( const B3DHomMatrix & rB3DMatrix )
{
B3DTuple aScale, aTranslation, aRotation, aShearing;
rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
return aScale;
}
void ReduceToRotationMatrix( ::basegfx::B3DHomMatrix & rB3DMatrix )
{
B3DTuple aR( GetRotationFromMatrix( rB3DMatrix ) );
::basegfx::B3DHomMatrix aRotationMatrix;
aRotationMatrix.rotate(aR.getX(),aR.getY(),aR.getZ());
rB3DMatrix = std::move(aRotationMatrix);
}
} // namespace chart::BaseGFXHelper
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */