tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / chart2 / source / tools / BaseGFXHelper.cxx
blob765521d6959c5ca0c7476f9121b2f51bd260e0d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <BaseGFXHelper.hxx>
21 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
22 #include <com/sun/star/awt/Rectangle.hpp>
24 using namespace ::com::sun::star;
25 using namespace ::com::sun::star::drawing;
26 using namespace ::basegfx;
28 namespace chart::BaseGFXHelper
31 ::basegfx::B3DRange getBoundVolume( const drawing::PolyPolygonShape3D& rPolyPoly )
33 ::basegfx::B3DRange aRet;
35 bool bInited = false;
36 sal_Int32 nPolyCount = rPolyPoly.SequenceX.getLength();
37 for(sal_Int32 nPoly = 0; nPoly < nPolyCount; nPoly++)
39 sal_Int32 nPointCount = rPolyPoly.SequenceX[nPoly].getLength();
40 for( sal_Int32 nPoint = 0; nPoint < nPointCount; nPoint++)
42 if(!bInited)
44 aRet = ::basegfx::B3DRange(::basegfx::B3DTuple(
45 rPolyPoly.SequenceX[nPoly][nPoint]
46 , rPolyPoly.SequenceY[nPoly][nPoint]
47 , rPolyPoly.SequenceZ[nPoly][nPoint]));
48 bInited = true;
50 else
52 aRet.expand( ::basegfx::B3DTuple(
53 rPolyPoly.SequenceX[nPoly][nPoint]
54 , rPolyPoly.SequenceY[nPoly][nPoint]
55 , rPolyPoly.SequenceZ[nPoly][nPoint]));
60 return aRet;
63 ::basegfx::B3DRange getBoundVolume( const std::vector<std::vector<css::drawing::Position3D>>& rPolyPoly )
65 ::basegfx::B3DRange aRet;
67 bool bInited = false;
68 sal_Int32 nPolyCount = rPolyPoly.size();
69 for(sal_Int32 nPoly = 0; nPoly < nPolyCount; nPoly++)
71 sal_Int32 nPointCount = rPolyPoly[nPoly].size();
72 for( sal_Int32 nPoint = 0; nPoint < nPointCount; nPoint++)
74 if(!bInited)
76 aRet = ::basegfx::B3DRange(::basegfx::B3DTuple(
77 rPolyPoly[nPoly][nPoint].PositionX
78 , rPolyPoly[nPoly][nPoint].PositionY
79 , rPolyPoly[nPoly][nPoint].PositionZ));
80 bInited = true;
82 else
84 aRet.expand( ::basegfx::B3DTuple(
85 rPolyPoly[nPoly][nPoint].PositionX
86 , rPolyPoly[nPoly][nPoint].PositionY
87 , rPolyPoly[nPoly][nPoint].PositionZ));
92 return aRet;
95 B2IRectangle makeRectangle( const awt::Point& rPos, const awt::Size& rSize )
97 return B2IRectangle(rPos.X,rPos.Y,rPos.X+rSize.Width,rPos.Y+rSize.Height);
100 B2IRectangle makeRectangle( const awt::Rectangle& rRect )
102 return B2IRectangle(rRect.X, rRect.Y, rRect.X+rRect.Width, rRect.Y+rRect.Height);
105 awt::Point B2IRectangleToAWTPoint( const ::basegfx::B2IRectangle& rB2IRectangle )
107 return awt::Point( rB2IRectangle.getMinX(), rB2IRectangle.getMinY() );
110 awt::Size B2IRectangleToAWTSize( const ::basegfx::B2IRectangle& rB2IRectangle )
112 return awt::Size( static_cast< sal_Int32 >( rB2IRectangle.getWidth()),
113 static_cast< sal_Int32 >( rB2IRectangle.getHeight()));
116 awt::Rectangle toAwtRectangle(const basegfx::B2IRectangle& rRectangle)
118 return awt::Rectangle(rRectangle.getMinX(), rRectangle.getMinY(),
119 rRectangle.getWidth(), rRectangle.getHeight());
122 B3DVector Direction3DToB3DVector( const Direction3D& rDirection )
124 return B3DVector(
125 rDirection.DirectionX
126 , rDirection.DirectionY
127 , rDirection.DirectionZ
131 Direction3D B3DVectorToDirection3D( const B3DVector& rB3DVector )
133 return Direction3D(
134 rB3DVector.getX()
135 , rB3DVector.getY()
136 , rB3DVector.getZ()
140 B3DVector Position3DToB3DVector( const Position3D& rPosition )
142 return B3DVector(
143 rPosition.PositionX
144 , rPosition.PositionY
145 , rPosition.PositionZ
149 Position3D B3DVectorToPosition3D( const B3DVector& rB3DVector )
151 return Position3D(
152 rB3DVector.getX()
153 , rB3DVector.getY()
154 , rB3DVector.getZ()
158 B3DHomMatrix HomogenMatrixToB3DHomMatrix( const HomogenMatrix & rHomogenMatrix )
160 B3DHomMatrix aResult;
162 aResult.set( 0, 0, rHomogenMatrix.Line1.Column1 );
163 aResult.set( 0, 1, rHomogenMatrix.Line1.Column2 );
164 aResult.set( 0, 2, rHomogenMatrix.Line1.Column3 );
165 aResult.set( 0, 3, rHomogenMatrix.Line1.Column4 );
167 aResult.set( 1, 0, rHomogenMatrix.Line2.Column1 );
168 aResult.set( 1, 1, rHomogenMatrix.Line2.Column2 );
169 aResult.set( 1, 2, rHomogenMatrix.Line2.Column3 );
170 aResult.set( 1, 3, rHomogenMatrix.Line2.Column4 );
172 aResult.set( 2, 0, rHomogenMatrix.Line3.Column1 );
173 aResult.set( 2, 1, rHomogenMatrix.Line3.Column2 );
174 aResult.set( 2, 2, rHomogenMatrix.Line3.Column3 );
175 aResult.set( 2, 3, rHomogenMatrix.Line3.Column4 );
177 aResult.set( 3, 0, rHomogenMatrix.Line4.Column1 );
178 aResult.set( 3, 1, rHomogenMatrix.Line4.Column2 );
179 aResult.set( 3, 2, rHomogenMatrix.Line4.Column3 );
180 aResult.set( 3, 3, rHomogenMatrix.Line4.Column4 );
182 return aResult;
185 HomogenMatrix B3DHomMatrixToHomogenMatrix( const B3DHomMatrix & rB3DMatrix )
187 HomogenMatrix aResult;
189 aResult.Line1.Column1 = rB3DMatrix.get( 0, 0 );
190 aResult.Line1.Column2 = rB3DMatrix.get( 0, 1 );
191 aResult.Line1.Column3 = rB3DMatrix.get( 0, 2 );
192 aResult.Line1.Column4 = rB3DMatrix.get( 0, 3 );
194 aResult.Line2.Column1 = rB3DMatrix.get( 1, 0 );
195 aResult.Line2.Column2 = rB3DMatrix.get( 1, 1 );
196 aResult.Line2.Column3 = rB3DMatrix.get( 1, 2 );
197 aResult.Line2.Column4 = rB3DMatrix.get( 1, 3 );
199 aResult.Line3.Column1 = rB3DMatrix.get( 2, 0 );
200 aResult.Line3.Column2 = rB3DMatrix.get( 2, 1 );
201 aResult.Line3.Column3 = rB3DMatrix.get( 2, 2 );
202 aResult.Line3.Column4 = rB3DMatrix.get( 2, 3 );
204 aResult.Line4.Column1 = rB3DMatrix.get( 3, 0 );
205 aResult.Line4.Column2 = rB3DMatrix.get( 3, 1 );
206 aResult.Line4.Column3 = rB3DMatrix.get( 3, 2 );
207 aResult.Line4.Column4 = rB3DMatrix.get( 3, 3 );
209 return aResult;
212 B3DTuple GetRotationFromMatrix( const B3DHomMatrix & rB3DMatrix )
214 B3DTuple aScale, aTranslation, aRotation, aShearing;
215 rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
216 return aRotation;
219 B3DTuple GetScaleFromMatrix( const B3DHomMatrix & rB3DMatrix )
221 B3DTuple aScale, aTranslation, aRotation, aShearing;
222 rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
223 return aScale;
226 void ReduceToRotationMatrix( ::basegfx::B3DHomMatrix & rB3DMatrix )
228 B3DTuple aR( GetRotationFromMatrix( rB3DMatrix ) );
229 ::basegfx::B3DHomMatrix aRotationMatrix;
230 aRotationMatrix.rotate(aR.getX(),aR.getY(),aR.getZ());
231 rB3DMatrix = std::move(aRotationMatrix);
234 } // namespace chart::BaseGFXHelper
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */