LibreOffice Module basegfx (master) 1
b3dpolypolygon.cxx
Go to the documentation of this file.
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 <osl/diagnose.h>
25#include <utility>
26#include <vector>
27
29{
30 typedef std::vector< ::basegfx::B3DPolygon > PolygonVector;
31
33
34public:
36 {
37 }
38
39 explicit ImplB3DPolyPolygon(const ::basegfx::B3DPolygon& rToBeCopied) :
40 maPolygons(1,rToBeCopied)
41 {
42 }
43
44 bool operator==(const ImplB3DPolyPolygon& rPolygonList) const
45 {
46 // same polygon count?
47 if(maPolygons.size() != rPolygonList.maPolygons.size())
48 return false;
49
50 // compare polygon content
51 if(maPolygons != rPolygonList.maPolygons)
52 return false;
53
54 return true;
55 }
56
57 const ::basegfx::B3DPolygon& getB3DPolygon(sal_uInt32 nIndex) const
58 {
59 return maPolygons[nIndex];
60 }
61
62 void setB3DPolygon(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon)
63 {
64 maPolygons[nIndex] = rPolygon;
65 }
66
67 void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon, sal_uInt32 nCount)
68 {
69 if(nCount)
70 {
71 // add nCount copies of rPolygon
72 PolygonVector::iterator aIndex(maPolygons.begin());
73 if( nIndex )
74 aIndex += nIndex;
75 maPolygons.insert(aIndex, nCount, rPolygon);
76 }
77 }
78
79 void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolyPolygon& rPolyPolygon)
80 {
81 // add all polygons from rPolyPolygon
82 PolygonVector::iterator aIndex(maPolygons.begin());
83 if( nIndex )
84 aIndex += nIndex;
85 maPolygons.insert(aIndex, rPolyPolygon.begin(), rPolyPolygon.end());
86 }
87
88 void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
89 {
90 if(nCount)
91 {
92 // remove polygon data
93 PolygonVector::iterator aStart(maPolygons.begin());
94 aStart += nIndex;
95 const PolygonVector::iterator aEnd(aStart + nCount);
96
97 maPolygons.erase(aStart, aEnd);
98 }
99 }
100
101 sal_uInt32 count() const
102 {
103 return maPolygons.size();
104 }
105
106 void flip()
107 {
108 for (auto& aPolygon : maPolygons)
109 aPolygon.flip();
110 }
111
113 {
114 for (auto& aPolygon : maPolygons)
115 aPolygon.removeDoublePoints();
116 }
117
118 void transform(const ::basegfx::B3DHomMatrix& rMatrix)
119 {
120 for (auto& aPolygon : maPolygons)
121 aPolygon.transform(rMatrix);
122 }
123
125 {
126 for (auto& aPolygon : maPolygons)
127 aPolygon.clearBColors();
128 }
129
130 void transformNormals(const ::basegfx::B3DHomMatrix& rMatrix)
131 {
132 for (auto& aPolygon : maPolygons)
133 aPolygon.transformNormals(rMatrix);
134 }
135
137 {
138 for (auto& aPolygon : maPolygons)
139 aPolygon.clearNormals();
140 }
141
142 void transformTextureCoordinates(const ::basegfx::B2DHomMatrix& rMatrix)
143 {
144 for (auto& aPolygon : maPolygons)
145 aPolygon.transformTextureCoordinates(rMatrix);
146 }
147
149 {
150 for (auto& aPolygon : maPolygons)
151 aPolygon.clearTextureCoordinates();
152 }
153
155 {
156 if (maPolygons.empty())
157 return nullptr;
158 else
159 return maPolygons.data();
160 }
161
163 {
164 if (maPolygons.empty())
165 return nullptr;
166 else
167 return maPolygons.data() + maPolygons.size();
168 }
169
171 {
172 if (maPolygons.empty())
173 return nullptr;
174 else
175 return maPolygons.data();
176 }
177
179 {
180 if (maPolygons.empty())
181 return nullptr;
182 else
183 return maPolygons.data() + maPolygons.size();
184 }
185};
186
187namespace basegfx
188{
189 namespace {
190
191 B3DPolyPolygon::ImplType const & getDefaultPolyPolygon() {
192 static B3DPolyPolygon::ImplType const singleton;
193 return singleton;
194 }
195
196 }
197
199 mpPolyPolygon(getDefaultPolyPolygon())
200 {
201 }
202
204
206
208 mpPolyPolygon( ImplB3DPolyPolygon(rPolygon) )
209 {
210 }
211
213
215
217
218 bool B3DPolyPolygon::operator==(const B3DPolyPolygon& rPolyPolygon) const
219 {
220 if(mpPolyPolygon.same_object(rPolyPolygon.mpPolyPolygon))
221 return true;
222
223 return ((*mpPolyPolygon) == (*rPolyPolygon.mpPolyPolygon));
224 }
225
226 bool B3DPolyPolygon::operator!=(const B3DPolyPolygon& rPolyPolygon) const
227 {
228 return !(*this == rPolyPolygon);
229 }
230
231 sal_uInt32 B3DPolyPolygon::count() const
232 {
233 return mpPolyPolygon->count();
234 }
235
236 B3DPolygon const & B3DPolyPolygon::getB3DPolygon(sal_uInt32 nIndex) const
237 {
238 OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)");
239
240 return mpPolyPolygon->getB3DPolygon(nIndex);
241 }
242
243 void B3DPolyPolygon::setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon& rPolygon)
244 {
245 OSL_ENSURE(nIndex < std::as_const(mpPolyPolygon)->count(), "B3DPolyPolygon access outside range (!)");
246
247 if(getB3DPolygon(nIndex) != rPolygon)
248 mpPolyPolygon->setB3DPolygon(nIndex, rPolygon);
249 }
250
252 {
253 for(sal_uInt32 a(0); a < mpPolyPolygon->count(); a++)
254 {
255 if(mpPolyPolygon->getB3DPolygon(a).areBColorsUsed())
256 {
257 return true;
258 }
259 }
260
261 return false;
262 }
263
265 {
266 if(areBColorsUsed())
267 mpPolyPolygon->clearBColors();
268 }
269
271 {
272 if(!rMatrix.isIdentity())
273 mpPolyPolygon->transformNormals(rMatrix);
274 }
275
277 {
278 for(sal_uInt32 a(0); a < mpPolyPolygon->count(); a++)
279 {
280 if(mpPolyPolygon->getB3DPolygon(a).areNormalsUsed())
281 {
282 return true;
283 }
284 }
285
286 return false;
287 }
288
290 {
291 if(areNormalsUsed())
292 mpPolyPolygon->clearNormals();
293 }
294
296 {
297 if(!rMatrix.isIdentity())
298 mpPolyPolygon->transformTextureCoordinates(rMatrix);
299 }
300
302 {
303 for(sal_uInt32 a(0); a < mpPolyPolygon->count(); a++)
304 {
305 if(mpPolyPolygon->getB3DPolygon(a).areTextureCoordinatesUsed())
306 {
307 return true;
308 }
309 }
310
311 return false;
312 }
313
315 {
317 mpPolyPolygon->clearTextureCoordinates();
318 }
319
320 void B3DPolyPolygon::append(const B3DPolygon& rPolygon, sal_uInt32 nCount)
321 {
322 if(nCount)
323 mpPolyPolygon->insert(std::as_const(mpPolyPolygon)->count(), rPolygon, nCount);
324 }
325
326 void B3DPolyPolygon::append(const B3DPolyPolygon& rPolyPolygon)
327 {
328 if(rPolyPolygon.count())
329 mpPolyPolygon->insert(std::as_const(mpPolyPolygon)->count(), rPolyPolygon);
330 }
331
332 void B3DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount)
333 {
334 OSL_ENSURE(nIndex + nCount <= std::as_const(mpPolyPolygon)->count(), "B3DPolyPolygon Remove outside range (!)");
335
336 if(nCount)
337 mpPolyPolygon->remove(nIndex, nCount);
338 }
339
341 {
342 mpPolyPolygon = getDefaultPolyPolygon();
343 }
344
346 {
347 mpPolyPolygon->flip();
348 }
349
351 {
352 bool bRetval(false);
353
354 for(sal_uInt32 a(0); !bRetval && a < mpPolyPolygon->count(); a++)
355 {
356 if(mpPolyPolygon->getB3DPolygon(a).hasDoublePoints())
357 {
358 bRetval = true;
359 }
360 }
361
362 return bRetval;
363 }
364
366 {
367 if(hasDoublePoints())
368 mpPolyPolygon->removeDoublePoints();
369 }
370
372 {
373 if(std::as_const(mpPolyPolygon)->count() && !rMatrix.isIdentity())
374 {
375 mpPolyPolygon->transform(rMatrix);
376 }
377 }
378
380 {
381 return mpPolyPolygon->begin();
382 }
383
385 {
386 return mpPolyPolygon->end();
387 }
388
390 {
391 return mpPolyPolygon->begin();
392 }
393
395 {
396 return mpPolyPolygon->end();
397 }
398} // end of namespace basegfx
399
400/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolyPolygon &rPolyPolygon)
void setB3DPolygon(sal_uInt32 nIndex, const ::basegfx::B3DPolygon &rPolygon)
void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolygon &rPolygon, sal_uInt32 nCount)
void transform(const ::basegfx::B3DHomMatrix &rMatrix)
basegfx::B3DPolygon * begin()
void transformNormals(const ::basegfx::B3DHomMatrix &rMatrix)
PolygonVector maPolygons
sal_uInt32 count() const
void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
const ::basegfx::B3DPolygon & getB3DPolygon(sal_uInt32 nIndex) const
const basegfx::B3DPolygon * begin() const
const basegfx::B3DPolygon * end() const
std::vector< ::basegfx::B3DPolygon > PolygonVector
basegfx::B3DPolygon * end()
bool operator==(const ImplB3DPolyPolygon &rPolygonList) const
void transformTextureCoordinates(const ::basegfx::B2DHomMatrix &rMatrix)
ImplB3DPolyPolygon(const ::basegfx::B3DPolygon &rToBeCopied)
bool isIdentity() const
bool isIdentity() const
const B3DPolygon * begin() const
void transformNormals(const B3DHomMatrix &rMatrix)
o3tl::cow_wrapper< ImplB3DPolyPolygon, o3tl::ThreadSafeRefCountingPolicy > ImplType
bool operator!=(const B3DPolyPolygon &rPolyPolygon) const
bool areTextureCoordinatesUsed() const
void remove(sal_uInt32 nIndex, sal_uInt32 nCount=1)
const B3DPolygon * end() const
void transformTextureCoordinates(const B2DHomMatrix &rMatrix)
B3DPolyPolygon & operator=(const B3DPolyPolygon &rPolyPolygon)
sal_uInt32 count() const
void setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon &rPolygon)
void transform(const basegfx::B3DHomMatrix &rMatrix)
void append(const B3DPolygon &rPolygon, sal_uInt32 nCount=1)
B3DPolygon const & getB3DPolygon(sal_uInt32 nIndex) const
bool operator==(const B3DPolyPolygon &rPolyPolygon) const
bool same_object(const cow_wrapper &rOther) const
int nCount
std::deque< AttacherIndex_Impl > aIndex
sal_Int32 nIndex
uno_Any a