Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / basegfx / source / polygon / b3dpolypolygon.cxx
blobe391fc783848984fc72c787989d54ab6779fe910
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 <basegfx/matrix/b2dhommatrix.hxx>
24 #include <basegfx/matrix/b3dhommatrix.hxx>
25 #include <vector>
27 class ImplB3DPolyPolygon
29 typedef std::vector< ::basegfx::B3DPolygon > PolygonVector;
31 PolygonVector maPolygons;
33 public:
34 ImplB3DPolyPolygon() : maPolygons()
38 explicit ImplB3DPolyPolygon(const ::basegfx::B3DPolygon& rToBeCopied) :
39 maPolygons(1,rToBeCopied)
43 bool operator==(const ImplB3DPolyPolygon& rPolygonList) const
45 // same polygon count?
46 if(maPolygons.size() != rPolygonList.maPolygons.size())
47 return false;
49 // compare polygon content
50 if(maPolygons != rPolygonList.maPolygons)
51 return false;
53 return true;
56 const ::basegfx::B3DPolygon& getB3DPolygon(sal_uInt32 nIndex) const
58 return maPolygons[nIndex];
61 void setB3DPolygon(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon)
63 maPolygons[nIndex] = rPolygon;
66 void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon, sal_uInt32 nCount)
68 if(nCount)
70 // add nCount copies of rPolygon
71 PolygonVector::iterator aIndex(maPolygons.begin());
72 if( nIndex )
73 aIndex += nIndex;
74 maPolygons.insert(aIndex, nCount, rPolygon);
78 void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolyPolygon& rPolyPolygon)
80 // add all polygons from rPolyPolygon
81 PolygonVector::iterator aIndex(maPolygons.begin());
82 if( nIndex )
83 aIndex += nIndex;
84 maPolygons.insert(aIndex, rPolyPolygon.begin(), rPolyPolygon.end());
87 void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
89 if(nCount)
91 // remove polygon data
92 PolygonVector::iterator aStart(maPolygons.begin());
93 aStart += nIndex;
94 const PolygonVector::iterator aEnd(aStart + nCount);
96 maPolygons.erase(aStart, aEnd);
100 sal_uInt32 count() const
102 return maPolygons.size();
105 void flip()
107 for (auto& aPolygon : maPolygons)
108 aPolygon.flip();
111 void removeDoublePoints()
113 for (auto& aPolygon : maPolygons)
114 aPolygon.removeDoublePoints();
117 void transform(const ::basegfx::B3DHomMatrix& rMatrix)
119 for (auto& aPolygon : maPolygons)
120 aPolygon.transform(rMatrix);
123 void clearBColors()
125 for (auto& aPolygon : maPolygons)
126 aPolygon.clearBColors();
129 void transformNormals(const ::basegfx::B3DHomMatrix& rMatrix)
131 for (auto& aPolygon : maPolygons)
132 aPolygon.transformNormals(rMatrix);
135 void clearNormals()
137 for (auto& aPolygon : maPolygons)
138 aPolygon.clearNormals();
141 void transformTextureCoordinates(const ::basegfx::B2DHomMatrix& rMatrix)
143 for (auto& aPolygon : maPolygons)
144 aPolygon.transformTextureCoordinates(rMatrix);
147 void clearTextureCoordinates()
149 for (auto& aPolygon : maPolygons)
150 aPolygon.clearTextureCoordinates();
153 const basegfx::B3DPolygon* begin() const
155 if (maPolygons.empty())
156 return nullptr;
157 else
158 return maPolygons.data();
161 const basegfx::B3DPolygon* end() const
163 if (maPolygons.empty())
164 return nullptr;
165 else
166 return maPolygons.data() + maPolygons.size();
169 basegfx::B3DPolygon* begin()
171 if (maPolygons.empty())
172 return nullptr;
173 else
174 return maPolygons.data();
177 basegfx::B3DPolygon* end()
179 if (maPolygons.empty())
180 return nullptr;
181 else
182 return maPolygons.data() + maPolygons.size();
186 namespace basegfx
188 namespace {
190 B3DPolyPolygon::ImplType const & getDefaultPolyPolygon() {
191 static B3DPolyPolygon::ImplType const singleton;
192 return singleton;
197 B3DPolyPolygon::B3DPolyPolygon() :
198 mpPolyPolygon(getDefaultPolyPolygon())
202 B3DPolyPolygon::B3DPolyPolygon(const B3DPolyPolygon&) = default;
204 B3DPolyPolygon::B3DPolyPolygon(B3DPolyPolygon&&) = default;
206 B3DPolyPolygon::B3DPolyPolygon(const B3DPolygon& rPolygon) :
207 mpPolyPolygon( ImplB3DPolyPolygon(rPolygon) )
211 B3DPolyPolygon::~B3DPolyPolygon() = default;
213 B3DPolyPolygon& B3DPolyPolygon::operator=(const B3DPolyPolygon&) = default;
215 B3DPolyPolygon& B3DPolyPolygon::operator=(B3DPolyPolygon&&) = default;
217 bool B3DPolyPolygon::operator==(const B3DPolyPolygon& rPolyPolygon) const
219 if(mpPolyPolygon.same_object(rPolyPolygon.mpPolyPolygon))
220 return true;
222 return ((*mpPolyPolygon) == (*rPolyPolygon.mpPolyPolygon));
225 bool B3DPolyPolygon::operator!=(const B3DPolyPolygon& rPolyPolygon) const
227 return !(*this == rPolyPolygon);
230 sal_uInt32 B3DPolyPolygon::count() const
232 return mpPolyPolygon->count();
235 B3DPolygon const & B3DPolyPolygon::getB3DPolygon(sal_uInt32 nIndex) const
237 OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)");
239 return mpPolyPolygon->getB3DPolygon(nIndex);
242 void B3DPolyPolygon::setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon& rPolygon)
244 OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)");
246 if(getB3DPolygon(nIndex) != rPolygon)
247 mpPolyPolygon->setB3DPolygon(nIndex, rPolygon);
250 bool B3DPolyPolygon::areBColorsUsed() const
252 for(sal_uInt32 a(0); a < mpPolyPolygon->count(); a++)
254 if(mpPolyPolygon->getB3DPolygon(a).areBColorsUsed())
256 return true;
260 return false;
263 void B3DPolyPolygon::clearBColors()
265 if(areBColorsUsed())
266 mpPolyPolygon->clearBColors();
269 void B3DPolyPolygon::transformNormals(const B3DHomMatrix& rMatrix)
271 if(!rMatrix.isIdentity())
272 mpPolyPolygon->transformNormals(rMatrix);
275 bool B3DPolyPolygon::areNormalsUsed() const
277 for(sal_uInt32 a(0); a < mpPolyPolygon->count(); a++)
279 if(mpPolyPolygon->getB3DPolygon(a).areNormalsUsed())
281 return true;
285 return false;
288 void B3DPolyPolygon::clearNormals()
290 if(areNormalsUsed())
291 mpPolyPolygon->clearNormals();
294 void B3DPolyPolygon::transformTextureCoordinates(const B2DHomMatrix& rMatrix)
296 if(!rMatrix.isIdentity())
297 mpPolyPolygon->transformTextureCoordinates(rMatrix);
300 bool B3DPolyPolygon::areTextureCoordinatesUsed() const
302 for(sal_uInt32 a(0); a < mpPolyPolygon->count(); a++)
304 if(mpPolyPolygon->getB3DPolygon(a).areTextureCoordinatesUsed())
306 return true;
310 return false;
313 void B3DPolyPolygon::clearTextureCoordinates()
315 if(areTextureCoordinatesUsed())
316 mpPolyPolygon->clearTextureCoordinates();
319 void B3DPolyPolygon::append(const B3DPolygon& rPolygon, sal_uInt32 nCount)
321 if(nCount)
322 mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount);
325 void B3DPolyPolygon::append(const B3DPolyPolygon& rPolyPolygon)
327 if(rPolyPolygon.count())
328 mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon);
331 void B3DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount)
333 OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B3DPolyPolygon Remove outside range (!)");
335 if(nCount)
336 mpPolyPolygon->remove(nIndex, nCount);
339 void B3DPolyPolygon::clear()
341 mpPolyPolygon = getDefaultPolyPolygon();
344 void B3DPolyPolygon::flip()
346 mpPolyPolygon->flip();
349 bool B3DPolyPolygon::hasDoublePoints() const
351 bool bRetval(false);
353 for(sal_uInt32 a(0); !bRetval && a < mpPolyPolygon->count(); a++)
355 if(mpPolyPolygon->getB3DPolygon(a).hasDoublePoints())
357 bRetval = true;
361 return bRetval;
364 void B3DPolyPolygon::removeDoublePoints()
366 if(hasDoublePoints())
367 mpPolyPolygon->removeDoublePoints();
370 void B3DPolyPolygon::transform(const B3DHomMatrix& rMatrix)
372 if(mpPolyPolygon->count() && !rMatrix.isIdentity())
374 mpPolyPolygon->transform(rMatrix);
378 const B3DPolygon* B3DPolyPolygon::begin() const
380 return mpPolyPolygon->begin();
383 const B3DPolygon* B3DPolyPolygon::end() const
385 return mpPolyPolygon->end();
388 B3DPolygon* B3DPolyPolygon::begin()
390 return mpPolyPolygon->begin();
393 B3DPolygon* B3DPolyPolygon::end()
395 return mpPolyPolygon->end();
397 } // end of namespace basegfx
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */