1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
28 class ImplB3DPolyPolygon
30 typedef std::vector
< ::basegfx::B3DPolygon
> PolygonVector
;
32 PolygonVector maPolygons
;
39 explicit ImplB3DPolyPolygon(const ::basegfx::B3DPolygon
& rToBeCopied
) :
40 maPolygons(1,rToBeCopied
)
44 bool operator==(const ImplB3DPolyPolygon
& rPolygonList
) const
46 // same polygon count?
47 if(maPolygons
.size() != rPolygonList
.maPolygons
.size())
50 // compare polygon content
51 if(maPolygons
!= rPolygonList
.maPolygons
)
57 const ::basegfx::B3DPolygon
& getB3DPolygon(sal_uInt32 nIndex
) const
59 return maPolygons
[nIndex
];
62 void setB3DPolygon(sal_uInt32 nIndex
, const ::basegfx::B3DPolygon
& rPolygon
)
64 maPolygons
[nIndex
] = rPolygon
;
67 void insert(sal_uInt32 nIndex
, const ::basegfx::B3DPolygon
& rPolygon
, sal_uInt32 nCount
)
71 // add nCount copies of rPolygon
72 PolygonVector::iterator
aIndex(maPolygons
.begin());
75 maPolygons
.insert(aIndex
, nCount
, rPolygon
);
79 void insert(sal_uInt32 nIndex
, const ::basegfx::B3DPolyPolygon
& rPolyPolygon
)
81 // add all polygons from rPolyPolygon
82 PolygonVector::iterator
aIndex(maPolygons
.begin());
85 maPolygons
.insert(aIndex
, rPolyPolygon
.begin(), rPolyPolygon
.end());
88 void remove(sal_uInt32 nIndex
, sal_uInt32 nCount
)
92 // remove polygon data
93 PolygonVector::iterator
aStart(maPolygons
.begin());
95 const PolygonVector::iterator
aEnd(aStart
+ nCount
);
97 maPolygons
.erase(aStart
, aEnd
);
101 sal_uInt32
count() const
103 return maPolygons
.size();
108 for (auto& aPolygon
: maPolygons
)
112 void removeDoublePoints()
114 for (auto& aPolygon
: maPolygons
)
115 aPolygon
.removeDoublePoints();
118 void transform(const ::basegfx::B3DHomMatrix
& rMatrix
)
120 for (auto& aPolygon
: maPolygons
)
121 aPolygon
.transform(rMatrix
);
126 for (auto& aPolygon
: maPolygons
)
127 aPolygon
.clearBColors();
130 void transformNormals(const ::basegfx::B3DHomMatrix
& rMatrix
)
132 for (auto& aPolygon
: maPolygons
)
133 aPolygon
.transformNormals(rMatrix
);
138 for (auto& aPolygon
: maPolygons
)
139 aPolygon
.clearNormals();
142 void transformTextureCoordinates(const ::basegfx::B2DHomMatrix
& rMatrix
)
144 for (auto& aPolygon
: maPolygons
)
145 aPolygon
.transformTextureCoordinates(rMatrix
);
148 void clearTextureCoordinates()
150 for (auto& aPolygon
: maPolygons
)
151 aPolygon
.clearTextureCoordinates();
154 const basegfx::B3DPolygon
* begin() const
156 if (maPolygons
.empty())
159 return maPolygons
.data();
162 const basegfx::B3DPolygon
* end() const
164 if (maPolygons
.empty())
167 return maPolygons
.data() + maPolygons
.size();
170 basegfx::B3DPolygon
* begin()
172 if (maPolygons
.empty())
175 return maPolygons
.data();
178 basegfx::B3DPolygon
* end()
180 if (maPolygons
.empty())
183 return maPolygons
.data() + maPolygons
.size();
191 B3DPolyPolygon::ImplType
const & getDefaultPolyPolygon() {
192 static B3DPolyPolygon::ImplType
const singleton
;
198 B3DPolyPolygon::B3DPolyPolygon() :
199 mpPolyPolygon(getDefaultPolyPolygon())
203 B3DPolyPolygon::B3DPolyPolygon(const B3DPolyPolygon
&) = default;
205 B3DPolyPolygon::B3DPolyPolygon(B3DPolyPolygon
&&) = default;
207 B3DPolyPolygon::B3DPolyPolygon(const B3DPolygon
& rPolygon
) :
208 mpPolyPolygon( ImplB3DPolyPolygon(rPolygon
) )
212 B3DPolyPolygon::~B3DPolyPolygon() = default;
214 B3DPolyPolygon
& B3DPolyPolygon::operator=(const B3DPolyPolygon
&) = default;
216 B3DPolyPolygon
& B3DPolyPolygon::operator=(B3DPolyPolygon
&&) = default;
218 bool B3DPolyPolygon::operator==(const B3DPolyPolygon
& rPolyPolygon
) const
220 if(mpPolyPolygon
.same_object(rPolyPolygon
.mpPolyPolygon
))
223 return ((*mpPolyPolygon
) == (*rPolyPolygon
.mpPolyPolygon
));
226 bool B3DPolyPolygon::operator!=(const B3DPolyPolygon
& rPolyPolygon
) const
228 return !(*this == rPolyPolygon
);
231 sal_uInt32
B3DPolyPolygon::count() const
233 return mpPolyPolygon
->count();
236 B3DPolygon
const & B3DPolyPolygon::getB3DPolygon(sal_uInt32 nIndex
) const
238 OSL_ENSURE(nIndex
< mpPolyPolygon
->count(), "B3DPolyPolygon access outside range (!)");
240 return mpPolyPolygon
->getB3DPolygon(nIndex
);
243 void B3DPolyPolygon::setB3DPolygon(sal_uInt32 nIndex
, const B3DPolygon
& rPolygon
)
245 OSL_ENSURE(nIndex
< std::as_const(mpPolyPolygon
)->count(), "B3DPolyPolygon access outside range (!)");
247 if(getB3DPolygon(nIndex
) != rPolygon
)
248 mpPolyPolygon
->setB3DPolygon(nIndex
, rPolygon
);
251 bool B3DPolyPolygon::areBColorsUsed() const
253 for(sal_uInt32
a(0); a
< mpPolyPolygon
->count(); a
++)
255 if(mpPolyPolygon
->getB3DPolygon(a
).areBColorsUsed())
264 void B3DPolyPolygon::clearBColors()
267 mpPolyPolygon
->clearBColors();
270 void B3DPolyPolygon::transformNormals(const B3DHomMatrix
& rMatrix
)
272 if(!rMatrix
.isIdentity())
273 mpPolyPolygon
->transformNormals(rMatrix
);
276 bool B3DPolyPolygon::areNormalsUsed() const
278 for(sal_uInt32
a(0); a
< mpPolyPolygon
->count(); a
++)
280 if(mpPolyPolygon
->getB3DPolygon(a
).areNormalsUsed())
289 void B3DPolyPolygon::clearNormals()
292 mpPolyPolygon
->clearNormals();
295 void B3DPolyPolygon::transformTextureCoordinates(const B2DHomMatrix
& rMatrix
)
297 if(!rMatrix
.isIdentity())
298 mpPolyPolygon
->transformTextureCoordinates(rMatrix
);
301 bool B3DPolyPolygon::areTextureCoordinatesUsed() const
303 for(sal_uInt32
a(0); a
< mpPolyPolygon
->count(); a
++)
305 if(mpPolyPolygon
->getB3DPolygon(a
).areTextureCoordinatesUsed())
314 void B3DPolyPolygon::clearTextureCoordinates()
316 if(areTextureCoordinatesUsed())
317 mpPolyPolygon
->clearTextureCoordinates();
320 void B3DPolyPolygon::append(const B3DPolygon
& rPolygon
, sal_uInt32 nCount
)
323 mpPolyPolygon
->insert(std::as_const(mpPolyPolygon
)->count(), rPolygon
, nCount
);
326 void B3DPolyPolygon::append(const B3DPolyPolygon
& rPolyPolygon
)
328 if(rPolyPolygon
.count())
329 mpPolyPolygon
->insert(std::as_const(mpPolyPolygon
)->count(), rPolyPolygon
);
332 void B3DPolyPolygon::remove(sal_uInt32 nIndex
, sal_uInt32 nCount
)
334 OSL_ENSURE(nIndex
+ nCount
<= std::as_const(mpPolyPolygon
)->count(), "B3DPolyPolygon Remove outside range (!)");
337 mpPolyPolygon
->remove(nIndex
, nCount
);
340 void B3DPolyPolygon::clear()
342 mpPolyPolygon
= getDefaultPolyPolygon();
345 void B3DPolyPolygon::flip()
347 mpPolyPolygon
->flip();
350 bool B3DPolyPolygon::hasDoublePoints() const
354 for(sal_uInt32
a(0); !bRetval
&& a
< mpPolyPolygon
->count(); a
++)
356 if(mpPolyPolygon
->getB3DPolygon(a
).hasDoublePoints())
365 void B3DPolyPolygon::removeDoublePoints()
367 if(hasDoublePoints())
368 mpPolyPolygon
->removeDoublePoints();
371 void B3DPolyPolygon::transform(const B3DHomMatrix
& rMatrix
)
373 if(std::as_const(mpPolyPolygon
)->count() && !rMatrix
.isIdentity())
375 mpPolyPolygon
->transform(rMatrix
);
379 const B3DPolygon
* B3DPolyPolygon::begin() const
381 return mpPolyPolygon
->begin();
384 const B3DPolygon
* B3DPolyPolygon::end() const
386 return mpPolyPolygon
->end();
389 B3DPolygon
* B3DPolyPolygon::begin()
391 return mpPolyPolygon
->begin();
394 B3DPolygon
* B3DPolyPolygon::end()
396 return mpPolyPolygon
->end();
398 } // end of namespace basegfx
400 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */