1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <VPolarTransformation.hxx>
22 using namespace ::com::sun::star
;
24 using ::com::sun::star::uno::Sequence
;
29 VPolarTransformation::VPolarTransformation( const PolarPlottingPositionHelper
& rPositionHelper
)
30 : m_aPositionHelper(rPositionHelper
)
31 , m_aUnitCartesianToScene( rPositionHelper
.getUnitCartesianToScene() )
35 VPolarTransformation::~VPolarTransformation()
39 // ____ XTransformation2 ____
40 css::drawing::Position3D
VPolarTransformation::transform(
41 const Sequence
< double >& rSourceValues
) const
43 double fScaledLogicAngle
= rSourceValues
[0];
44 double fScaledLogicRadius
= rSourceValues
[1];
46 if( m_aPositionHelper
.isSwapXAndY() )
47 std::swap(fScaledLogicAngle
,fScaledLogicRadius
);
49 double fAngleDegree
= m_aPositionHelper
.transformToAngleDegree( fScaledLogicAngle
, false );
50 double fAnglePi
= basegfx::deg2rad(fAngleDegree
);
51 double fRadius
= m_aPositionHelper
.transformToRadius( fScaledLogicRadius
, false);
53 double fX
=fRadius
*cos(fAnglePi
);
54 double fY
=fRadius
*sin(fAnglePi
);
55 double fZ
=rSourceValues
[2];
57 //!! applying matrix to vector does ignore translation, so it is important to use a B3DPoint here instead of B3DVector
58 ::basegfx::B3DPoint
aPoint(fX
,fY
,fZ
);
59 ::basegfx::B3DPoint aRet
= m_aUnitCartesianToScene
* aPoint
;
60 return css::drawing::Position3D(aRet
.getX(), aRet
.getY(), aRet
.getZ());
63 css::drawing::Position3D
VPolarTransformation::transform(
64 const css::drawing::Position3D
& rSourceValues
) const
66 double fScaledLogicAngle
= rSourceValues
.PositionX
;
67 double fScaledLogicRadius
= rSourceValues
.PositionY
;
69 if( m_aPositionHelper
.isSwapXAndY() )
70 std::swap(fScaledLogicAngle
,fScaledLogicRadius
);
72 double fAngleDegree
= m_aPositionHelper
.transformToAngleDegree( fScaledLogicAngle
, false );
73 double fAnglePi
= basegfx::deg2rad(fAngleDegree
);
74 double fRadius
= m_aPositionHelper
.transformToRadius( fScaledLogicRadius
, false);
76 double fX
=fRadius
*cos(fAnglePi
);
77 double fY
=fRadius
*sin(fAnglePi
);
78 double fZ
=rSourceValues
.PositionZ
;
80 //!! applying matrix to vector does ignore translation, so it is important to use a B3DPoint here instead of B3DVector
81 ::basegfx::B3DPoint
aPoint(fX
,fY
,fZ
);
82 ::basegfx::B3DPoint aRet
= m_aUnitCartesianToScene
* aPoint
;
83 return css::drawing::Position3D(aRet
.getX(), aRet
.getY(), aRet
.getZ());
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */