Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/tools/BaseGFXHelper.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#include <BaseGFXHelper.hxx>
21
#include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
22
#include <com/sun/star/awt/Rectangle.hpp>
23
24
using namespace ::com::sun::star;
25
using namespace ::com::sun::star::drawing;
26
using namespace ::basegfx;
27
28
namespace chart::BaseGFXHelper
29
{
30
31
::basegfx::B3DRange getBoundVolume( const drawing::PolyPolygonShape3D& rPolyPoly )
32
0
{
33
0
    ::basegfx::B3DRange aRet;
34
35
0
    bool bInited = false;
36
0
    sal_Int32 nPolyCount = rPolyPoly.SequenceX.getLength();
37
0
    for(sal_Int32 nPoly = 0; nPoly < nPolyCount; nPoly++)
38
0
    {
39
0
        sal_Int32 nPointCount = rPolyPoly.SequenceX[nPoly].getLength();
40
0
        for( sal_Int32 nPoint = 0; nPoint < nPointCount; nPoint++)
41
0
        {
42
0
            if(!bInited)
43
0
            {
44
0
                aRet = ::basegfx::B3DRange(::basegfx::B3DTuple(
45
0
                          rPolyPoly.SequenceX[nPoly][nPoint]
46
0
                        , rPolyPoly.SequenceY[nPoly][nPoint]
47
0
                        , rPolyPoly.SequenceZ[nPoly][nPoint]));
48
0
                bInited = true;
49
0
            }
50
0
            else
51
0
            {
52
0
                aRet.expand( ::basegfx::B3DTuple(
53
0
                          rPolyPoly.SequenceX[nPoly][nPoint]
54
0
                        , rPolyPoly.SequenceY[nPoly][nPoint]
55
0
                        , rPolyPoly.SequenceZ[nPoly][nPoint]));
56
0
            }
57
0
        }
58
0
    }
59
60
0
    return aRet;
61
0
}
62
63
::basegfx::B3DRange getBoundVolume( const std::vector<std::vector<css::drawing::Position3D>>& rPolyPoly )
64
0
{
65
0
    ::basegfx::B3DRange aRet;
66
67
0
    bool bInited = false;
68
0
    sal_Int32 nPolyCount = rPolyPoly.size();
69
0
    for(sal_Int32 nPoly = 0; nPoly < nPolyCount; nPoly++)
70
0
    {
71
0
        sal_Int32 nPointCount = rPolyPoly[nPoly].size();
72
0
        for( sal_Int32 nPoint = 0; nPoint < nPointCount; nPoint++)
73
0
        {
74
0
            if(!bInited)
75
0
            {
76
0
                aRet = ::basegfx::B3DRange(::basegfx::B3DTuple(
77
0
                          rPolyPoly[nPoly][nPoint].PositionX
78
0
                        , rPolyPoly[nPoly][nPoint].PositionY
79
0
                        , rPolyPoly[nPoly][nPoint].PositionZ));
80
0
                bInited = true;
81
0
            }
82
0
            else
83
0
            {
84
0
                aRet.expand( ::basegfx::B3DTuple(
85
0
                          rPolyPoly[nPoly][nPoint].PositionX
86
0
                        , rPolyPoly[nPoly][nPoint].PositionY
87
0
                        , rPolyPoly[nPoly][nPoint].PositionZ));
88
0
            }
89
0
        }
90
0
    }
91
92
0
    return aRet;
93
0
}
94
95
B2IRectangle makeRectangle( const awt::Point& rPos, const awt::Size& rSize )
96
0
{
97
0
    return B2IRectangle(rPos.X,rPos.Y,rPos.X+rSize.Width,rPos.Y+rSize.Height);
98
0
}
99
100
B2IRectangle makeRectangle( const awt::Rectangle& rRect )
101
0
{
102
0
    return B2IRectangle(rRect.X, rRect.Y, rRect.X+rRect.Width, rRect.Y+rRect.Height);
103
0
}
104
105
awt::Point B2IRectangleToAWTPoint( const ::basegfx::B2IRectangle& rB2IRectangle )
106
0
{
107
0
    return awt::Point( rB2IRectangle.getMinX(), rB2IRectangle.getMinY() );
108
0
}
109
110
awt::Size B2IRectangleToAWTSize( const ::basegfx::B2IRectangle& rB2IRectangle )
111
0
{
112
0
    return awt::Size( static_cast< sal_Int32 >( rB2IRectangle.getWidth()),
113
0
                      static_cast< sal_Int32 >( rB2IRectangle.getHeight()));
114
0
}
115
116
awt::Rectangle toAwtRectangle(const basegfx::B2IRectangle& rRectangle)
117
0
{
118
0
    return awt::Rectangle(rRectangle.getMinX(), rRectangle.getMinY(),
119
0
                          rRectangle.getWidth(), rRectangle.getHeight());
120
0
}
121
122
B3DVector Direction3DToB3DVector( const Direction3D& rDirection )
123
0
{
124
0
    return B3DVector(
125
0
          rDirection.DirectionX
126
0
        , rDirection.DirectionY
127
0
        , rDirection.DirectionZ
128
0
        );
129
0
}
130
131
Direction3D B3DVectorToDirection3D( const B3DVector& rB3DVector )
132
0
{
133
0
    return Direction3D(
134
0
          rB3DVector.getX()
135
0
        , rB3DVector.getY()
136
0
        , rB3DVector.getZ()
137
0
        );
138
0
}
139
140
B3DVector Position3DToB3DVector( const Position3D& rPosition )
141
0
{
142
0
    return B3DVector(
143
0
          rPosition.PositionX
144
0
        , rPosition.PositionY
145
0
        , rPosition.PositionZ
146
0
        );
147
0
}
148
149
Position3D B3DVectorToPosition3D( const B3DVector& rB3DVector )
150
0
{
151
0
    return Position3D(
152
0
          rB3DVector.getX()
153
0
        , rB3DVector.getY()
154
0
        , rB3DVector.getZ()
155
0
        );
156
0
}
157
158
B3DHomMatrix HomogenMatrixToB3DHomMatrix( const HomogenMatrix & rHomogenMatrix )
159
0
{
160
0
    B3DHomMatrix aResult;
161
162
0
    aResult.set( 0, 0, rHomogenMatrix.Line1.Column1 );
163
0
    aResult.set( 0, 1, rHomogenMatrix.Line1.Column2 );
164
0
    aResult.set( 0, 2, rHomogenMatrix.Line1.Column3 );
165
0
    aResult.set( 0, 3, rHomogenMatrix.Line1.Column4 );
166
167
0
    aResult.set( 1, 0, rHomogenMatrix.Line2.Column1 );
168
0
    aResult.set( 1, 1, rHomogenMatrix.Line2.Column2 );
169
0
    aResult.set( 1, 2, rHomogenMatrix.Line2.Column3 );
170
0
    aResult.set( 1, 3, rHomogenMatrix.Line2.Column4 );
171
172
0
    aResult.set( 2, 0, rHomogenMatrix.Line3.Column1 );
173
0
    aResult.set( 2, 1, rHomogenMatrix.Line3.Column2 );
174
0
    aResult.set( 2, 2, rHomogenMatrix.Line3.Column3 );
175
0
    aResult.set( 2, 3, rHomogenMatrix.Line3.Column4 );
176
177
0
    aResult.set( 3, 0, rHomogenMatrix.Line4.Column1 );
178
0
    aResult.set( 3, 1, rHomogenMatrix.Line4.Column2 );
179
0
    aResult.set( 3, 2, rHomogenMatrix.Line4.Column3 );
180
0
    aResult.set( 3, 3, rHomogenMatrix.Line4.Column4 );
181
182
0
    return aResult;
183
0
}
184
185
HomogenMatrix B3DHomMatrixToHomogenMatrix( const B3DHomMatrix & rB3DMatrix )
186
0
{
187
0
    HomogenMatrix aResult;
188
189
0
    aResult.Line1.Column1 = rB3DMatrix.get( 0, 0 );
190
0
    aResult.Line1.Column2 = rB3DMatrix.get( 0, 1 );
191
0
    aResult.Line1.Column3 = rB3DMatrix.get( 0, 2 );
192
0
    aResult.Line1.Column4 = rB3DMatrix.get( 0, 3 );
193
194
0
    aResult.Line2.Column1 = rB3DMatrix.get( 1, 0 );
195
0
    aResult.Line2.Column2 = rB3DMatrix.get( 1, 1 );
196
0
    aResult.Line2.Column3 = rB3DMatrix.get( 1, 2 );
197
0
    aResult.Line2.Column4 = rB3DMatrix.get( 1, 3 );
198
199
0
    aResult.Line3.Column1 = rB3DMatrix.get( 2, 0 );
200
0
    aResult.Line3.Column2 = rB3DMatrix.get( 2, 1 );
201
0
    aResult.Line3.Column3 = rB3DMatrix.get( 2, 2 );
202
0
    aResult.Line3.Column4 = rB3DMatrix.get( 2, 3 );
203
204
0
    aResult.Line4.Column1 = rB3DMatrix.get( 3, 0 );
205
0
    aResult.Line4.Column2 = rB3DMatrix.get( 3, 1 );
206
0
    aResult.Line4.Column3 = rB3DMatrix.get( 3, 2 );
207
0
    aResult.Line4.Column4 = rB3DMatrix.get( 3, 3 );
208
209
0
    return aResult;
210
0
}
211
212
B3DTuple GetRotationFromMatrix( const B3DHomMatrix & rB3DMatrix )
213
0
{
214
0
    B3DTuple aScale, aTranslation, aRotation, aShearing;
215
0
    rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
216
0
    return aRotation;
217
0
}
218
219
B3DTuple GetScaleFromMatrix( const B3DHomMatrix & rB3DMatrix )
220
0
{
221
0
    B3DTuple aScale, aTranslation, aRotation, aShearing;
222
0
    rB3DMatrix.decompose( aScale, aTranslation, aRotation, aShearing );
223
0
    return aScale;
224
0
}
225
226
void ReduceToRotationMatrix( ::basegfx::B3DHomMatrix & rB3DMatrix )
227
0
{
228
0
    B3DTuple aR( GetRotationFromMatrix( rB3DMatrix ) );
229
0
    ::basegfx::B3DHomMatrix aRotationMatrix;
230
0
    aRotationMatrix.rotate(aR.getX(),aR.getY(),aR.getZ());
231
0
    rB3DMatrix = std::move(aRotationMatrix);
232
0
}
233
234
} //  namespace chart::BaseGFXHelper
235
236
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */