tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / chart2 / source / view / main / Stripe.cxx
blob74c8ad0468100e58e0a297c591f9a2c34e5ec08f
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 <Stripe.hxx>
21 #include <CommonConverters.hxx>
22 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
23 #include <com/sun/star/drawing/DoubleSequence.hpp>
24 #include <basegfx/polygon/b3dpolygon.hxx>
26 using namespace ::com::sun::star;
28 namespace chart
31 Stripe::Stripe( const drawing::Position3D& rPoint1
32 , const drawing::Direction3D& rDirectionToPoint2
33 , const drawing::Direction3D& rDirectionToPoint4 )
34 : m_aPoint1(rPoint1)
35 , m_aPoint2(rPoint1+rDirectionToPoint2)
36 , m_aPoint3(m_aPoint2+rDirectionToPoint4)
37 , m_aPoint4(rPoint1+rDirectionToPoint4)
38 , m_bInvertNormal(false)
39 , m_bManualNormalSet(false)
43 Stripe::Stripe( const drawing::Position3D& rPoint1
44 , const drawing::Position3D& rPoint2
45 , double fDepth )
46 : m_aPoint1(rPoint1)
47 , m_aPoint2(rPoint2)
48 , m_aPoint3(rPoint2)
49 , m_aPoint4(rPoint1)
50 , m_bInvertNormal(false)
51 , m_bManualNormalSet(false)
53 m_aPoint3.PositionZ += fDepth;
54 m_aPoint4.PositionZ += fDepth;
57 Stripe::Stripe( const drawing::Position3D& rPoint1
58 , const drawing::Position3D& rPoint2
59 , const drawing::Position3D& rPoint3
60 , const drawing::Position3D& rPoint4 )
61 : m_aPoint1(rPoint1)
62 , m_aPoint2(rPoint2)
63 , m_aPoint3(rPoint3)
64 , m_aPoint4(rPoint4)
65 , m_bInvertNormal(false)
66 , m_bManualNormalSet(false)
70 void Stripe::SetManualNormal( const drawing::Direction3D& rNormal )
72 m_aManualNormal = rNormal;
73 m_bManualNormalSet = true;
76 void Stripe::InvertNormal( bool bInvertNormal )
78 m_bInvertNormal = bInvertNormal;
81 uno::Any Stripe::getPolyPolygonShape3D() const
83 drawing::PolyPolygonShape3D aPP;
85 aPP.SequenceX.realloc(1);
86 aPP.SequenceY.realloc(1);
87 aPP.SequenceZ.realloc(1);
89 drawing::DoubleSequence* pOuterSequenceX = aPP.SequenceX.getArray();
90 drawing::DoubleSequence* pOuterSequenceY = aPP.SequenceY.getArray();
91 drawing::DoubleSequence* pOuterSequenceZ = aPP.SequenceZ.getArray();
93 pOuterSequenceX->realloc(4);
94 pOuterSequenceY->realloc(4);
95 pOuterSequenceZ->realloc(4);
97 double* pInnerSequenceX = pOuterSequenceX->getArray();
98 double* pInnerSequenceY = pOuterSequenceY->getArray();
99 double* pInnerSequenceZ = pOuterSequenceZ->getArray();
101 *pInnerSequenceX++ = m_aPoint1.PositionX;
102 *pInnerSequenceY++ = m_aPoint1.PositionY;
103 *pInnerSequenceZ++ = m_aPoint1.PositionZ;
105 *pInnerSequenceX++ = m_aPoint2.PositionX;
106 *pInnerSequenceY++ = m_aPoint2.PositionY;
107 *pInnerSequenceZ++ = m_aPoint2.PositionZ;
109 *pInnerSequenceX++ = m_aPoint3.PositionX;
110 *pInnerSequenceY++ = m_aPoint3.PositionY;
111 *pInnerSequenceZ++ = m_aPoint3.PositionZ;
113 *pInnerSequenceX++ = m_aPoint4.PositionX;
114 *pInnerSequenceY++ = m_aPoint4.PositionY;
115 *pInnerSequenceZ++ = m_aPoint4.PositionZ;
117 return uno::Any( &aPP, cppu::UnoType<drawing::PolyPolygonShape3D>::get());
120 drawing::Direction3D Stripe::getNormal() const
122 drawing::Direction3D aRet(1.0,0.0,0.0);
124 if( m_bManualNormalSet )
125 aRet = m_aManualNormal;
126 else
128 ::basegfx::B3DPolygon aPolygon3D;
129 aPolygon3D.append(Position3DToB3DPoint( m_aPoint1 ));
130 aPolygon3D.append(Position3DToB3DPoint( m_aPoint2 ));
131 aPolygon3D.append(Position3DToB3DPoint( m_aPoint3 ));
132 aPolygon3D.append(Position3DToB3DPoint( m_aPoint4 ));
133 ::basegfx::B3DVector aNormal(aPolygon3D.getNormal());
134 aRet = B3DVectorToDirection3D(aNormal);
137 if( m_bInvertNormal )
139 aRet.DirectionX *= -1.0;
140 aRet.DirectionY *= -1.0;
141 aRet.DirectionZ *= -1.0;
143 return aRet;
146 uno::Any Stripe::getNormalsPolygon() const
148 drawing::PolyPolygonShape3D aPP;
150 aPP.SequenceX.realloc(1);
151 aPP.SequenceY.realloc(1);
152 aPP.SequenceZ.realloc(1);
154 drawing::DoubleSequence* pOuterSequenceX = aPP.SequenceX.getArray();
155 drawing::DoubleSequence* pOuterSequenceY = aPP.SequenceY.getArray();
156 drawing::DoubleSequence* pOuterSequenceZ = aPP.SequenceZ.getArray();
158 pOuterSequenceX->realloc(4);
159 pOuterSequenceY->realloc(4);
160 pOuterSequenceZ->realloc(4);
162 double* pInnerSequenceX = pOuterSequenceX->getArray();
163 double* pInnerSequenceY = pOuterSequenceY->getArray();
164 double* pInnerSequenceZ = pOuterSequenceZ->getArray();
166 drawing::Direction3D aNormal( getNormal() );
168 for(sal_Int32 nN=4; --nN; )
170 *pInnerSequenceX++ = aNormal.DirectionX;
171 *pInnerSequenceY++ = aNormal.DirectionY;
172 *pInnerSequenceZ++ = aNormal.DirectionZ;
174 return uno::Any( &aPP, cppu::UnoType<drawing::PolyPolygonShape3D>::get());
177 uno::Any Stripe::getTexturePolygon( short nRotatedTexture )
179 drawing::PolyPolygonShape3D aPP;
181 aPP.SequenceX.realloc(1);
182 aPP.SequenceY.realloc(1);
183 aPP.SequenceZ.realloc(1);
185 drawing::DoubleSequence* pOuterSequenceX = aPP.SequenceX.getArray();
186 drawing::DoubleSequence* pOuterSequenceY = aPP.SequenceY.getArray();
187 drawing::DoubleSequence* pOuterSequenceZ = aPP.SequenceZ.getArray();
189 pOuterSequenceX->realloc(4);
190 pOuterSequenceY->realloc(4);
191 pOuterSequenceZ->realloc(4);
193 double* pInnerSequenceX = pOuterSequenceX->getArray();
194 double* pInnerSequenceY = pOuterSequenceY->getArray();
195 double* pInnerSequenceZ = pOuterSequenceZ->getArray();
197 if( nRotatedTexture==0 )
199 *pInnerSequenceX++ = 0.0;
200 *pInnerSequenceY++ = 0.0;
201 *pInnerSequenceZ++ = 0.0;
203 *pInnerSequenceX++ = 0.0;
204 *pInnerSequenceY++ = 1.0;
205 *pInnerSequenceZ++ = 0.0;
207 *pInnerSequenceX++ = 1.0;
208 *pInnerSequenceY++ = 1.0;
209 *pInnerSequenceZ++ = 0.0;
211 *pInnerSequenceX++ = 1.0;
212 *pInnerSequenceY++ = 0.0;
213 *pInnerSequenceZ++ = 0.0;
215 else if( nRotatedTexture==1 )
217 *pInnerSequenceX++ = 1.0;
218 *pInnerSequenceY++ = 0.0;
219 *pInnerSequenceZ++ = 0.0;
221 *pInnerSequenceX++ = 0.0;
222 *pInnerSequenceY++ = 0.0;
223 *pInnerSequenceZ++ = 0.0;
225 *pInnerSequenceX++ = 0.0;
226 *pInnerSequenceY++ = 1.0;
227 *pInnerSequenceZ++ = 0.0;
229 *pInnerSequenceX++ = 1.0;
230 *pInnerSequenceY++ = 1.0;
231 *pInnerSequenceZ++ = 0.0;
233 else if( nRotatedTexture==2 )
235 *pInnerSequenceX++ = 1.0;
236 *pInnerSequenceY++ = 1.0;
237 *pInnerSequenceZ++ = 0.0;
239 *pInnerSequenceX++ = 1.0;
240 *pInnerSequenceY++ = 0.0;
241 *pInnerSequenceZ++ = 0.0;
243 *pInnerSequenceX++ = 0.0;
244 *pInnerSequenceY++ = 0.0;
245 *pInnerSequenceZ++ = 0.0;
247 *pInnerSequenceX++ = 0.0;
248 *pInnerSequenceY++ = 1.0;
249 *pInnerSequenceZ++ = 0.0;
251 else if( nRotatedTexture==3 )
253 *pInnerSequenceX++ = 0.0;
254 *pInnerSequenceY++ = 1.0;
255 *pInnerSequenceZ++ = 0.0;
257 *pInnerSequenceX++ = 1.0;
258 *pInnerSequenceY++ = 1.0;
259 *pInnerSequenceZ++ = 0.0;
261 *pInnerSequenceX++ = 1.0;
262 *pInnerSequenceY++ = 0.0;
263 *pInnerSequenceZ++ = 0.0;
265 *pInnerSequenceX++ = 0.0;
266 *pInnerSequenceY++ = 0.0;
267 *pInnerSequenceZ++ = 0.0;
269 else if( nRotatedTexture==4 )
271 *pInnerSequenceX++ = 1.0;
272 *pInnerSequenceY++ = 0.0;
273 *pInnerSequenceZ++ = 0.0;
275 *pInnerSequenceX++ = 1.0;
276 *pInnerSequenceY++ = 1.0;
277 *pInnerSequenceZ++ = 0.0;
279 *pInnerSequenceX++ = 0.0;
280 *pInnerSequenceY++ = 1.0;
281 *pInnerSequenceZ++ = 0.0;
283 *pInnerSequenceX++ = 0.0;
284 *pInnerSequenceY++ = 0.0;
285 *pInnerSequenceZ++ = 0.0;
287 else if( nRotatedTexture==5 )
289 *pInnerSequenceX++ = 0.0;
290 *pInnerSequenceY++ = 0.0;
291 *pInnerSequenceZ++ = 0.0;
293 *pInnerSequenceX++ = 1.0;
294 *pInnerSequenceY++ = 0.0;
295 *pInnerSequenceZ++ = 0.0;
297 *pInnerSequenceX++ = 1.0;
298 *pInnerSequenceY++ = 1.0;
299 *pInnerSequenceZ++ = 0.0;
301 *pInnerSequenceX++ = 0.0;
302 *pInnerSequenceY++ = 1.0;
303 *pInnerSequenceZ++ = 0.0;
305 else if( nRotatedTexture==6 )
307 *pInnerSequenceX++ = 0.0;
308 *pInnerSequenceY++ = 1.0;
309 *pInnerSequenceZ++ = 0.0;
311 *pInnerSequenceX++ = 0.0;
312 *pInnerSequenceY++ = 0.0;
313 *pInnerSequenceZ++ = 0.0;
315 *pInnerSequenceX++ = 1.0;
316 *pInnerSequenceY++ = 0.0;
317 *pInnerSequenceZ++ = 0.0;
319 *pInnerSequenceX++ = 1.0;
320 *pInnerSequenceY++ = 1.0;
321 *pInnerSequenceZ++ = 0.0;
323 else if( nRotatedTexture==7 )
325 *pInnerSequenceX++ = 1.0;
326 *pInnerSequenceY++ = 1.0;
327 *pInnerSequenceZ++ = 0.0;
329 *pInnerSequenceX++ = 0.0;
330 *pInnerSequenceY++ = 1.0;
331 *pInnerSequenceZ++ = 0.0;
333 *pInnerSequenceX++ = 0.0;
334 *pInnerSequenceY++ = 0.0;
335 *pInnerSequenceZ++ = 0.0;
337 *pInnerSequenceX++ = 1.0;
338 *pInnerSequenceY++ = 0.0;
339 *pInnerSequenceZ++ = 0.0;
342 return uno::Any( &aPP, cppu::UnoType<drawing::PolyPolygonShape3D>::get());
345 } //namespace chart
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */