Bump for 3.6-28
[LibreOffice.git] / chart2 / source / tools / BaseGFXHelper.cxx
blobe76958576033f150572bb695d19ed4af7a46788e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "BaseGFXHelper.hxx"
31 #include <com/sun/star/drawing/DoubleSequence.hpp>
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::drawing;
35 using namespace ::basegfx;
37 namespace chart
39 namespace BaseGFXHelper
42 ::basegfx::B3DRange getBoundVolume( const drawing::PolyPolygonShape3D& rPolyPoly )
44 ::basegfx::B3DRange aRet;
46 bool bInited = false;
47 sal_Int32 nPolyCount = rPolyPoly.SequenceX.getLength();
48 for(sal_Int32 nPoly = 0; nPoly < nPolyCount; nPoly++)
50 sal_Int32 nPointCount = rPolyPoly.SequenceX[nPoly].getLength();
51 for( sal_Int32 nPoint = 0; nPoint < nPointCount; nPoint++)
53 if(!bInited)
55 aRet = ::basegfx::B3DRange(::basegfx::B3DTuple(
56 rPolyPoly.SequenceX[nPoly][nPoint]
57 , rPolyPoly.SequenceY[nPoly][nPoint]
58 , rPolyPoly.SequenceZ[nPoly][nPoint]));
59 bInited = true;
61 else
63 aRet.expand( ::basegfx::B3DTuple(
64 rPolyPoly.SequenceX[nPoly][nPoint]
65 , rPolyPoly.SequenceY[nPoly][nPoint]
66 , rPolyPoly.SequenceZ[nPoly][nPoint]));
71 return aRet;
74 B2IRectangle makeRectangle( const awt::Point& rPos, const awt::Size& rSize )
76 return B2IRectangle(rPos.X,rPos.Y,rPos.X+rSize.Width,rPos.Y+rSize.Height);
79 awt::Point B2IRectangleToAWTPoint( const ::basegfx::B2IRectangle& rB2IRectangle )
81 return awt::Point( rB2IRectangle.getMinX(), rB2IRectangle.getMinY() );
84 awt::Size B2IRectangleToAWTSize( const ::basegfx::B2IRectangle& rB2IRectangle )
86 return awt::Size( static_cast< sal_Int32 >( rB2IRectangle.getWidth()),
87 static_cast< sal_Int32 >( rB2IRectangle.getHeight()));
90 awt::Rectangle B2IRectangleToAWTRectangle(
91 const ::basegfx::B2IRectangle& rB2IRectangle )
93 return awt::Rectangle( rB2IRectangle.getMinX(), rB2IRectangle.getMinY(),
94 static_cast< sal_Int32 >( rB2IRectangle.getWidth()),
95 static_cast< sal_Int32 >( rB2IRectangle.getHeight()));
98 B3DVector Direction3DToB3DVector( const Direction3D& rDirection )
100 return B3DVector(
101 rDirection.DirectionX
102 , rDirection.DirectionY
103 , rDirection.DirectionZ
107 Direction3D B3DVectorToDirection3D( const B3DVector& rB3DVector )
109 return Direction3D(
110 rB3DVector.getX()
111 , rB3DVector.getY()
112 , rB3DVector.getZ()
116 B3DVector Position3DToB3DVector( const Position3D& rPosition )
118 return B3DVector(
119 rPosition.PositionX
120 , rPosition.PositionY
121 , rPosition.PositionZ
125 Position3D B3DVectorToPosition3D( const B3DVector& rB3DVector )
127 return Position3D(
128 rB3DVector.getX()
129 , rB3DVector.getY()
130 , rB3DVector.getZ()
134 B3DHomMatrix HomogenMatrixToB3DHomMatrix( const HomogenMatrix & rHomogenMatrix )
136 B3DHomMatrix aResult;
138 aResult.set( 0, 0, rHomogenMatrix.Line1.Column1 );
139 aResult.set( 0, 1, rHomogenMatrix.Line1.Column2 );
140 aResult.set( 0, 2, rHomogenMatrix.Line1.Column3 );
141 aResult.set( 0, 3, rHomogenMatrix.Line1.Column4 );
143 aResult.set( 1, 0, rHomogenMatrix.Line2.Column1 );
144 aResult.set( 1, 1, rHomogenMatrix.Line2.Column2 );
145 aResult.set( 1, 2, rHomogenMatrix.Line2.Column3 );
146 aResult.set( 1, 3, rHomogenMatrix.Line2.Column4 );
148 aResult.set( 2, 0, rHomogenMatrix.Line3.Column1 );
149 aResult.set( 2, 1, rHomogenMatrix.Line3.Column2 );
150 aResult.set( 2, 2, rHomogenMatrix.Line3.Column3 );
151 aResult.set( 2, 3, rHomogenMatrix.Line3.Column4 );
153 aResult.set( 3, 0, rHomogenMatrix.Line4.Column1 );
154 aResult.set( 3, 1, rHomogenMatrix.Line4.Column2 );
155 aResult.set( 3, 2, rHomogenMatrix.Line4.Column3 );
156 aResult.set( 3, 3, rHomogenMatrix.Line4.Column4 );
158 return aResult;
161 HomogenMatrix B3DHomMatrixToHomogenMatrix( const B3DHomMatrix & rB3DMatrix )
163 HomogenMatrix aResult;
165 aResult.Line1.Column1 = rB3DMatrix.get( 0, 0 );
166 aResult.Line1.Column2 = rB3DMatrix.get( 0, 1 );
167 aResult.Line1.Column3 = rB3DMatrix.get( 0, 2 );
168 aResult.Line1.Column4 = rB3DMatrix.get( 0, 3 );
170 aResult.Line2.Column1 = rB3DMatrix.get( 1, 0 );
171 aResult.Line2.Column2 = rB3DMatrix.get( 1, 1 );
172 aResult.Line2.Column3 = rB3DMatrix.get( 1, 2 );
173 aResult.Line2.Column4 = rB3DMatrix.get( 1, 3 );
175 aResult.Line3.Column1 = rB3DMatrix.get( 2, 0 );
176 aResult.Line3.Column2 = rB3DMatrix.get( 2, 1 );
177 aResult.Line3.Column3 = rB3DMatrix.get( 2, 2 );
178 aResult.Line3.Column4 = rB3DMatrix.get( 2, 3 );
180 aResult.Line4.Column1 = rB3DMatrix.get( 3, 0 );
181 aResult.Line4.Column2 = rB3DMatrix.get( 3, 1 );
182 aResult.Line4.Column3 = rB3DMatrix.get( 3, 2 );
183 aResult.Line4.Column4 = rB3DMatrix.get( 3, 3 );
185 return aResult;
188 B3DTuple GetRotationFromMatrix( const B3DHomMatrix & rB3DMatrix )
190 B3DTuple aScale, aTranslation, aRotation, aShearing;
191 rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
192 return aRotation;
195 B3DTuple GetScaleFromMatrix( const B3DHomMatrix & rB3DMatrix )
197 B3DTuple aScale, aTranslation, aRotation, aShearing;
198 rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
199 return aScale;
202 void ReduceToRotationMatrix( ::basegfx::B3DHomMatrix & rB3DMatrix )
204 B3DTuple aR( GetRotationFromMatrix( rB3DMatrix ) );
205 ::basegfx::B3DHomMatrix aRotationMatrix;
206 aRotationMatrix.rotate(aR.getX(),aR.getY(),aR.getZ());
207 rB3DMatrix = aRotationMatrix;
210 double Deg2Rad( double fDegrees )
212 return fDegrees * ( F_PI / 180.0 );
215 double Rad2Deg( double fRadians )
217 return fRadians * ( 180.0 / F_PI );
220 } // namespace BaseGFXHelper
221 } // namespace chart
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */