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