merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / tools / BaseGFXHelper.cxx
blob0ec7df9b7d71c529654fcf6a74ab968a2162ca0b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "BaseGFXHelper.hxx"
32 #include <com/sun/star/drawing/DoubleSequence.hpp>
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::drawing;
36 using namespace ::basegfx;
38 namespace chart
40 namespace BaseGFXHelper
43 ::basegfx::B3DRange getBoundVolume( const drawing::PolyPolygonShape3D& rPolyPoly )
45 ::basegfx::B3DRange aRet;
47 bool bInited = false;
48 sal_Int32 nPolyCount = rPolyPoly.SequenceX.getLength();
49 for(sal_Int32 nPoly = 0; nPoly < nPolyCount; nPoly++)
51 sal_Int32 nPointCount = rPolyPoly.SequenceX[nPoly].getLength();
52 for( sal_Int32 nPoint = 0; nPoint < nPointCount; nPoint++)
54 if(!bInited)
56 aRet = ::basegfx::B3DRange(::basegfx::B3DTuple(
57 rPolyPoly.SequenceX[nPoly][nPoint]
58 , rPolyPoly.SequenceY[nPoly][nPoint]
59 , rPolyPoly.SequenceZ[nPoly][nPoint]));
60 bInited = true;
62 else
64 aRet.expand( ::basegfx::B3DTuple(
65 rPolyPoly.SequenceX[nPoly][nPoint]
66 , rPolyPoly.SequenceY[nPoly][nPoint]
67 , rPolyPoly.SequenceZ[nPoly][nPoint]));
72 return aRet;
75 B2IRectangle makeRectangle( const awt::Point& rPos, const awt::Size& rSize )
77 return B2IRectangle(rPos.X,rPos.Y,rPos.X+rSize.Width,rPos.Y+rSize.Height);
80 awt::Point B2IRectangleToAWTPoint( const ::basegfx::B2IRectangle& rB2IRectangle )
82 return awt::Point( rB2IRectangle.getMinX(), rB2IRectangle.getMinY() );
85 awt::Size B2IRectangleToAWTSize( const ::basegfx::B2IRectangle& rB2IRectangle )
87 return awt::Size( static_cast< sal_Int32 >( rB2IRectangle.getWidth()),
88 static_cast< sal_Int32 >( rB2IRectangle.getHeight()));
91 awt::Rectangle B2IRectangleToAWTRectangle(
92 const ::basegfx::B2IRectangle& rB2IRectangle )
94 return awt::Rectangle( rB2IRectangle.getMinX(), rB2IRectangle.getMinY(),
95 static_cast< sal_Int32 >( rB2IRectangle.getWidth()),
96 static_cast< sal_Int32 >( rB2IRectangle.getHeight()));
99 B3DVector Direction3DToB3DVector( const Direction3D& rDirection )
101 return B3DVector(
102 rDirection.DirectionX
103 , rDirection.DirectionY
104 , rDirection.DirectionZ
108 Direction3D B3DVectorToDirection3D( const B3DVector& rB3DVector )
110 return Direction3D(
111 rB3DVector.getX()
112 , rB3DVector.getY()
113 , rB3DVector.getZ()
117 B3DVector Position3DToB3DVector( const Position3D& rPosition )
119 return B3DVector(
120 rPosition.PositionX
121 , rPosition.PositionY
122 , rPosition.PositionZ
126 Position3D B3DVectorToPosition3D( const B3DVector& rB3DVector )
128 return Position3D(
129 rB3DVector.getX()
130 , rB3DVector.getY()
131 , rB3DVector.getZ()
135 B3DHomMatrix HomogenMatrixToB3DHomMatrix( const HomogenMatrix & rHomogenMatrix )
137 B3DHomMatrix aResult;
139 aResult.set( 0, 0, rHomogenMatrix.Line1.Column1 );
140 aResult.set( 0, 1, rHomogenMatrix.Line1.Column2 );
141 aResult.set( 0, 2, rHomogenMatrix.Line1.Column3 );
142 aResult.set( 0, 3, rHomogenMatrix.Line1.Column4 );
144 aResult.set( 1, 0, rHomogenMatrix.Line2.Column1 );
145 aResult.set( 1, 1, rHomogenMatrix.Line2.Column2 );
146 aResult.set( 1, 2, rHomogenMatrix.Line2.Column3 );
147 aResult.set( 1, 3, rHomogenMatrix.Line2.Column4 );
149 aResult.set( 2, 0, rHomogenMatrix.Line3.Column1 );
150 aResult.set( 2, 1, rHomogenMatrix.Line3.Column2 );
151 aResult.set( 2, 2, rHomogenMatrix.Line3.Column3 );
152 aResult.set( 2, 3, rHomogenMatrix.Line3.Column4 );
154 aResult.set( 3, 0, rHomogenMatrix.Line4.Column1 );
155 aResult.set( 3, 1, rHomogenMatrix.Line4.Column2 );
156 aResult.set( 3, 2, rHomogenMatrix.Line4.Column3 );
157 aResult.set( 3, 3, rHomogenMatrix.Line4.Column4 );
159 return aResult;
162 HomogenMatrix B3DHomMatrixToHomogenMatrix( const B3DHomMatrix & rB3DMatrix )
164 HomogenMatrix aResult;
166 aResult.Line1.Column1 = rB3DMatrix.get( 0, 0 );
167 aResult.Line1.Column2 = rB3DMatrix.get( 0, 1 );
168 aResult.Line1.Column3 = rB3DMatrix.get( 0, 2 );
169 aResult.Line1.Column4 = rB3DMatrix.get( 0, 3 );
171 aResult.Line2.Column1 = rB3DMatrix.get( 1, 0 );
172 aResult.Line2.Column2 = rB3DMatrix.get( 1, 1 );
173 aResult.Line2.Column3 = rB3DMatrix.get( 1, 2 );
174 aResult.Line2.Column4 = rB3DMatrix.get( 1, 3 );
176 aResult.Line3.Column1 = rB3DMatrix.get( 2, 0 );
177 aResult.Line3.Column2 = rB3DMatrix.get( 2, 1 );
178 aResult.Line3.Column3 = rB3DMatrix.get( 2, 2 );
179 aResult.Line3.Column4 = rB3DMatrix.get( 2, 3 );
181 aResult.Line4.Column1 = rB3DMatrix.get( 3, 0 );
182 aResult.Line4.Column2 = rB3DMatrix.get( 3, 1 );
183 aResult.Line4.Column3 = rB3DMatrix.get( 3, 2 );
184 aResult.Line4.Column4 = rB3DMatrix.get( 3, 3 );
186 return aResult;
189 B3DTuple GetRotationFromMatrix( const B3DHomMatrix & rB3DMatrix )
191 B3DTuple aScale, aTranslation, aRotation, aShearing;
192 rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
193 return aRotation;
196 B3DTuple GetScaleFromMatrix( const B3DHomMatrix & rB3DMatrix )
198 B3DTuple aScale, aTranslation, aRotation, aShearing;
199 rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
200 return aScale;
203 void ReduceToRotationMatrix( ::basegfx::B3DHomMatrix & rB3DMatrix )
205 B3DTuple aR( GetRotationFromMatrix( rB3DMatrix ) );
206 ::basegfx::B3DHomMatrix aRotationMatrix;
207 aRotationMatrix.rotate(aR.getX(),aR.getY(),aR.getZ());
208 rB3DMatrix = aRotationMatrix;
211 double Deg2Rad( double fDegrees )
213 return fDegrees * ( F_PI / 180.0 );
216 double Rad2Deg( double fRadians )
218 return fRadians * ( 180.0 / F_PI );
221 } // namespace BaseGFXHelper
222 } // namespace chart