bump product version to 5.0.4.1
[LibreOffice.git] / basegfx / source / polygon / b3dpolypolygon.cxx
bloba96d4dac7355d1a838eb36a7add2ff5347d8c61a
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 <osl/diagnose.h>
21 #include <basegfx/polygon/b3dpolypolygon.hxx>
22 #include <basegfx/polygon/b3dpolygon.hxx>
23 #include <rtl/instance.hxx>
24 #include <basegfx/matrix/b2dhommatrix.hxx>
25 #include <basegfx/matrix/b3dhommatrix.hxx>
26 #include <functional>
27 #include <vector>
28 #include <algorithm>
30 class ImplB3DPolyPolygon
32 typedef ::std::vector< ::basegfx::B3DPolygon > PolygonVector;
34 PolygonVector maPolygons;
36 public:
37 ImplB3DPolyPolygon() : maPolygons()
41 explicit ImplB3DPolyPolygon(const ::basegfx::B3DPolygon& rToBeCopied) :
42 maPolygons(1,rToBeCopied)
46 bool operator==(const ImplB3DPolyPolygon& rPolygonList) const
48 // same polygon count?
49 if(maPolygons.size() != rPolygonList.maPolygons.size())
50 return false;
52 // compare polygon content
53 if(maPolygons != rPolygonList.maPolygons)
54 return false;
56 return true;
59 const ::basegfx::B3DPolygon& getB3DPolygon(sal_uInt32 nIndex) const
61 return maPolygons[nIndex];
64 void setB3DPolygon(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon)
66 maPolygons[nIndex] = rPolygon;
69 void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon, sal_uInt32 nCount)
71 if(nCount)
73 // add nCount copies of rPolygon
74 PolygonVector::iterator aIndex(maPolygons.begin());
75 if( nIndex )
76 aIndex += nIndex;
77 maPolygons.insert(aIndex, nCount, rPolygon);
81 void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolyPolygon& rPolyPolygon)
83 // add all polygons from rPolyPolygon
84 PolygonVector::iterator aIndex(maPolygons.begin());
85 if( nIndex )
86 aIndex += nIndex;
87 maPolygons.insert(aIndex, rPolyPolygon.begin(), rPolyPolygon.end());
90 void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
92 if(nCount)
94 // remove polygon data
95 PolygonVector::iterator aStart(maPolygons.begin());
96 aStart += nIndex;
97 const PolygonVector::iterator aEnd(aStart + nCount);
99 maPolygons.erase(aStart, aEnd);
103 sal_uInt32 count() const
105 return maPolygons.size();
108 void flip()
110 std::for_each( maPolygons.begin(),
111 maPolygons.end(),
112 std::mem_fun_ref( &::basegfx::B3DPolygon::flip ));
115 void removeDoublePoints()
117 std::for_each( maPolygons.begin(),
118 maPolygons.end(),
119 std::mem_fun_ref( &::basegfx::B3DPolygon::removeDoublePoints ));
122 void transform(const ::basegfx::B3DHomMatrix& rMatrix)
124 for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
126 maPolygons[a].transform(rMatrix);
130 void clearBColors()
132 for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
134 maPolygons[a].clearBColors();
138 void transformNormals(const ::basegfx::B3DHomMatrix& rMatrix)
140 for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
142 maPolygons[a].transformNormals(rMatrix);
146 void clearNormals()
148 for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
150 maPolygons[a].clearNormals();
154 void transformTextureCoordiantes(const ::basegfx::B2DHomMatrix& rMatrix)
156 for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
158 maPolygons[a].transformTextureCoordiantes(rMatrix);
162 void clearTextureCoordinates()
164 for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
166 maPolygons[a].clearTextureCoordinates();
170 const basegfx::B3DPolygon* begin() const
172 if(maPolygons.empty())
173 return 0;
174 else
175 return &maPolygons.front();
178 const basegfx::B3DPolygon* end() const
180 if(maPolygons.empty())
181 return 0;
182 else
183 return (&maPolygons.back())+1;
186 basegfx::B3DPolygon* begin()
188 if(maPolygons.empty())
189 return 0;
190 else
191 return &maPolygons.front();
194 basegfx::B3DPolygon* end()
196 if(maPolygons.empty())
197 return 0;
198 else
199 return &(maPolygons.back())+1;
203 namespace basegfx
205 namespace { struct DefaultPolyPolygon : public rtl::Static<B3DPolyPolygon::ImplType,
206 DefaultPolyPolygon> {}; }
208 B3DPolyPolygon::B3DPolyPolygon() :
209 mpPolyPolygon(DefaultPolyPolygon::get())
213 B3DPolyPolygon::B3DPolyPolygon(const B3DPolyPolygon& rPolyPolygon) :
214 mpPolyPolygon(rPolyPolygon.mpPolyPolygon)
218 B3DPolyPolygon::B3DPolyPolygon(const B3DPolygon& rPolygon) :
219 mpPolyPolygon( ImplB3DPolyPolygon(rPolygon) )
223 B3DPolyPolygon::~B3DPolyPolygon()
227 B3DPolyPolygon& B3DPolyPolygon::operator=(const B3DPolyPolygon& rPolyPolygon)
229 mpPolyPolygon = rPolyPolygon.mpPolyPolygon;
230 return *this;
233 bool B3DPolyPolygon::operator==(const B3DPolyPolygon& rPolyPolygon) const
235 if(mpPolyPolygon.same_object(rPolyPolygon.mpPolyPolygon))
236 return true;
238 return ((*mpPolyPolygon) == (*rPolyPolygon.mpPolyPolygon));
241 bool B3DPolyPolygon::operator!=(const B3DPolyPolygon& rPolyPolygon) const
243 return !(*this == rPolyPolygon);
246 sal_uInt32 B3DPolyPolygon::count() const
248 return mpPolyPolygon->count();
251 B3DPolygon B3DPolyPolygon::getB3DPolygon(sal_uInt32 nIndex) const
253 OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)");
255 return mpPolyPolygon->getB3DPolygon(nIndex);
258 void B3DPolyPolygon::setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon& rPolygon)
260 OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)");
262 if(getB3DPolygon(nIndex) != rPolygon)
263 mpPolyPolygon->setB3DPolygon(nIndex, rPolygon);
266 bool B3DPolyPolygon::areBColorsUsed() const
268 for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
270 if((mpPolyPolygon->getB3DPolygon(a)).areBColorsUsed())
272 return true;
276 return false;
279 void B3DPolyPolygon::clearBColors()
281 if(areBColorsUsed())
282 mpPolyPolygon->clearBColors();
285 void B3DPolyPolygon::transformNormals(const B3DHomMatrix& rMatrix)
287 if(!rMatrix.isIdentity())
288 mpPolyPolygon->transformNormals(rMatrix);
291 bool B3DPolyPolygon::areNormalsUsed() const
293 for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
295 if((mpPolyPolygon->getB3DPolygon(a)).areNormalsUsed())
297 return true;
301 return false;
304 void B3DPolyPolygon::clearNormals()
306 if(areNormalsUsed())
307 mpPolyPolygon->clearNormals();
310 void B3DPolyPolygon::transformTextureCoordiantes(const B2DHomMatrix& rMatrix)
312 if(!rMatrix.isIdentity())
313 mpPolyPolygon->transformTextureCoordiantes(rMatrix);
316 bool B3DPolyPolygon::areTextureCoordinatesUsed() const
318 for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
320 if((mpPolyPolygon->getB3DPolygon(a)).areTextureCoordinatesUsed())
322 return true;
326 return false;
329 void B3DPolyPolygon::clearTextureCoordinates()
331 if(areTextureCoordinatesUsed())
332 mpPolyPolygon->clearTextureCoordinates();
335 void B3DPolyPolygon::append(const B3DPolygon& rPolygon, sal_uInt32 nCount)
337 if(nCount)
338 mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount);
341 void B3DPolyPolygon::append(const B3DPolyPolygon& rPolyPolygon)
343 if(rPolyPolygon.count())
344 mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon);
347 void B3DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount)
349 OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B3DPolyPolygon Remove outside range (!)");
351 if(nCount)
352 mpPolyPolygon->remove(nIndex, nCount);
355 void B3DPolyPolygon::clear()
357 mpPolyPolygon = DefaultPolyPolygon::get();
360 void B3DPolyPolygon::flip()
362 mpPolyPolygon->flip();
365 bool B3DPolyPolygon::hasDoublePoints() const
367 bool bRetval(false);
369 for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++)
371 if((mpPolyPolygon->getB3DPolygon(a)).hasDoublePoints())
373 bRetval = true;
377 return bRetval;
380 void B3DPolyPolygon::removeDoublePoints()
382 if(hasDoublePoints())
383 mpPolyPolygon->removeDoublePoints();
386 void B3DPolyPolygon::transform(const B3DHomMatrix& rMatrix)
388 if(mpPolyPolygon->count() && !rMatrix.isIdentity())
390 mpPolyPolygon->transform(rMatrix);
394 const B3DPolygon* B3DPolyPolygon::begin() const
396 return mpPolyPolygon->begin();
399 const B3DPolygon* B3DPolyPolygon::end() const
401 return mpPolyPolygon->end();
404 B3DPolygon* B3DPolyPolygon::begin()
406 return mpPolyPolygon->begin();
409 B3DPolygon* B3DPolyPolygon::end()
411 return mpPolyPolygon->end();
413 } // end of namespace basegfx
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */