LibreOffice Module basegfx (master) 1
b2dpolypolygon.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 <sal/config.h>
21
22#include <cassert>
23#include <utility>
24
29
30namespace basegfx
31{
32
34{
36 // we do not want to 'modify' the ImplB2DPolyPolygon,
37 // but add buffered data that is valid for all referencing instances
38 mutable std::unique_ptr<basegfx::SystemDependentDataHolder> mpSystemDependentDataHolder;
39
40public:
42 {
43 }
44
45 explicit ImplB2DPolyPolygon(const ImplB2DPolyPolygon& rSource)
46 : maPolygons(rSource.maPolygons)
47 {
48 }
49
50 explicit ImplB2DPolyPolygon(const basegfx::B2DPolygon& rToBeCopied)
51 : maPolygons(1,rToBeCopied)
52 {
53 }
54
56 {
57 if (this != &rSource)
58 {
59 maPolygons = rSource.maPolygons;
61 }
62
63 return *this;
64 }
65
67 {
69 {
71 }
72
73 mpSystemDependentDataHolder->addOrReplaceSystemDependentData(rData);
74 }
75
77 {
79 {
81 }
82
83 return mpSystemDependentDataHolder->getSystemDependentData(hash_code);
84 }
85
86 bool operator==(const ImplB2DPolyPolygon& rPolygonList) const
87 {
88 return maPolygons == rPolygonList.maPolygons;
89 }
90
91 const basegfx::B2DPolygon& getB2DPolygon(sal_uInt32 nIndex) const
92 {
93 assert(nIndex < maPolygons.size());
94 return maPolygons[nIndex];
95 }
96
97 void setB2DPolygon(sal_uInt32 nIndex, const basegfx::B2DPolygon& rPolygon)
98 {
99 assert(nIndex < maPolygons.size());
100 maPolygons[nIndex] = rPolygon;
101 }
102
103 void insert(sal_uInt32 nIndex, const basegfx::B2DPolygon& rPolygon, sal_uInt32 nCount)
104 {
105 assert(nCount > 0);
106 assert(nIndex <= maPolygons.size());
107 // add nCount copies of rPolygon
108 maPolygons.insert(maPolygons.begin() + nIndex, nCount, rPolygon);
109 }
110
111 void append(const basegfx::B2DPolygon& rPolygon, sal_uInt32 nCount)
112 {
113 insert(maPolygons.size(), rPolygon, nCount);
114 }
115
116 void reserve(sal_uInt32 nCount)
117 {
118 maPolygons.reserve(nCount);
119 }
120
121 void insert(sal_uInt32 nIndex, const basegfx::B2DPolyPolygon& rPolyPolygon)
122 {
123 assert(nIndex <= maPolygons.size());
124 // add nCount polygons from rPolyPolygon
125 maPolygons.insert(maPolygons.begin() + nIndex, rPolyPolygon.begin(), rPolyPolygon.end());
126 }
127
128 void append(const basegfx::B2DPolyPolygon& rPolyPolygon)
129 {
130 insert(maPolygons.size(), rPolyPolygon);
131 }
132
133 void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
134 {
135 assert(nCount > 0);
136 assert(nIndex + nCount <= maPolygons.size());
137 // remove polygon data
138 auto aStart(maPolygons.begin() + nIndex);
139 auto aEnd(aStart + nCount);
140
141 maPolygons.erase(aStart, aEnd);
142 }
143
144 sal_uInt32 count() const
145 {
146 return maPolygons.size();
147 }
148
149 void setClosed(bool bNew)
150 {
151 for(basegfx::B2DPolygon & rPolygon : maPolygons)
152 {
153 rPolygon.setClosed(bNew);
154 }
155 }
156
157 void flip()
158 {
159 for (auto& aPolygon : maPolygons)
160 aPolygon.flip();
161 }
162
164 {
165 for (auto& aPolygon : maPolygons)
166 aPolygon.removeDoublePoints();
167 }
168
169 void transform(const basegfx::B2DHomMatrix& rMatrix)
170 {
171 for (auto& aPolygon : maPolygons)
172 aPolygon.transform(rMatrix);
173 }
174
176 {
177 for (auto& aPolygon : maPolygons)
178 aPolygon.makeUnique();
179 }
180
182 {
183 if (maPolygons.empty())
184 return nullptr;
185 else
186 return maPolygons.data();
187 }
188
190 {
191 if (maPolygons.empty())
192 return nullptr;
193 else
194 return maPolygons.data() + maPolygons.size();
195 }
196
198 {
199 if (maPolygons.empty())
200 return nullptr;
201 else
202 return maPolygons.data();
203 }
204
206 {
207 if (maPolygons.empty())
208 return nullptr;
209 else
210 return maPolygons.data() + maPolygons.size();
211 }
212};
213
215
216 B2DPolyPolygon::B2DPolyPolygon(const B2DPolyPolygon&) = default;
217
218 B2DPolyPolygon::B2DPolyPolygon(B2DPolyPolygon&&) = default;
219
221 mpPolyPolygon( ImplB2DPolyPolygon(rPolygon) )
222 {
223 }
224
226
228
230
232 {
233 mpPolyPolygon->makeUnique(); // non-const cow_wrapper::operator-> calls make_unique
234 }
235
236 bool B2DPolyPolygon::operator==(const B2DPolyPolygon& rPolyPolygon) const
237 {
238 if(mpPolyPolygon.same_object(rPolyPolygon.mpPolyPolygon))
239 return true;
240
241 return ((*mpPolyPolygon) == (*rPolyPolygon.mpPolyPolygon));
242 }
243
244 bool B2DPolyPolygon::operator!=(const B2DPolyPolygon& rPolyPolygon) const
245 {
246 return !((*this) == rPolyPolygon);
247 }
248
249 sal_uInt32 B2DPolyPolygon::count() const
250 {
251 return mpPolyPolygon->count();
252 }
253
254 B2DPolygon const & B2DPolyPolygon::getB2DPolygon(sal_uInt32 nIndex) const
255 {
256 return mpPolyPolygon->getB2DPolygon(nIndex);
257 }
258
259 void B2DPolyPolygon::setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon& rPolygon)
260 {
261 if(getB2DPolygon(nIndex) != rPolygon)
262 mpPolyPolygon->setB2DPolygon(nIndex, rPolygon);
263 }
264
266 {
267 for(sal_uInt32 a(0); a < count(); a++)
268 {
270 {
271 return true;
272 }
273 }
274
275 return false;
276 }
277
278 void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPolygon, sal_uInt32 nCount)
279 {
280 if(nCount)
281 mpPolyPolygon->insert(nIndex, rPolygon, nCount);
282 }
283
284 void B2DPolyPolygon::append(const B2DPolygon& rPolygon, sal_uInt32 nCount)
285 {
286 if(nCount)
287 mpPolyPolygon->append(rPolygon, nCount);
288 }
289
290 void B2DPolyPolygon::reserve(sal_uInt32 nCount)
291 {
292 if(nCount)
293 mpPolyPolygon->reserve(nCount);
294 }
295
297 {
298 B2DPolyPolygon aRetval;
299 if (count())
300 {
301 ImplB2DPolyPolygon& dest = *aRetval.mpPolyPolygon;
302 dest.reserve(count());
303
304 for (sal_uInt32 a(0); a < count(); a++)
305 {
307 }
308 }
309
310 return aRetval;
311 }
312
314 {
315 B2DRange aRetval;
316
317 for(sal_uInt32 a(0); a < count(); a++)
318 {
319 aRetval.expand(getB2DPolygon(a).getB2DRange());
320 }
321
322 return aRetval;
323 }
324
325 void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolyPolygon& rPolyPolygon)
326 {
327 if(rPolyPolygon.count())
328 mpPolyPolygon->insert(nIndex, rPolyPolygon);
329 }
330
331 void B2DPolyPolygon::append(const B2DPolyPolygon& rPolyPolygon)
332 {
333 if(rPolyPolygon.count())
334 mpPolyPolygon->append(rPolyPolygon);
335 }
336
337 void B2DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount)
338 {
339 if(nCount)
340 mpPolyPolygon->remove(nIndex, nCount);
341 }
342
344 {
346 }
347
349 {
350 // PolyPOlygon is closed when all contained Polygons are closed or
351 // no Polygon exists.
352 for(sal_uInt32 a(0); a < count(); a++)
353 {
354 if(!getB2DPolygon(a).isClosed())
355 return false;
356 }
357
358 return true;
359 }
360
362 {
363 if(bNew != isClosed())
364 mpPolyPolygon->setClosed(bNew);
365 }
366
368 {
369 if(count())
370 {
371 mpPolyPolygon->flip();
372 }
373 }
374
376 {
377 for(sal_uInt32 a(0); a < count(); a++)
378 {
380 return true;
381 }
382
383 return false;
384 }
385
387 {
388 if(hasDoublePoints())
389 mpPolyPolygon->removeDoublePoints();
390 }
391
393 {
394 if(count() && !rMatrix.isIdentity())
395 {
396 mpPolyPolygon->transform(rMatrix);
397 }
398 }
399
401 {
402 return mpPolyPolygon->begin();
403 }
404
406 {
407 return mpPolyPolygon->end();
408 }
409
411 {
412 return mpPolyPolygon->begin();
413 }
414
416 {
417 return mpPolyPolygon->end();
418 }
419
421 {
422 mpPolyPolygon->addOrReplaceSystemDependentData(rData);
423 }
424
426 {
427 return mpPolyPolygon->getSystemDependentData(hash_code);
428 }
429
430} // end of namespace basegfx
431
432/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isIdentity() const
void insert(sal_uInt32 nIndex, const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
B2DPolygon const & getB2DPolygon(sal_uInt32 nIndex) const
const B2DPolygon * begin() const
void makeUnique()
unshare this poly-polygon (and all included polygons) with all internally shared instances
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
bool operator==(const B2DPolyPolygon &rPolyPolygon) const
B2DPolyPolygon & operator=(const B2DPolyPolygon &rPolyPolygon)
o3tl::cow_wrapper< ImplB2DPolyPolygon, o3tl::ThreadSafeRefCountingPolicy > mpPolyPolygon
bool operator!=(const B2DPolyPolygon &rPolyPolygon) const
void setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon &rPolygon)
void transform(const basegfx::B2DHomMatrix &rMatrix)
B2DRange getB2DRange() const
Get the B2DRange (Rectangle dimensions) of this B2DPolyPolygon.
void addOrReplaceSystemDependentDataInternal(SystemDependentData_SharedPtr &rData) const
bool areControlPointsUsed() const
void remove(sal_uInt32 nIndex, sal_uInt32 nCount=1)
SystemDependentData_SharedPtr getSystemDependantDataInternal(size_t hash_code) const
const B2DPolygon * end() const
sal_uInt32 count() const
B2DPolyPolygon getDefaultAdaptiveSubdivision() const
Default adaptive subdivision access.
void reserve(sal_uInt32 nCount)
bool isClosed() const
closed state interface
bool hasDoublePoints() const
test if Polygon has double points
bool areControlPointsUsed() const
ControlPoint checks.
B2DRange const & getB2DRange() const
Get the B2DRange (Rectangle dimensions) of this B2DPolygon.
B2DPolygon const & getDefaultAdaptiveSubdivision() const
Default adaptive subdivision access.
A two-dimensional interval over doubles.
Definition: b2drange.hxx:54
const basegfx::B2DPolygon * begin() const
void insert(sal_uInt32 nIndex, const basegfx::B2DPolygon &rPolygon, sal_uInt32 nCount)
const basegfx::B2DPolygon & getB2DPolygon(sal_uInt32 nIndex) const
std::unique_ptr< basegfx::SystemDependentDataHolder > mpSystemDependentDataHolder
void append(const basegfx::B2DPolyPolygon &rPolyPolygon)
const basegfx::B2DPolygon * end() const
void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
void insert(sal_uInt32 nIndex, const basegfx::B2DPolyPolygon &rPolyPolygon)
bool operator==(const ImplB2DPolyPolygon &rPolygonList) const
basegfx::SystemDependentData_SharedPtr getSystemDependentData(size_t hash_code) const
basegfx::B2DPolygonVector maPolygons
void reserve(sal_uInt32 nCount)
ImplB2DPolyPolygon(const ImplB2DPolyPolygon &rSource)
void setB2DPolygon(sal_uInt32 nIndex, const basegfx::B2DPolygon &rPolygon)
ImplB2DPolyPolygon & operator=(const ImplB2DPolyPolygon &rSource)
basegfx::B2DPolygon * begin()
void addOrReplaceSystemDependentData(basegfx::SystemDependentData_SharedPtr &rData) const
void append(const basegfx::B2DPolygon &rPolygon, sal_uInt32 nCount)
ImplB2DPolyPolygon(const basegfx::B2DPolygon &rToBeCopied)
basegfx::B2DPolygon * end()
void transform(const basegfx::B2DHomMatrix &rMatrix)
void expand(const Tuple2D< TYPE > &rTuple)
add point to the set, expanding as necessary
Definition: Range2D.hxx:142
int nCount
sal_Int32 nIndex
uno_Any a
::std::vector< B2DPolygon > B2DPolygonVector
Definition: b2dpolygon.hxx:262
std::shared_ptr< SystemDependentData > SystemDependentData_SharedPtr
Definition: b2dpolygon.hxx:41