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>
27 class ImplB3DPolyPolygon
29 typedef std::vector
< ::basegfx::B3DPolygon
> PolygonVector
;
31 PolygonVector maPolygons
;
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())
49 // compare polygon content
50 if(maPolygons
!= rPolygonList
.maPolygons
)
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
)
70 // add nCount copies of rPolygon
71 PolygonVector::iterator
aIndex(maPolygons
.begin());
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());
84 maPolygons
.insert(aIndex
, rPolyPolygon
.begin(), rPolyPolygon
.end());
87 void remove(sal_uInt32 nIndex
, sal_uInt32 nCount
)
91 // remove polygon data
92 PolygonVector::iterator
aStart(maPolygons
.begin());
94 const PolygonVector::iterator
aEnd(aStart
+ nCount
);
96 maPolygons
.erase(aStart
, aEnd
);
100 sal_uInt32
count() const
102 return maPolygons
.size();
107 for (auto& aPolygon
: maPolygons
)
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
);
125 for (auto& aPolygon
: maPolygons
)
126 aPolygon
.clearBColors();
129 void transformNormals(const ::basegfx::B3DHomMatrix
& rMatrix
)
131 for (auto& aPolygon
: maPolygons
)
132 aPolygon
.transformNormals(rMatrix
);
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())
158 return maPolygons
.data();
161 const basegfx::B3DPolygon
* end() const
163 if (maPolygons
.empty())
166 return maPolygons
.data() + maPolygons
.size();
169 basegfx::B3DPolygon
* begin()
171 if (maPolygons
.empty())
174 return maPolygons
.data();
177 basegfx::B3DPolygon
* end()
179 if (maPolygons
.empty())
182 return maPolygons
.data() + maPolygons
.size();
190 B3DPolyPolygon::ImplType
const & getDefaultPolyPolygon() {
191 static B3DPolyPolygon::ImplType
const 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
))
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())
263 void B3DPolyPolygon::clearBColors()
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())
288 void B3DPolyPolygon::clearNormals()
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())
313 void B3DPolyPolygon::clearTextureCoordinates()
315 if(areTextureCoordinatesUsed())
316 mpPolyPolygon
->clearTextureCoordinates();
319 void B3DPolyPolygon::append(const B3DPolygon
& rPolygon
, sal_uInt32 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 (!)");
336 mpPolyPolygon
->remove(nIndex
, nCount
);
339 void B3DPolyPolygon::clear()
341 mpPolyPolygon
= getDefaultPolyPolygon();
344 void B3DPolyPolygon::flip()
346 mpPolyPolygon
->flip();
349 bool B3DPolyPolygon::hasDoublePoints() const
353 for(sal_uInt32
a(0); !bRetval
&& a
< mpPolyPolygon
->count(); a
++)
355 if(mpPolyPolygon
->getB3DPolygon(a
).hasDoublePoints())
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: */