1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_basegfx.hxx"
30*cdf0e10cSrcweir #include <osl/diagnose.h>
31*cdf0e10cSrcweir #include <basegfx/polygon/b3dpolygon.hxx>
32*cdf0e10cSrcweir #include <basegfx/point/b3dpoint.hxx>
33*cdf0e10cSrcweir #include <basegfx/matrix/b3dhommatrix.hxx>
34*cdf0e10cSrcweir #include <rtl/instance.hxx>
35*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
36*cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx>
37*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
38*cdf0e10cSrcweir #include <vector>
39*cdf0e10cSrcweir #include <algorithm>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir class CoordinateData3D
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir 	basegfx::B3DPoint								maPoint;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir public:
48*cdf0e10cSrcweir 	CoordinateData3D()
49*cdf0e10cSrcweir 	:	maPoint()
50*cdf0e10cSrcweir 	{
51*cdf0e10cSrcweir 	}
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 	explicit CoordinateData3D(const basegfx::B3DPoint& rData)
54*cdf0e10cSrcweir 	:	maPoint(rData)
55*cdf0e10cSrcweir 	{
56*cdf0e10cSrcweir 	}
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 	const basegfx::B3DPoint& getCoordinate() const
59*cdf0e10cSrcweir 	{
60*cdf0e10cSrcweir 		return maPoint;
61*cdf0e10cSrcweir 	}
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 	void setCoordinate(const basegfx::B3DPoint& rValue)
64*cdf0e10cSrcweir 	{
65*cdf0e10cSrcweir 		if(rValue != maPoint)
66*cdf0e10cSrcweir 			maPoint = rValue;
67*cdf0e10cSrcweir 	}
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 	bool operator==(const CoordinateData3D& rData) const
70*cdf0e10cSrcweir 	{
71*cdf0e10cSrcweir 		return (maPoint == rData.getCoordinate());
72*cdf0e10cSrcweir 	}
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 	void transform(const basegfx::B3DHomMatrix& rMatrix)
75*cdf0e10cSrcweir 	{
76*cdf0e10cSrcweir 		maPoint *= rMatrix;
77*cdf0e10cSrcweir 	}
78*cdf0e10cSrcweir };
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir class CoordinateDataArray3D
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir 	typedef ::std::vector< CoordinateData3D > CoordinateData3DVector;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 	CoordinateData3DVector							maVector;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir public:
89*cdf0e10cSrcweir 	explicit CoordinateDataArray3D(sal_uInt32 nCount)
90*cdf0e10cSrcweir 	:	maVector(nCount)
91*cdf0e10cSrcweir 	{
92*cdf0e10cSrcweir 	}
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 	explicit CoordinateDataArray3D(const CoordinateDataArray3D& rOriginal)
95*cdf0e10cSrcweir 	:	maVector(rOriginal.maVector)
96*cdf0e10cSrcweir 	{
97*cdf0e10cSrcweir 	}
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 	CoordinateDataArray3D(const CoordinateDataArray3D& rOriginal, sal_uInt32 nIndex, sal_uInt32 nCount)
100*cdf0e10cSrcweir 	:	maVector(rOriginal.maVector.begin() + nIndex, rOriginal.maVector.begin() + (nIndex + nCount))
101*cdf0e10cSrcweir 	{
102*cdf0e10cSrcweir 	}
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 	~CoordinateDataArray3D()
105*cdf0e10cSrcweir 	{
106*cdf0e10cSrcweir 	}
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	::basegfx::B3DVector getNormal() const
109*cdf0e10cSrcweir 	{
110*cdf0e10cSrcweir 		::basegfx::B3DVector aRetval;
111*cdf0e10cSrcweir 		const sal_uInt32 nPointCount(maVector.size());
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 		if(nPointCount > 2)
114*cdf0e10cSrcweir 		{
115*cdf0e10cSrcweir             sal_uInt32 nISmallest(0);
116*cdf0e10cSrcweir             sal_uInt32 a(0);
117*cdf0e10cSrcweir             const basegfx::B3DPoint* pSmallest(&maVector[0].getCoordinate());
118*cdf0e10cSrcweir             const basegfx::B3DPoint* pNext(0);
119*cdf0e10cSrcweir             const basegfx::B3DPoint* pPrev(0);
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir             // To guarantee a correctly oriented point, choose an outmost one
122*cdf0e10cSrcweir             // which then cannot be concave
123*cdf0e10cSrcweir             for(a = 1; a < nPointCount; a++)
124*cdf0e10cSrcweir             {
125*cdf0e10cSrcweir             	const basegfx::B3DPoint& rCandidate = maVector[a].getCoordinate();
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir                 if((rCandidate.getX() < pSmallest->getX())
128*cdf0e10cSrcweir                     || (rCandidate.getX() == pSmallest->getX() && rCandidate.getY() < pSmallest->getY())
129*cdf0e10cSrcweir                     || (rCandidate.getX() == pSmallest->getX() && rCandidate.getY() == pSmallest->getY() && rCandidate.getZ() < pSmallest->getZ()))
130*cdf0e10cSrcweir                 {
131*cdf0e10cSrcweir                     nISmallest = a;
132*cdf0e10cSrcweir                     pSmallest = &rCandidate;
133*cdf0e10cSrcweir                 }
134*cdf0e10cSrcweir             }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir             // look for a next point different from minimal one
137*cdf0e10cSrcweir             for(a = (nISmallest + 1) % nPointCount; a != nISmallest; a = (a + 1) % nPointCount)
138*cdf0e10cSrcweir             {
139*cdf0e10cSrcweir             	const basegfx::B3DPoint& rCandidate = maVector[a].getCoordinate();
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir                 if(!rCandidate.equal(*pSmallest))
142*cdf0e10cSrcweir                 {
143*cdf0e10cSrcweir                 	pNext = &rCandidate;
144*cdf0e10cSrcweir                     break;
145*cdf0e10cSrcweir                 }
146*cdf0e10cSrcweir             }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir             // look for a previous point different from minimal one
149*cdf0e10cSrcweir             for(a = (nISmallest + nPointCount - 1) % nPointCount; a != nISmallest; a = (a + nPointCount - 1) % nPointCount)
150*cdf0e10cSrcweir             {
151*cdf0e10cSrcweir             	const basegfx::B3DPoint& rCandidate = maVector[a].getCoordinate();
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir                 if(!rCandidate.equal(*pSmallest))
154*cdf0e10cSrcweir                 {
155*cdf0e10cSrcweir                 	pPrev = &rCandidate;
156*cdf0e10cSrcweir                     break;
157*cdf0e10cSrcweir                 }
158*cdf0e10cSrcweir             }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir             // we always have a minimal point. If we also have a different next and previous,
161*cdf0e10cSrcweir             // we can calculate the normal
162*cdf0e10cSrcweir             if(pNext && pPrev)
163*cdf0e10cSrcweir             {
164*cdf0e10cSrcweir                 const basegfx::B3DVector aPrev(*pPrev - *pSmallest);
165*cdf0e10cSrcweir                 const basegfx::B3DVector aNext(*pNext - *pSmallest);
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir                 aRetval = cross(aPrev, aNext);
168*cdf0e10cSrcweir     			aRetval.normalize();
169*cdf0e10cSrcweir             }
170*cdf0e10cSrcweir 		}
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 		return aRetval;
173*cdf0e10cSrcweir 	}
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	sal_uInt32 count() const
176*cdf0e10cSrcweir 	{
177*cdf0e10cSrcweir 		return maVector.size();
178*cdf0e10cSrcweir 	}
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 	bool operator==(const CoordinateDataArray3D& rCandidate) const
181*cdf0e10cSrcweir 	{
182*cdf0e10cSrcweir 		return (maVector == rCandidate.maVector);
183*cdf0e10cSrcweir 	}
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	const basegfx::B3DPoint& getCoordinate(sal_uInt32 nIndex) const
186*cdf0e10cSrcweir 	{
187*cdf0e10cSrcweir 		return maVector[nIndex].getCoordinate();
188*cdf0e10cSrcweir 	}
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	void setCoordinate(sal_uInt32 nIndex, const basegfx::B3DPoint& rValue)
191*cdf0e10cSrcweir 	{
192*cdf0e10cSrcweir 		maVector[nIndex].setCoordinate(rValue);
193*cdf0e10cSrcweir 	}
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 	void insert(sal_uInt32 nIndex, const CoordinateData3D& rValue, sal_uInt32 nCount)
196*cdf0e10cSrcweir 	{
197*cdf0e10cSrcweir 		if(nCount)
198*cdf0e10cSrcweir 		{
199*cdf0e10cSrcweir 			// add nCount copies of rValue
200*cdf0e10cSrcweir 			CoordinateData3DVector::iterator aIndex(maVector.begin());
201*cdf0e10cSrcweir 			aIndex += nIndex;
202*cdf0e10cSrcweir 			maVector.insert(aIndex, nCount, rValue);
203*cdf0e10cSrcweir 		}
204*cdf0e10cSrcweir 	}
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 	void insert(sal_uInt32 nIndex, const CoordinateDataArray3D& rSource)
207*cdf0e10cSrcweir 	{
208*cdf0e10cSrcweir 		const sal_uInt32 nCount(rSource.maVector.size());
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 		if(nCount)
211*cdf0e10cSrcweir 		{
212*cdf0e10cSrcweir 			// insert data
213*cdf0e10cSrcweir 			CoordinateData3DVector::iterator aIndex(maVector.begin());
214*cdf0e10cSrcweir 			aIndex += nIndex;
215*cdf0e10cSrcweir 			CoordinateData3DVector::const_iterator aStart(rSource.maVector.begin());
216*cdf0e10cSrcweir 			CoordinateData3DVector::const_iterator aEnd(rSource.maVector.end());
217*cdf0e10cSrcweir 			maVector.insert(aIndex, aStart, aEnd);
218*cdf0e10cSrcweir 		}
219*cdf0e10cSrcweir 	}
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 	void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
222*cdf0e10cSrcweir 	{
223*cdf0e10cSrcweir 		if(nCount)
224*cdf0e10cSrcweir 		{
225*cdf0e10cSrcweir 			// remove point data
226*cdf0e10cSrcweir 			CoordinateData3DVector::iterator aStart(maVector.begin());
227*cdf0e10cSrcweir 			aStart += nIndex;
228*cdf0e10cSrcweir 			const CoordinateData3DVector::iterator aEnd(aStart + nCount);
229*cdf0e10cSrcweir 			maVector.erase(aStart, aEnd);
230*cdf0e10cSrcweir 		}
231*cdf0e10cSrcweir 	}
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 	void flip()
234*cdf0e10cSrcweir 	{
235*cdf0e10cSrcweir 		if(maVector.size() > 1)
236*cdf0e10cSrcweir 		{
237*cdf0e10cSrcweir 			const sal_uInt32 nHalfSize(maVector.size() >> 1L);
238*cdf0e10cSrcweir 			CoordinateData3DVector::iterator aStart(maVector.begin());
239*cdf0e10cSrcweir 			CoordinateData3DVector::iterator aEnd(maVector.end() - 1L);
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 			for(sal_uInt32 a(0); a < nHalfSize; a++)
242*cdf0e10cSrcweir 			{
243*cdf0e10cSrcweir 				::std::swap(*aStart, *aEnd);
244*cdf0e10cSrcweir 				aStart++;
245*cdf0e10cSrcweir 				aEnd--;
246*cdf0e10cSrcweir 			}
247*cdf0e10cSrcweir 		}
248*cdf0e10cSrcweir 	}
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir 	void transform(const ::basegfx::B3DHomMatrix& rMatrix)
251*cdf0e10cSrcweir 	{
252*cdf0e10cSrcweir 		CoordinateData3DVector::iterator aStart(maVector.begin());
253*cdf0e10cSrcweir 		CoordinateData3DVector::iterator aEnd(maVector.end());
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 		for(; aStart != aEnd; aStart++)
256*cdf0e10cSrcweir 		{
257*cdf0e10cSrcweir 			aStart->transform(rMatrix);
258*cdf0e10cSrcweir 		}
259*cdf0e10cSrcweir 	}
260*cdf0e10cSrcweir };
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir class BColorArray
265*cdf0e10cSrcweir {
266*cdf0e10cSrcweir 	typedef ::std::vector< ::basegfx::BColor > BColorDataVector;
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 	BColorDataVector									maVector;
269*cdf0e10cSrcweir 	sal_uInt32											mnUsedEntries;
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir public:
272*cdf0e10cSrcweir 	explicit BColorArray(sal_uInt32 nCount)
273*cdf0e10cSrcweir 	:	maVector(nCount),
274*cdf0e10cSrcweir 		mnUsedEntries(0L)
275*cdf0e10cSrcweir 	{
276*cdf0e10cSrcweir 	}
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir 	explicit BColorArray(const BColorArray& rOriginal)
279*cdf0e10cSrcweir 	:	maVector(rOriginal.maVector),
280*cdf0e10cSrcweir 		mnUsedEntries(rOriginal.mnUsedEntries)
281*cdf0e10cSrcweir 	{
282*cdf0e10cSrcweir 	}
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 	BColorArray(const BColorArray& rOriginal, sal_uInt32 nIndex, sal_uInt32 nCount)
285*cdf0e10cSrcweir 	:	maVector(),
286*cdf0e10cSrcweir 		mnUsedEntries(0L)
287*cdf0e10cSrcweir 	{
288*cdf0e10cSrcweir 		BColorDataVector::const_iterator aStart(rOriginal.maVector.begin());
289*cdf0e10cSrcweir 		aStart += nIndex;
290*cdf0e10cSrcweir 		BColorDataVector::const_iterator aEnd(aStart);
291*cdf0e10cSrcweir 		aEnd += nCount;
292*cdf0e10cSrcweir 		maVector.reserve(nCount);
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 		for(; aStart != aEnd; aStart++)
295*cdf0e10cSrcweir 		{
296*cdf0e10cSrcweir 			if(!aStart->equalZero())
297*cdf0e10cSrcweir 				mnUsedEntries++;
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir 			maVector.push_back(*aStart);
300*cdf0e10cSrcweir 		}
301*cdf0e10cSrcweir 	}
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 	~BColorArray()
304*cdf0e10cSrcweir 	{
305*cdf0e10cSrcweir 	}
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 	sal_uInt32 count() const
308*cdf0e10cSrcweir 	{
309*cdf0e10cSrcweir 		return maVector.size();
310*cdf0e10cSrcweir 	}
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir 	bool operator==(const BColorArray& rCandidate) const
313*cdf0e10cSrcweir 	{
314*cdf0e10cSrcweir 		return (maVector == rCandidate.maVector);
315*cdf0e10cSrcweir 	}
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir 	bool isUsed() const
318*cdf0e10cSrcweir 	{
319*cdf0e10cSrcweir 		return (0L != mnUsedEntries);
320*cdf0e10cSrcweir 	}
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir 	const ::basegfx::BColor& getBColor(sal_uInt32 nIndex) const
323*cdf0e10cSrcweir 	{
324*cdf0e10cSrcweir 		return maVector[nIndex];
325*cdf0e10cSrcweir 	}
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 	void setBColor(sal_uInt32 nIndex, const ::basegfx::BColor& rValue)
328*cdf0e10cSrcweir 	{
329*cdf0e10cSrcweir 		bool bWasUsed(mnUsedEntries && !maVector[nIndex].equalZero());
330*cdf0e10cSrcweir 		bool bIsUsed(!rValue.equalZero());
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 		if(bWasUsed)
333*cdf0e10cSrcweir 		{
334*cdf0e10cSrcweir 			if(bIsUsed)
335*cdf0e10cSrcweir 			{
336*cdf0e10cSrcweir 				maVector[nIndex] = rValue;
337*cdf0e10cSrcweir 			}
338*cdf0e10cSrcweir 			else
339*cdf0e10cSrcweir 			{
340*cdf0e10cSrcweir 				maVector[nIndex] = ::basegfx::BColor::getEmptyBColor();
341*cdf0e10cSrcweir 				mnUsedEntries--;
342*cdf0e10cSrcweir 			}
343*cdf0e10cSrcweir 		}
344*cdf0e10cSrcweir 		else
345*cdf0e10cSrcweir 		{
346*cdf0e10cSrcweir 			if(bIsUsed)
347*cdf0e10cSrcweir 			{
348*cdf0e10cSrcweir 				maVector[nIndex] = rValue;
349*cdf0e10cSrcweir 				mnUsedEntries++;
350*cdf0e10cSrcweir 			}
351*cdf0e10cSrcweir 		}
352*cdf0e10cSrcweir 	}
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 	void insert(sal_uInt32 nIndex, const ::basegfx::BColor& rValue, sal_uInt32 nCount)
355*cdf0e10cSrcweir 	{
356*cdf0e10cSrcweir 		if(nCount)
357*cdf0e10cSrcweir 		{
358*cdf0e10cSrcweir 			// add nCount copies of rValue
359*cdf0e10cSrcweir 			BColorDataVector::iterator aIndex(maVector.begin());
360*cdf0e10cSrcweir 			aIndex += nIndex;
361*cdf0e10cSrcweir 			maVector.insert(aIndex, nCount, rValue);
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 			if(!rValue.equalZero())
364*cdf0e10cSrcweir 				mnUsedEntries += nCount;
365*cdf0e10cSrcweir 		}
366*cdf0e10cSrcweir 	}
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir 	void insert(sal_uInt32 nIndex, const BColorArray& rSource)
369*cdf0e10cSrcweir 	{
370*cdf0e10cSrcweir 		const sal_uInt32 nCount(rSource.maVector.size());
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 		if(nCount)
373*cdf0e10cSrcweir 		{
374*cdf0e10cSrcweir 			// insert data
375*cdf0e10cSrcweir 			BColorDataVector::iterator aIndex(maVector.begin());
376*cdf0e10cSrcweir 			aIndex += nIndex;
377*cdf0e10cSrcweir 			BColorDataVector::const_iterator aStart(rSource.maVector.begin());
378*cdf0e10cSrcweir 			BColorDataVector::const_iterator aEnd(rSource.maVector.end());
379*cdf0e10cSrcweir 			maVector.insert(aIndex, aStart, aEnd);
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 			for(; aStart != aEnd; aStart++)
382*cdf0e10cSrcweir 			{
383*cdf0e10cSrcweir 				if(!aStart->equalZero())
384*cdf0e10cSrcweir 					mnUsedEntries++;
385*cdf0e10cSrcweir 			}
386*cdf0e10cSrcweir 		}
387*cdf0e10cSrcweir 	}
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir 	void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
390*cdf0e10cSrcweir 	{
391*cdf0e10cSrcweir 		if(nCount)
392*cdf0e10cSrcweir 		{
393*cdf0e10cSrcweir 			const BColorDataVector::iterator aDeleteStart(maVector.begin() + nIndex);
394*cdf0e10cSrcweir 			const BColorDataVector::iterator aDeleteEnd(aDeleteStart + nCount);
395*cdf0e10cSrcweir 			BColorDataVector::const_iterator aStart(aDeleteStart);
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir 			for(; mnUsedEntries && aStart != aDeleteEnd; aStart++)
398*cdf0e10cSrcweir 			{
399*cdf0e10cSrcweir 				if(!aStart->equalZero())
400*cdf0e10cSrcweir 					mnUsedEntries--;
401*cdf0e10cSrcweir 			}
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir 			// remove point data
404*cdf0e10cSrcweir 			maVector.erase(aDeleteStart, aDeleteEnd);
405*cdf0e10cSrcweir 		}
406*cdf0e10cSrcweir 	}
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir 	void flip()
409*cdf0e10cSrcweir 	{
410*cdf0e10cSrcweir 		if(maVector.size() > 1)
411*cdf0e10cSrcweir 		{
412*cdf0e10cSrcweir 			const sal_uInt32 nHalfSize(maVector.size() >> 1L);
413*cdf0e10cSrcweir 			BColorDataVector::iterator aStart(maVector.begin());
414*cdf0e10cSrcweir 			BColorDataVector::iterator aEnd(maVector.end() - 1L);
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir 			for(sal_uInt32 a(0); a < nHalfSize; a++)
417*cdf0e10cSrcweir 			{
418*cdf0e10cSrcweir 				::std::swap(*aStart, *aEnd);
419*cdf0e10cSrcweir 				aStart++;
420*cdf0e10cSrcweir 				aEnd--;
421*cdf0e10cSrcweir 			}
422*cdf0e10cSrcweir 		}
423*cdf0e10cSrcweir 	}
424*cdf0e10cSrcweir };
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir class NormalsArray3D
429*cdf0e10cSrcweir {
430*cdf0e10cSrcweir 	typedef ::std::vector< ::basegfx::B3DVector > NormalsData3DVector;
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir 	NormalsData3DVector									maVector;
433*cdf0e10cSrcweir 	sal_uInt32											mnUsedEntries;
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir public:
436*cdf0e10cSrcweir 	explicit NormalsArray3D(sal_uInt32 nCount)
437*cdf0e10cSrcweir 	:	maVector(nCount),
438*cdf0e10cSrcweir 		mnUsedEntries(0L)
439*cdf0e10cSrcweir 	{
440*cdf0e10cSrcweir 	}
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 	explicit NormalsArray3D(const NormalsArray3D& rOriginal)
443*cdf0e10cSrcweir 	:	maVector(rOriginal.maVector),
444*cdf0e10cSrcweir 		mnUsedEntries(rOriginal.mnUsedEntries)
445*cdf0e10cSrcweir 	{
446*cdf0e10cSrcweir 	}
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 	NormalsArray3D(const NormalsArray3D& rOriginal, sal_uInt32 nIndex, sal_uInt32 nCount)
449*cdf0e10cSrcweir 	:	maVector(),
450*cdf0e10cSrcweir 		mnUsedEntries(0L)
451*cdf0e10cSrcweir 	{
452*cdf0e10cSrcweir 		NormalsData3DVector::const_iterator aStart(rOriginal.maVector.begin());
453*cdf0e10cSrcweir 		aStart += nIndex;
454*cdf0e10cSrcweir 		NormalsData3DVector::const_iterator aEnd(aStart);
455*cdf0e10cSrcweir 		aEnd += nCount;
456*cdf0e10cSrcweir 		maVector.reserve(nCount);
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir 		for(; aStart != aEnd; aStart++)
459*cdf0e10cSrcweir 		{
460*cdf0e10cSrcweir 			if(!aStart->equalZero())
461*cdf0e10cSrcweir 				mnUsedEntries++;
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir 			maVector.push_back(*aStart);
464*cdf0e10cSrcweir 		}
465*cdf0e10cSrcweir 	}
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir 	~NormalsArray3D()
468*cdf0e10cSrcweir 	{
469*cdf0e10cSrcweir 	}
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 	sal_uInt32 count() const
472*cdf0e10cSrcweir 	{
473*cdf0e10cSrcweir 		return maVector.size();
474*cdf0e10cSrcweir 	}
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir 	bool operator==(const NormalsArray3D& rCandidate) const
477*cdf0e10cSrcweir 	{
478*cdf0e10cSrcweir 		return (maVector == rCandidate.maVector);
479*cdf0e10cSrcweir 	}
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir 	bool isUsed() const
482*cdf0e10cSrcweir 	{
483*cdf0e10cSrcweir 		return (0L != mnUsedEntries);
484*cdf0e10cSrcweir 	}
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir 	const ::basegfx::B3DVector& getNormal(sal_uInt32 nIndex) const
487*cdf0e10cSrcweir 	{
488*cdf0e10cSrcweir 		return maVector[nIndex];
489*cdf0e10cSrcweir 	}
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir 	void setNormal(sal_uInt32 nIndex, const ::basegfx::B3DVector& rValue)
492*cdf0e10cSrcweir 	{
493*cdf0e10cSrcweir 		bool bWasUsed(mnUsedEntries && !maVector[nIndex].equalZero());
494*cdf0e10cSrcweir 		bool bIsUsed(!rValue.equalZero());
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir 		if(bWasUsed)
497*cdf0e10cSrcweir 		{
498*cdf0e10cSrcweir 			if(bIsUsed)
499*cdf0e10cSrcweir 			{
500*cdf0e10cSrcweir 				maVector[nIndex] = rValue;
501*cdf0e10cSrcweir 			}
502*cdf0e10cSrcweir 			else
503*cdf0e10cSrcweir 			{
504*cdf0e10cSrcweir 				maVector[nIndex] = ::basegfx::B3DVector::getEmptyVector();
505*cdf0e10cSrcweir 				mnUsedEntries--;
506*cdf0e10cSrcweir 			}
507*cdf0e10cSrcweir 		}
508*cdf0e10cSrcweir 		else
509*cdf0e10cSrcweir 		{
510*cdf0e10cSrcweir 			if(bIsUsed)
511*cdf0e10cSrcweir 			{
512*cdf0e10cSrcweir 				maVector[nIndex] = rValue;
513*cdf0e10cSrcweir 				mnUsedEntries++;
514*cdf0e10cSrcweir 			}
515*cdf0e10cSrcweir 		}
516*cdf0e10cSrcweir 	}
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir 	void insert(sal_uInt32 nIndex, const ::basegfx::B3DVector& rValue, sal_uInt32 nCount)
519*cdf0e10cSrcweir 	{
520*cdf0e10cSrcweir 		if(nCount)
521*cdf0e10cSrcweir 		{
522*cdf0e10cSrcweir 			// add nCount copies of rValue
523*cdf0e10cSrcweir 			NormalsData3DVector::iterator aIndex(maVector.begin());
524*cdf0e10cSrcweir 			aIndex += nIndex;
525*cdf0e10cSrcweir 			maVector.insert(aIndex, nCount, rValue);
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 			if(!rValue.equalZero())
528*cdf0e10cSrcweir 				mnUsedEntries += nCount;
529*cdf0e10cSrcweir 		}
530*cdf0e10cSrcweir 	}
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir 	void insert(sal_uInt32 nIndex, const NormalsArray3D& rSource)
533*cdf0e10cSrcweir 	{
534*cdf0e10cSrcweir 		const sal_uInt32 nCount(rSource.maVector.size());
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir 		if(nCount)
537*cdf0e10cSrcweir 		{
538*cdf0e10cSrcweir 			// insert data
539*cdf0e10cSrcweir 			NormalsData3DVector::iterator aIndex(maVector.begin());
540*cdf0e10cSrcweir 			aIndex += nIndex;
541*cdf0e10cSrcweir 			NormalsData3DVector::const_iterator aStart(rSource.maVector.begin());
542*cdf0e10cSrcweir 			NormalsData3DVector::const_iterator aEnd(rSource.maVector.end());
543*cdf0e10cSrcweir 			maVector.insert(aIndex, aStart, aEnd);
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir 			for(; aStart != aEnd; aStart++)
546*cdf0e10cSrcweir 			{
547*cdf0e10cSrcweir 				if(!aStart->equalZero())
548*cdf0e10cSrcweir 					mnUsedEntries++;
549*cdf0e10cSrcweir 			}
550*cdf0e10cSrcweir 		}
551*cdf0e10cSrcweir 	}
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir 	void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
554*cdf0e10cSrcweir 	{
555*cdf0e10cSrcweir 		if(nCount)
556*cdf0e10cSrcweir 		{
557*cdf0e10cSrcweir 			const NormalsData3DVector::iterator aDeleteStart(maVector.begin() + nIndex);
558*cdf0e10cSrcweir 			const NormalsData3DVector::iterator aDeleteEnd(aDeleteStart + nCount);
559*cdf0e10cSrcweir 			NormalsData3DVector::const_iterator aStart(aDeleteStart);
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir 			for(; mnUsedEntries && aStart != aDeleteEnd; aStart++)
562*cdf0e10cSrcweir 			{
563*cdf0e10cSrcweir 				if(!aStart->equalZero())
564*cdf0e10cSrcweir 					mnUsedEntries--;
565*cdf0e10cSrcweir 			}
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir 			// remove point data
568*cdf0e10cSrcweir 			maVector.erase(aDeleteStart, aDeleteEnd);
569*cdf0e10cSrcweir 		}
570*cdf0e10cSrcweir 	}
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir 	void flip()
573*cdf0e10cSrcweir 	{
574*cdf0e10cSrcweir 		if(maVector.size() > 1)
575*cdf0e10cSrcweir 		{
576*cdf0e10cSrcweir 			const sal_uInt32 nHalfSize(maVector.size() >> 1L);
577*cdf0e10cSrcweir 			NormalsData3DVector::iterator aStart(maVector.begin());
578*cdf0e10cSrcweir 			NormalsData3DVector::iterator aEnd(maVector.end() - 1L);
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 			for(sal_uInt32 a(0); a < nHalfSize; a++)
581*cdf0e10cSrcweir 			{
582*cdf0e10cSrcweir 				::std::swap(*aStart, *aEnd);
583*cdf0e10cSrcweir 				aStart++;
584*cdf0e10cSrcweir 				aEnd--;
585*cdf0e10cSrcweir 			}
586*cdf0e10cSrcweir 		}
587*cdf0e10cSrcweir 	}
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir 	void transform(const basegfx::B3DHomMatrix& rMatrix)
590*cdf0e10cSrcweir 	{
591*cdf0e10cSrcweir 		NormalsData3DVector::iterator aStart(maVector.begin());
592*cdf0e10cSrcweir 		NormalsData3DVector::iterator aEnd(maVector.end());
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir 		for(; aStart != aEnd; aStart++)
595*cdf0e10cSrcweir 		{
596*cdf0e10cSrcweir 			(*aStart) *= rMatrix;
597*cdf0e10cSrcweir 		}
598*cdf0e10cSrcweir 	}
599*cdf0e10cSrcweir };
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir class TextureCoordinate2D
604*cdf0e10cSrcweir {
605*cdf0e10cSrcweir 	typedef ::std::vector< ::basegfx::B2DPoint > TextureData2DVector;
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir 	TextureData2DVector									maVector;
608*cdf0e10cSrcweir 	sal_uInt32											mnUsedEntries;
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir public:
611*cdf0e10cSrcweir 	explicit TextureCoordinate2D(sal_uInt32 nCount)
612*cdf0e10cSrcweir 	:	maVector(nCount),
613*cdf0e10cSrcweir 		mnUsedEntries(0L)
614*cdf0e10cSrcweir 	{
615*cdf0e10cSrcweir 	}
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir 	explicit TextureCoordinate2D(const TextureCoordinate2D& rOriginal)
618*cdf0e10cSrcweir 	:	maVector(rOriginal.maVector),
619*cdf0e10cSrcweir 		mnUsedEntries(rOriginal.mnUsedEntries)
620*cdf0e10cSrcweir 	{
621*cdf0e10cSrcweir 	}
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir 	TextureCoordinate2D(const TextureCoordinate2D& rOriginal, sal_uInt32 nIndex, sal_uInt32 nCount)
624*cdf0e10cSrcweir 	:	maVector(),
625*cdf0e10cSrcweir 		mnUsedEntries(0L)
626*cdf0e10cSrcweir 	{
627*cdf0e10cSrcweir 		TextureData2DVector::const_iterator aStart(rOriginal.maVector.begin());
628*cdf0e10cSrcweir 		aStart += nIndex;
629*cdf0e10cSrcweir 		TextureData2DVector::const_iterator aEnd(aStart);
630*cdf0e10cSrcweir 		aEnd += nCount;
631*cdf0e10cSrcweir 		maVector.reserve(nCount);
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir 		for(; aStart != aEnd; aStart++)
634*cdf0e10cSrcweir 		{
635*cdf0e10cSrcweir 			if(!aStart->equalZero())
636*cdf0e10cSrcweir 				mnUsedEntries++;
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir 			maVector.push_back(*aStart);
639*cdf0e10cSrcweir 		}
640*cdf0e10cSrcweir 	}
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir 	~TextureCoordinate2D()
643*cdf0e10cSrcweir 	{
644*cdf0e10cSrcweir 	}
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir 	sal_uInt32 count() const
647*cdf0e10cSrcweir 	{
648*cdf0e10cSrcweir 		return maVector.size();
649*cdf0e10cSrcweir 	}
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir 	bool operator==(const TextureCoordinate2D& rCandidate) const
652*cdf0e10cSrcweir 	{
653*cdf0e10cSrcweir 		return (maVector == rCandidate.maVector);
654*cdf0e10cSrcweir 	}
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir 	bool isUsed() const
657*cdf0e10cSrcweir 	{
658*cdf0e10cSrcweir 		return (0L != mnUsedEntries);
659*cdf0e10cSrcweir 	}
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir 	const ::basegfx::B2DPoint& getTextureCoordinate(sal_uInt32 nIndex) const
662*cdf0e10cSrcweir 	{
663*cdf0e10cSrcweir 		return maVector[nIndex];
664*cdf0e10cSrcweir 	}
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir 	void setTextureCoordinate(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue)
667*cdf0e10cSrcweir 	{
668*cdf0e10cSrcweir 		bool bWasUsed(mnUsedEntries && !maVector[nIndex].equalZero());
669*cdf0e10cSrcweir 		bool bIsUsed(!rValue.equalZero());
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir 		if(bWasUsed)
672*cdf0e10cSrcweir 		{
673*cdf0e10cSrcweir 			if(bIsUsed)
674*cdf0e10cSrcweir 			{
675*cdf0e10cSrcweir 				maVector[nIndex] = rValue;
676*cdf0e10cSrcweir 			}
677*cdf0e10cSrcweir 			else
678*cdf0e10cSrcweir 			{
679*cdf0e10cSrcweir 				maVector[nIndex] = ::basegfx::B2DPoint::getEmptyPoint();
680*cdf0e10cSrcweir 				mnUsedEntries--;
681*cdf0e10cSrcweir 			}
682*cdf0e10cSrcweir 		}
683*cdf0e10cSrcweir 		else
684*cdf0e10cSrcweir 		{
685*cdf0e10cSrcweir 			if(bIsUsed)
686*cdf0e10cSrcweir 			{
687*cdf0e10cSrcweir 				maVector[nIndex] = rValue;
688*cdf0e10cSrcweir 				mnUsedEntries++;
689*cdf0e10cSrcweir 			}
690*cdf0e10cSrcweir 		}
691*cdf0e10cSrcweir 	}
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir 	void insert(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue, sal_uInt32 nCount)
694*cdf0e10cSrcweir 	{
695*cdf0e10cSrcweir 		if(nCount)
696*cdf0e10cSrcweir 		{
697*cdf0e10cSrcweir 			// add nCount copies of rValue
698*cdf0e10cSrcweir 			TextureData2DVector::iterator aIndex(maVector.begin());
699*cdf0e10cSrcweir 			aIndex += nIndex;
700*cdf0e10cSrcweir 			maVector.insert(aIndex, nCount, rValue);
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir 			if(!rValue.equalZero())
703*cdf0e10cSrcweir 				mnUsedEntries += nCount;
704*cdf0e10cSrcweir 		}
705*cdf0e10cSrcweir 	}
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir 	void insert(sal_uInt32 nIndex, const TextureCoordinate2D& rSource)
708*cdf0e10cSrcweir 	{
709*cdf0e10cSrcweir 		const sal_uInt32 nCount(rSource.maVector.size());
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir 		if(nCount)
712*cdf0e10cSrcweir 		{
713*cdf0e10cSrcweir 			// insert data
714*cdf0e10cSrcweir 			TextureData2DVector::iterator aIndex(maVector.begin());
715*cdf0e10cSrcweir 			aIndex += nIndex;
716*cdf0e10cSrcweir 			TextureData2DVector::const_iterator aStart(rSource.maVector.begin());
717*cdf0e10cSrcweir 			TextureData2DVector::const_iterator aEnd(rSource.maVector.end());
718*cdf0e10cSrcweir 			maVector.insert(aIndex, aStart, aEnd);
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir 			for(; aStart != aEnd; aStart++)
721*cdf0e10cSrcweir 			{
722*cdf0e10cSrcweir 				if(!aStart->equalZero())
723*cdf0e10cSrcweir 					mnUsedEntries++;
724*cdf0e10cSrcweir 			}
725*cdf0e10cSrcweir 		}
726*cdf0e10cSrcweir 	}
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir 	void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
729*cdf0e10cSrcweir 	{
730*cdf0e10cSrcweir 		if(nCount)
731*cdf0e10cSrcweir 		{
732*cdf0e10cSrcweir 			const TextureData2DVector::iterator aDeleteStart(maVector.begin() + nIndex);
733*cdf0e10cSrcweir 			const TextureData2DVector::iterator aDeleteEnd(aDeleteStart + nCount);
734*cdf0e10cSrcweir 			TextureData2DVector::const_iterator aStart(aDeleteStart);
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir 			for(; mnUsedEntries && aStart != aDeleteEnd; aStart++)
737*cdf0e10cSrcweir 			{
738*cdf0e10cSrcweir 				if(!aStart->equalZero())
739*cdf0e10cSrcweir 					mnUsedEntries--;
740*cdf0e10cSrcweir 			}
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir 			// remove point data
743*cdf0e10cSrcweir 			maVector.erase(aDeleteStart, aDeleteEnd);
744*cdf0e10cSrcweir 		}
745*cdf0e10cSrcweir 	}
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir 	void flip()
748*cdf0e10cSrcweir 	{
749*cdf0e10cSrcweir 		if(maVector.size() > 1)
750*cdf0e10cSrcweir 		{
751*cdf0e10cSrcweir 			const sal_uInt32 nHalfSize(maVector.size() >> 1L);
752*cdf0e10cSrcweir 			TextureData2DVector::iterator aStart(maVector.begin());
753*cdf0e10cSrcweir 			TextureData2DVector::iterator aEnd(maVector.end() - 1L);
754*cdf0e10cSrcweir 
755*cdf0e10cSrcweir 			for(sal_uInt32 a(0); a < nHalfSize; a++)
756*cdf0e10cSrcweir 			{
757*cdf0e10cSrcweir 				::std::swap(*aStart, *aEnd);
758*cdf0e10cSrcweir 				aStart++;
759*cdf0e10cSrcweir 				aEnd--;
760*cdf0e10cSrcweir 			}
761*cdf0e10cSrcweir 		}
762*cdf0e10cSrcweir 	}
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir 	void transform(const ::basegfx::B2DHomMatrix& rMatrix)
765*cdf0e10cSrcweir 	{
766*cdf0e10cSrcweir 		TextureData2DVector::iterator aStart(maVector.begin());
767*cdf0e10cSrcweir 		TextureData2DVector::iterator aEnd(maVector.end());
768*cdf0e10cSrcweir 
769*cdf0e10cSrcweir 		for(; aStart != aEnd; aStart++)
770*cdf0e10cSrcweir 		{
771*cdf0e10cSrcweir 			(*aStart) *= rMatrix;
772*cdf0e10cSrcweir 		}
773*cdf0e10cSrcweir 	}
774*cdf0e10cSrcweir };
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
777*cdf0e10cSrcweir 
778*cdf0e10cSrcweir class ImplB3DPolygon
779*cdf0e10cSrcweir {
780*cdf0e10cSrcweir 	// The point vector. This vector exists always and defines the
781*cdf0e10cSrcweir 	// count of members.
782*cdf0e10cSrcweir 	CoordinateDataArray3D							maPoints;
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir 	// The BColor vector. This vectors are created on demand
785*cdf0e10cSrcweir 	// and may be zero.
786*cdf0e10cSrcweir 	BColorArray*									mpBColors;
787*cdf0e10cSrcweir 
788*cdf0e10cSrcweir 	// The Normals vector. This vectors are created on demand
789*cdf0e10cSrcweir 	// and may be zero.
790*cdf0e10cSrcweir 	NormalsArray3D*									mpNormals;
791*cdf0e10cSrcweir 
792*cdf0e10cSrcweir 	// The TextureCoordinates vector. This vectors are created on demand
793*cdf0e10cSrcweir 	// and may be zero.
794*cdf0e10cSrcweir 	TextureCoordinate2D*							mpTextureCoordiantes;
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir 	// The calculated plane normal. mbPlaneNormalValid says if it's valid.
797*cdf0e10cSrcweir 	::basegfx::B3DVector							maPlaneNormal;
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir 	// bitfield
800*cdf0e10cSrcweir 	// flag which decides if this polygon is opened or closed
801*cdf0e10cSrcweir 	unsigned										mbIsClosed : 1;
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir 	// flag which says if maPlaneNormal is up-to-date
804*cdf0e10cSrcweir 	unsigned										mbPlaneNormalValid : 1;
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir protected:
807*cdf0e10cSrcweir 	void invalidatePlaneNormal()
808*cdf0e10cSrcweir 	{
809*cdf0e10cSrcweir 		if(mbPlaneNormalValid)
810*cdf0e10cSrcweir 		{
811*cdf0e10cSrcweir 			mbPlaneNormalValid = false;
812*cdf0e10cSrcweir 		}
813*cdf0e10cSrcweir 	}
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir public:
816*cdf0e10cSrcweir 	// This constructor is only used from the static identity polygon, thus
817*cdf0e10cSrcweir 	// the RefCount is set to 1 to never 'delete' this static incarnation.
818*cdf0e10cSrcweir 	ImplB3DPolygon()
819*cdf0e10cSrcweir 	:	maPoints(0L),
820*cdf0e10cSrcweir 		mpBColors(0L),
821*cdf0e10cSrcweir 		mpNormals(0L),
822*cdf0e10cSrcweir 		mpTextureCoordiantes(0L),
823*cdf0e10cSrcweir 		maPlaneNormal(::basegfx::B3DVector::getEmptyVector()),
824*cdf0e10cSrcweir 		mbIsClosed(false),
825*cdf0e10cSrcweir 		mbPlaneNormalValid(true)
826*cdf0e10cSrcweir 	{
827*cdf0e10cSrcweir 		// complete initialization with defaults
828*cdf0e10cSrcweir 	}
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir 	ImplB3DPolygon(const ImplB3DPolygon& rToBeCopied)
831*cdf0e10cSrcweir 	:	maPoints(rToBeCopied.maPoints),
832*cdf0e10cSrcweir 		mpBColors(0L),
833*cdf0e10cSrcweir 		mpNormals(0L),
834*cdf0e10cSrcweir 		mpTextureCoordiantes(0L),
835*cdf0e10cSrcweir 		maPlaneNormal(rToBeCopied.maPlaneNormal),
836*cdf0e10cSrcweir 		mbIsClosed(rToBeCopied.mbIsClosed),
837*cdf0e10cSrcweir 		mbPlaneNormalValid(rToBeCopied.mbPlaneNormalValid)
838*cdf0e10cSrcweir 	{
839*cdf0e10cSrcweir 		// complete initialization using copy
840*cdf0e10cSrcweir 		if(rToBeCopied.mpBColors && rToBeCopied.mpBColors->isUsed())
841*cdf0e10cSrcweir 		{
842*cdf0e10cSrcweir 			mpBColors = new BColorArray(*rToBeCopied.mpBColors);
843*cdf0e10cSrcweir 		}
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir 		if(rToBeCopied.mpNormals && rToBeCopied.mpNormals->isUsed())
846*cdf0e10cSrcweir 		{
847*cdf0e10cSrcweir 			mpNormals = new NormalsArray3D(*rToBeCopied.mpNormals);
848*cdf0e10cSrcweir 		}
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir 		if(rToBeCopied.mpTextureCoordiantes && rToBeCopied.mpTextureCoordiantes->isUsed())
851*cdf0e10cSrcweir 		{
852*cdf0e10cSrcweir 			mpTextureCoordiantes = new TextureCoordinate2D(*rToBeCopied.mpTextureCoordiantes);
853*cdf0e10cSrcweir 		}
854*cdf0e10cSrcweir 	}
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir 	ImplB3DPolygon(const ImplB3DPolygon& rToBeCopied, sal_uInt32 nIndex, sal_uInt32 nCount)
857*cdf0e10cSrcweir 	:	maPoints(rToBeCopied.maPoints, nIndex, nCount),
858*cdf0e10cSrcweir 		mpBColors(0L),
859*cdf0e10cSrcweir 		mpNormals(0L),
860*cdf0e10cSrcweir 		mpTextureCoordiantes(0L),
861*cdf0e10cSrcweir 		maPlaneNormal(::basegfx::B3DVector::getEmptyVector()),
862*cdf0e10cSrcweir 		mbIsClosed(rToBeCopied.mbIsClosed),
863*cdf0e10cSrcweir 		mbPlaneNormalValid(false)
864*cdf0e10cSrcweir 	{
865*cdf0e10cSrcweir 		// complete initialization using partly copy
866*cdf0e10cSrcweir 		if(rToBeCopied.mpBColors && rToBeCopied.mpBColors->isUsed())
867*cdf0e10cSrcweir 		{
868*cdf0e10cSrcweir 			mpBColors = new BColorArray(*rToBeCopied.mpBColors, nIndex, nCount);
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir 			if(!mpBColors->isUsed())
871*cdf0e10cSrcweir 			{
872*cdf0e10cSrcweir 				delete mpBColors;
873*cdf0e10cSrcweir 				mpBColors = 0L;
874*cdf0e10cSrcweir 			}
875*cdf0e10cSrcweir 		}
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir 		if(rToBeCopied.mpNormals && rToBeCopied.mpNormals->isUsed())
878*cdf0e10cSrcweir 		{
879*cdf0e10cSrcweir 			mpNormals = new NormalsArray3D(*rToBeCopied.mpNormals, nIndex, nCount);
880*cdf0e10cSrcweir 
881*cdf0e10cSrcweir 			if(!mpNormals->isUsed())
882*cdf0e10cSrcweir 			{
883*cdf0e10cSrcweir 				delete mpNormals;
884*cdf0e10cSrcweir 				mpNormals = 0L;
885*cdf0e10cSrcweir 			}
886*cdf0e10cSrcweir 		}
887*cdf0e10cSrcweir 
888*cdf0e10cSrcweir 		if(rToBeCopied.mpTextureCoordiantes && rToBeCopied.mpTextureCoordiantes->isUsed())
889*cdf0e10cSrcweir 		{
890*cdf0e10cSrcweir 			mpTextureCoordiantes = new TextureCoordinate2D(*rToBeCopied.mpTextureCoordiantes, nIndex, nCount);
891*cdf0e10cSrcweir 
892*cdf0e10cSrcweir 			if(!mpTextureCoordiantes->isUsed())
893*cdf0e10cSrcweir 			{
894*cdf0e10cSrcweir 				delete mpTextureCoordiantes;
895*cdf0e10cSrcweir 				mpTextureCoordiantes = 0L;
896*cdf0e10cSrcweir 			}
897*cdf0e10cSrcweir 		}
898*cdf0e10cSrcweir 	}
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir 	~ImplB3DPolygon()
901*cdf0e10cSrcweir 	{
902*cdf0e10cSrcweir 		if(mpBColors)
903*cdf0e10cSrcweir 		{
904*cdf0e10cSrcweir 			delete mpBColors;
905*cdf0e10cSrcweir 			mpBColors = 0L;
906*cdf0e10cSrcweir 		}
907*cdf0e10cSrcweir 
908*cdf0e10cSrcweir 		if(mpNormals)
909*cdf0e10cSrcweir 		{
910*cdf0e10cSrcweir 			delete mpNormals;
911*cdf0e10cSrcweir 			mpNormals = 0L;
912*cdf0e10cSrcweir 		}
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir 		if(mpTextureCoordiantes)
915*cdf0e10cSrcweir 		{
916*cdf0e10cSrcweir 			delete mpTextureCoordiantes;
917*cdf0e10cSrcweir 			mpTextureCoordiantes = 0L;
918*cdf0e10cSrcweir 		}
919*cdf0e10cSrcweir 	}
920*cdf0e10cSrcweir 
921*cdf0e10cSrcweir 	sal_uInt32 count() const
922*cdf0e10cSrcweir 	{
923*cdf0e10cSrcweir 		return maPoints.count();
924*cdf0e10cSrcweir 	}
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir 	bool isClosed() const
927*cdf0e10cSrcweir 	{
928*cdf0e10cSrcweir 		return mbIsClosed;
929*cdf0e10cSrcweir 	}
930*cdf0e10cSrcweir 
931*cdf0e10cSrcweir 	void setClosed(bool bNew)
932*cdf0e10cSrcweir 	{
933*cdf0e10cSrcweir 		if(bNew != (bool)mbIsClosed)
934*cdf0e10cSrcweir 		{
935*cdf0e10cSrcweir 			mbIsClosed = bNew;
936*cdf0e10cSrcweir 		}
937*cdf0e10cSrcweir 	}
938*cdf0e10cSrcweir 
939*cdf0e10cSrcweir 	inline bool impBColorsAreEqual(const ImplB3DPolygon& rCandidate) const
940*cdf0e10cSrcweir 	{
941*cdf0e10cSrcweir 		bool bBColorsAreEqual(true);
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir 		if(mpBColors)
944*cdf0e10cSrcweir 		{
945*cdf0e10cSrcweir 			if(rCandidate.mpBColors)
946*cdf0e10cSrcweir 			{
947*cdf0e10cSrcweir 				bBColorsAreEqual = (*mpBColors == *rCandidate.mpBColors);
948*cdf0e10cSrcweir 			}
949*cdf0e10cSrcweir 			else
950*cdf0e10cSrcweir 			{
951*cdf0e10cSrcweir 				// candidate has no BColors, so it's assumed all unused.
952*cdf0e10cSrcweir 				bBColorsAreEqual = !mpBColors->isUsed();
953*cdf0e10cSrcweir 			}
954*cdf0e10cSrcweir 		}
955*cdf0e10cSrcweir 		else
956*cdf0e10cSrcweir 		{
957*cdf0e10cSrcweir 			if(rCandidate.mpBColors)
958*cdf0e10cSrcweir 			{
959*cdf0e10cSrcweir 				// we have no TextureCoordiantes, so it's assumed all unused.
960*cdf0e10cSrcweir 				bBColorsAreEqual = !rCandidate.mpBColors->isUsed();
961*cdf0e10cSrcweir 			}
962*cdf0e10cSrcweir 		}
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir 		return bBColorsAreEqual;
965*cdf0e10cSrcweir 	}
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir 	inline bool impNormalsAreEqual(const ImplB3DPolygon& rCandidate) const
968*cdf0e10cSrcweir 	{
969*cdf0e10cSrcweir 		bool bNormalsAreEqual(true);
970*cdf0e10cSrcweir 
971*cdf0e10cSrcweir 		if(mpNormals)
972*cdf0e10cSrcweir 		{
973*cdf0e10cSrcweir 			if(rCandidate.mpNormals)
974*cdf0e10cSrcweir 			{
975*cdf0e10cSrcweir 				bNormalsAreEqual = (*mpNormals == *rCandidate.mpNormals);
976*cdf0e10cSrcweir 			}
977*cdf0e10cSrcweir 			else
978*cdf0e10cSrcweir 			{
979*cdf0e10cSrcweir 				// candidate has no normals, so it's assumed all unused.
980*cdf0e10cSrcweir 				bNormalsAreEqual = !mpNormals->isUsed();
981*cdf0e10cSrcweir 			}
982*cdf0e10cSrcweir 		}
983*cdf0e10cSrcweir 		else
984*cdf0e10cSrcweir 		{
985*cdf0e10cSrcweir 			if(rCandidate.mpNormals)
986*cdf0e10cSrcweir 			{
987*cdf0e10cSrcweir 				// we have no normals, so it's assumed all unused.
988*cdf0e10cSrcweir 				bNormalsAreEqual = !rCandidate.mpNormals->isUsed();
989*cdf0e10cSrcweir 			}
990*cdf0e10cSrcweir 		}
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir 		return bNormalsAreEqual;
993*cdf0e10cSrcweir 	}
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir 	inline bool impTextureCoordinatesAreEqual(const ImplB3DPolygon& rCandidate) const
996*cdf0e10cSrcweir 	{
997*cdf0e10cSrcweir 		bool bTextureCoordinatesAreEqual(true);
998*cdf0e10cSrcweir 
999*cdf0e10cSrcweir 		if(mpTextureCoordiantes)
1000*cdf0e10cSrcweir 		{
1001*cdf0e10cSrcweir 			if(rCandidate.mpTextureCoordiantes)
1002*cdf0e10cSrcweir 			{
1003*cdf0e10cSrcweir 				bTextureCoordinatesAreEqual = (*mpTextureCoordiantes == *rCandidate.mpTextureCoordiantes);
1004*cdf0e10cSrcweir 			}
1005*cdf0e10cSrcweir 			else
1006*cdf0e10cSrcweir 			{
1007*cdf0e10cSrcweir 				// candidate has no TextureCoordinates, so it's assumed all unused.
1008*cdf0e10cSrcweir 				bTextureCoordinatesAreEqual = !mpTextureCoordiantes->isUsed();
1009*cdf0e10cSrcweir 			}
1010*cdf0e10cSrcweir 		}
1011*cdf0e10cSrcweir 		else
1012*cdf0e10cSrcweir 		{
1013*cdf0e10cSrcweir 			if(rCandidate.mpTextureCoordiantes)
1014*cdf0e10cSrcweir 			{
1015*cdf0e10cSrcweir 				// we have no TextureCoordiantes, so it's assumed all unused.
1016*cdf0e10cSrcweir 				bTextureCoordinatesAreEqual = !rCandidate.mpTextureCoordiantes->isUsed();
1017*cdf0e10cSrcweir 			}
1018*cdf0e10cSrcweir 		}
1019*cdf0e10cSrcweir 
1020*cdf0e10cSrcweir 		return bTextureCoordinatesAreEqual;
1021*cdf0e10cSrcweir 	}
1022*cdf0e10cSrcweir 
1023*cdf0e10cSrcweir 	bool operator==(const ImplB3DPolygon& rCandidate) const
1024*cdf0e10cSrcweir 	{
1025*cdf0e10cSrcweir 		if(mbIsClosed == rCandidate.mbIsClosed)
1026*cdf0e10cSrcweir 		{
1027*cdf0e10cSrcweir 			if(maPoints == rCandidate.maPoints)
1028*cdf0e10cSrcweir 			{
1029*cdf0e10cSrcweir 				if(impBColorsAreEqual(rCandidate))
1030*cdf0e10cSrcweir 				{
1031*cdf0e10cSrcweir 					if(impNormalsAreEqual(rCandidate))
1032*cdf0e10cSrcweir 					{
1033*cdf0e10cSrcweir 						if(impTextureCoordinatesAreEqual(rCandidate))
1034*cdf0e10cSrcweir 						{
1035*cdf0e10cSrcweir 							return true;
1036*cdf0e10cSrcweir 						}
1037*cdf0e10cSrcweir 					}
1038*cdf0e10cSrcweir 				}
1039*cdf0e10cSrcweir 			}
1040*cdf0e10cSrcweir 		}
1041*cdf0e10cSrcweir 
1042*cdf0e10cSrcweir 		return false;
1043*cdf0e10cSrcweir 	}
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir 	const ::basegfx::B3DPoint& getPoint(sal_uInt32 nIndex) const
1046*cdf0e10cSrcweir 	{
1047*cdf0e10cSrcweir 		return maPoints.getCoordinate(nIndex);
1048*cdf0e10cSrcweir 	}
1049*cdf0e10cSrcweir 
1050*cdf0e10cSrcweir 	void setPoint(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rValue)
1051*cdf0e10cSrcweir 	{
1052*cdf0e10cSrcweir 		maPoints.setCoordinate(nIndex, rValue);
1053*cdf0e10cSrcweir 		invalidatePlaneNormal();
1054*cdf0e10cSrcweir 	}
1055*cdf0e10cSrcweir 
1056*cdf0e10cSrcweir 	void insert(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rPoint, sal_uInt32 nCount)
1057*cdf0e10cSrcweir 	{
1058*cdf0e10cSrcweir 		if(nCount)
1059*cdf0e10cSrcweir 		{
1060*cdf0e10cSrcweir 			CoordinateData3D aCoordinate(rPoint);
1061*cdf0e10cSrcweir 			maPoints.insert(nIndex, aCoordinate, nCount);
1062*cdf0e10cSrcweir 			invalidatePlaneNormal();
1063*cdf0e10cSrcweir 
1064*cdf0e10cSrcweir 			if(mpBColors)
1065*cdf0e10cSrcweir 			{
1066*cdf0e10cSrcweir 				mpBColors->insert(nIndex, ::basegfx::BColor::getEmptyBColor(), nCount);
1067*cdf0e10cSrcweir 			}
1068*cdf0e10cSrcweir 
1069*cdf0e10cSrcweir 			if(mpNormals)
1070*cdf0e10cSrcweir 			{
1071*cdf0e10cSrcweir 				mpNormals->insert(nIndex, ::basegfx::B3DVector::getEmptyVector(), nCount);
1072*cdf0e10cSrcweir 			}
1073*cdf0e10cSrcweir 
1074*cdf0e10cSrcweir 			if(mpTextureCoordiantes)
1075*cdf0e10cSrcweir 			{
1076*cdf0e10cSrcweir 				mpTextureCoordiantes->insert(nIndex, ::basegfx::B2DPoint::getEmptyPoint(), nCount);
1077*cdf0e10cSrcweir 			}
1078*cdf0e10cSrcweir 		}
1079*cdf0e10cSrcweir 	}
1080*cdf0e10cSrcweir 
1081*cdf0e10cSrcweir 	const ::basegfx::BColor& getBColor(sal_uInt32 nIndex) const
1082*cdf0e10cSrcweir 	{
1083*cdf0e10cSrcweir 		if(mpBColors)
1084*cdf0e10cSrcweir 		{
1085*cdf0e10cSrcweir 			return mpBColors->getBColor(nIndex);
1086*cdf0e10cSrcweir 		}
1087*cdf0e10cSrcweir 		else
1088*cdf0e10cSrcweir 		{
1089*cdf0e10cSrcweir 			return ::basegfx::BColor::getEmptyBColor();
1090*cdf0e10cSrcweir 		}
1091*cdf0e10cSrcweir 	}
1092*cdf0e10cSrcweir 
1093*cdf0e10cSrcweir 	void setBColor(sal_uInt32 nIndex, const ::basegfx::BColor& rValue)
1094*cdf0e10cSrcweir 	{
1095*cdf0e10cSrcweir 		if(!mpBColors)
1096*cdf0e10cSrcweir 		{
1097*cdf0e10cSrcweir 			if(!rValue.equalZero())
1098*cdf0e10cSrcweir 			{
1099*cdf0e10cSrcweir 				mpBColors = new BColorArray(maPoints.count());
1100*cdf0e10cSrcweir 				mpBColors->setBColor(nIndex, rValue);
1101*cdf0e10cSrcweir 			}
1102*cdf0e10cSrcweir 		}
1103*cdf0e10cSrcweir 		else
1104*cdf0e10cSrcweir 		{
1105*cdf0e10cSrcweir 			mpBColors->setBColor(nIndex, rValue);
1106*cdf0e10cSrcweir 
1107*cdf0e10cSrcweir 			if(!mpBColors->isUsed())
1108*cdf0e10cSrcweir 			{
1109*cdf0e10cSrcweir 				delete mpBColors;
1110*cdf0e10cSrcweir 				mpBColors = 0L;
1111*cdf0e10cSrcweir 			}
1112*cdf0e10cSrcweir 		}
1113*cdf0e10cSrcweir 	}
1114*cdf0e10cSrcweir 
1115*cdf0e10cSrcweir 	bool areBColorsUsed() const
1116*cdf0e10cSrcweir 	{
1117*cdf0e10cSrcweir 		return (mpBColors && mpBColors->isUsed());
1118*cdf0e10cSrcweir 	}
1119*cdf0e10cSrcweir 
1120*cdf0e10cSrcweir 	void clearBColors()
1121*cdf0e10cSrcweir 	{
1122*cdf0e10cSrcweir 		if(mpBColors)
1123*cdf0e10cSrcweir 		{
1124*cdf0e10cSrcweir 			delete mpBColors;
1125*cdf0e10cSrcweir 			mpBColors = 0L;
1126*cdf0e10cSrcweir 		}
1127*cdf0e10cSrcweir 	}
1128*cdf0e10cSrcweir 
1129*cdf0e10cSrcweir 	const ::basegfx::B3DVector& getNormal() const
1130*cdf0e10cSrcweir 	{
1131*cdf0e10cSrcweir 		if(!mbPlaneNormalValid)
1132*cdf0e10cSrcweir 		{
1133*cdf0e10cSrcweir 			const_cast< ImplB3DPolygon* >(this)->maPlaneNormal = maPoints.getNormal();
1134*cdf0e10cSrcweir 			const_cast< ImplB3DPolygon* >(this)->mbPlaneNormalValid = true;
1135*cdf0e10cSrcweir 		}
1136*cdf0e10cSrcweir 
1137*cdf0e10cSrcweir 		return maPlaneNormal;
1138*cdf0e10cSrcweir 	}
1139*cdf0e10cSrcweir 
1140*cdf0e10cSrcweir 	const ::basegfx::B3DVector& getNormal(sal_uInt32 nIndex) const
1141*cdf0e10cSrcweir 	{
1142*cdf0e10cSrcweir 		if(mpNormals)
1143*cdf0e10cSrcweir 		{
1144*cdf0e10cSrcweir 			return mpNormals->getNormal(nIndex);
1145*cdf0e10cSrcweir 		}
1146*cdf0e10cSrcweir 		else
1147*cdf0e10cSrcweir 		{
1148*cdf0e10cSrcweir 			return ::basegfx::B3DVector::getEmptyVector();
1149*cdf0e10cSrcweir 		}
1150*cdf0e10cSrcweir 	}
1151*cdf0e10cSrcweir 
1152*cdf0e10cSrcweir 	void setNormal(sal_uInt32 nIndex, const ::basegfx::B3DVector& rValue)
1153*cdf0e10cSrcweir 	{
1154*cdf0e10cSrcweir 		if(!mpNormals)
1155*cdf0e10cSrcweir 		{
1156*cdf0e10cSrcweir 			if(!rValue.equalZero())
1157*cdf0e10cSrcweir 			{
1158*cdf0e10cSrcweir 				mpNormals = new NormalsArray3D(maPoints.count());
1159*cdf0e10cSrcweir 				mpNormals->setNormal(nIndex, rValue);
1160*cdf0e10cSrcweir 			}
1161*cdf0e10cSrcweir 		}
1162*cdf0e10cSrcweir 		else
1163*cdf0e10cSrcweir 		{
1164*cdf0e10cSrcweir 			mpNormals->setNormal(nIndex, rValue);
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir 			if(!mpNormals->isUsed())
1167*cdf0e10cSrcweir 			{
1168*cdf0e10cSrcweir 				delete mpNormals;
1169*cdf0e10cSrcweir 				mpNormals = 0L;
1170*cdf0e10cSrcweir 			}
1171*cdf0e10cSrcweir 		}
1172*cdf0e10cSrcweir 	}
1173*cdf0e10cSrcweir 
1174*cdf0e10cSrcweir 	void transformNormals(const ::basegfx::B3DHomMatrix& rMatrix)
1175*cdf0e10cSrcweir 	{
1176*cdf0e10cSrcweir 		if(mpNormals)
1177*cdf0e10cSrcweir 		{
1178*cdf0e10cSrcweir 			mpNormals->transform(rMatrix);
1179*cdf0e10cSrcweir 		}
1180*cdf0e10cSrcweir 	}
1181*cdf0e10cSrcweir 
1182*cdf0e10cSrcweir 	bool areNormalsUsed() const
1183*cdf0e10cSrcweir 	{
1184*cdf0e10cSrcweir 		return (mpNormals && mpNormals->isUsed());
1185*cdf0e10cSrcweir 	}
1186*cdf0e10cSrcweir 
1187*cdf0e10cSrcweir 	void clearNormals()
1188*cdf0e10cSrcweir 	{
1189*cdf0e10cSrcweir 		if(mpNormals)
1190*cdf0e10cSrcweir 		{
1191*cdf0e10cSrcweir 			delete mpNormals;
1192*cdf0e10cSrcweir 			mpNormals = 0L;
1193*cdf0e10cSrcweir 		}
1194*cdf0e10cSrcweir 	}
1195*cdf0e10cSrcweir 
1196*cdf0e10cSrcweir 	const ::basegfx::B2DPoint& getTextureCoordinate(sal_uInt32 nIndex) const
1197*cdf0e10cSrcweir 	{
1198*cdf0e10cSrcweir 		if(mpTextureCoordiantes)
1199*cdf0e10cSrcweir 		{
1200*cdf0e10cSrcweir 			return mpTextureCoordiantes->getTextureCoordinate(nIndex);
1201*cdf0e10cSrcweir 		}
1202*cdf0e10cSrcweir 		else
1203*cdf0e10cSrcweir 		{
1204*cdf0e10cSrcweir 			return ::basegfx::B2DPoint::getEmptyPoint();
1205*cdf0e10cSrcweir 		}
1206*cdf0e10cSrcweir 	}
1207*cdf0e10cSrcweir 
1208*cdf0e10cSrcweir 	void setTextureCoordinate(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue)
1209*cdf0e10cSrcweir 	{
1210*cdf0e10cSrcweir 		if(!mpTextureCoordiantes)
1211*cdf0e10cSrcweir 		{
1212*cdf0e10cSrcweir 			if(!rValue.equalZero())
1213*cdf0e10cSrcweir 			{
1214*cdf0e10cSrcweir 				mpTextureCoordiantes = new TextureCoordinate2D(maPoints.count());
1215*cdf0e10cSrcweir 				mpTextureCoordiantes->setTextureCoordinate(nIndex, rValue);
1216*cdf0e10cSrcweir 			}
1217*cdf0e10cSrcweir 		}
1218*cdf0e10cSrcweir 		else
1219*cdf0e10cSrcweir 		{
1220*cdf0e10cSrcweir 			mpTextureCoordiantes->setTextureCoordinate(nIndex, rValue);
1221*cdf0e10cSrcweir 
1222*cdf0e10cSrcweir 			if(!mpTextureCoordiantes->isUsed())
1223*cdf0e10cSrcweir 			{
1224*cdf0e10cSrcweir 				delete mpTextureCoordiantes;
1225*cdf0e10cSrcweir 				mpTextureCoordiantes = 0L;
1226*cdf0e10cSrcweir 			}
1227*cdf0e10cSrcweir 		}
1228*cdf0e10cSrcweir 	}
1229*cdf0e10cSrcweir 
1230*cdf0e10cSrcweir 	bool areTextureCoordinatesUsed() const
1231*cdf0e10cSrcweir 	{
1232*cdf0e10cSrcweir 		return (mpTextureCoordiantes && mpTextureCoordiantes->isUsed());
1233*cdf0e10cSrcweir 	}
1234*cdf0e10cSrcweir 
1235*cdf0e10cSrcweir 	void clearTextureCoordinates()
1236*cdf0e10cSrcweir 	{
1237*cdf0e10cSrcweir 		if(mpTextureCoordiantes)
1238*cdf0e10cSrcweir 		{
1239*cdf0e10cSrcweir 			delete mpTextureCoordiantes;
1240*cdf0e10cSrcweir 			mpTextureCoordiantes = 0L;
1241*cdf0e10cSrcweir 		}
1242*cdf0e10cSrcweir 	}
1243*cdf0e10cSrcweir 
1244*cdf0e10cSrcweir 	void transformTextureCoordinates(const ::basegfx::B2DHomMatrix& rMatrix)
1245*cdf0e10cSrcweir 	{
1246*cdf0e10cSrcweir 		if(mpTextureCoordiantes)
1247*cdf0e10cSrcweir 		{
1248*cdf0e10cSrcweir 			mpTextureCoordiantes->transform(rMatrix);
1249*cdf0e10cSrcweir 		}
1250*cdf0e10cSrcweir 	}
1251*cdf0e10cSrcweir 
1252*cdf0e10cSrcweir 	void insert(sal_uInt32 nIndex, const ImplB3DPolygon& rSource)
1253*cdf0e10cSrcweir 	{
1254*cdf0e10cSrcweir 		const sal_uInt32 nCount(rSource.maPoints.count());
1255*cdf0e10cSrcweir 
1256*cdf0e10cSrcweir 		if(nCount)
1257*cdf0e10cSrcweir 		{
1258*cdf0e10cSrcweir 			maPoints.insert(nIndex, rSource.maPoints);
1259*cdf0e10cSrcweir 			invalidatePlaneNormal();
1260*cdf0e10cSrcweir 
1261*cdf0e10cSrcweir 			if(rSource.mpBColors && rSource.mpBColors->isUsed())
1262*cdf0e10cSrcweir 			{
1263*cdf0e10cSrcweir 				if(!mpBColors)
1264*cdf0e10cSrcweir 				{
1265*cdf0e10cSrcweir 					mpBColors = new BColorArray(maPoints.count());
1266*cdf0e10cSrcweir 				}
1267*cdf0e10cSrcweir 
1268*cdf0e10cSrcweir 				mpBColors->insert(nIndex, *rSource.mpBColors);
1269*cdf0e10cSrcweir 			}
1270*cdf0e10cSrcweir 			else
1271*cdf0e10cSrcweir 			{
1272*cdf0e10cSrcweir 				if(mpBColors)
1273*cdf0e10cSrcweir 				{
1274*cdf0e10cSrcweir 					mpBColors->insert(nIndex, ::basegfx::BColor::getEmptyBColor(), nCount);
1275*cdf0e10cSrcweir 				}
1276*cdf0e10cSrcweir 			}
1277*cdf0e10cSrcweir 
1278*cdf0e10cSrcweir 			if(rSource.mpNormals && rSource.mpNormals->isUsed())
1279*cdf0e10cSrcweir 			{
1280*cdf0e10cSrcweir 				if(!mpNormals)
1281*cdf0e10cSrcweir 				{
1282*cdf0e10cSrcweir 					mpNormals = new NormalsArray3D(maPoints.count());
1283*cdf0e10cSrcweir 				}
1284*cdf0e10cSrcweir 
1285*cdf0e10cSrcweir 				mpNormals->insert(nIndex, *rSource.mpNormals);
1286*cdf0e10cSrcweir 			}
1287*cdf0e10cSrcweir 			else
1288*cdf0e10cSrcweir 			{
1289*cdf0e10cSrcweir 				if(mpNormals)
1290*cdf0e10cSrcweir 				{
1291*cdf0e10cSrcweir 					mpNormals->insert(nIndex, ::basegfx::B3DVector::getEmptyVector(), nCount);
1292*cdf0e10cSrcweir 				}
1293*cdf0e10cSrcweir 			}
1294*cdf0e10cSrcweir 
1295*cdf0e10cSrcweir 			if(rSource.mpTextureCoordiantes && rSource.mpTextureCoordiantes->isUsed())
1296*cdf0e10cSrcweir 			{
1297*cdf0e10cSrcweir 				if(!mpTextureCoordiantes)
1298*cdf0e10cSrcweir 				{
1299*cdf0e10cSrcweir 					mpTextureCoordiantes = new TextureCoordinate2D(maPoints.count());
1300*cdf0e10cSrcweir 				}
1301*cdf0e10cSrcweir 
1302*cdf0e10cSrcweir 				mpTextureCoordiantes->insert(nIndex, *rSource.mpTextureCoordiantes);
1303*cdf0e10cSrcweir 			}
1304*cdf0e10cSrcweir 			else
1305*cdf0e10cSrcweir 			{
1306*cdf0e10cSrcweir 				if(mpTextureCoordiantes)
1307*cdf0e10cSrcweir 				{
1308*cdf0e10cSrcweir 					mpTextureCoordiantes->insert(nIndex, ::basegfx::B2DPoint::getEmptyPoint(), nCount);
1309*cdf0e10cSrcweir 				}
1310*cdf0e10cSrcweir 			}
1311*cdf0e10cSrcweir 		}
1312*cdf0e10cSrcweir 	}
1313*cdf0e10cSrcweir 
1314*cdf0e10cSrcweir 	void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
1315*cdf0e10cSrcweir 	{
1316*cdf0e10cSrcweir 		if(nCount)
1317*cdf0e10cSrcweir 		{
1318*cdf0e10cSrcweir 			maPoints.remove(nIndex, nCount);
1319*cdf0e10cSrcweir 			invalidatePlaneNormal();
1320*cdf0e10cSrcweir 
1321*cdf0e10cSrcweir 			if(mpBColors)
1322*cdf0e10cSrcweir 			{
1323*cdf0e10cSrcweir 				mpBColors->remove(nIndex, nCount);
1324*cdf0e10cSrcweir 
1325*cdf0e10cSrcweir 				if(!mpBColors->isUsed())
1326*cdf0e10cSrcweir 				{
1327*cdf0e10cSrcweir 					delete mpBColors;
1328*cdf0e10cSrcweir 					mpBColors = 0L;
1329*cdf0e10cSrcweir 				}
1330*cdf0e10cSrcweir 			}
1331*cdf0e10cSrcweir 
1332*cdf0e10cSrcweir 			if(mpNormals)
1333*cdf0e10cSrcweir 			{
1334*cdf0e10cSrcweir 				mpNormals->remove(nIndex, nCount);
1335*cdf0e10cSrcweir 
1336*cdf0e10cSrcweir 				if(!mpNormals->isUsed())
1337*cdf0e10cSrcweir 				{
1338*cdf0e10cSrcweir 					delete mpNormals;
1339*cdf0e10cSrcweir 					mpNormals = 0L;
1340*cdf0e10cSrcweir 				}
1341*cdf0e10cSrcweir 			}
1342*cdf0e10cSrcweir 
1343*cdf0e10cSrcweir 			if(mpTextureCoordiantes)
1344*cdf0e10cSrcweir 			{
1345*cdf0e10cSrcweir 				mpTextureCoordiantes->remove(nIndex, nCount);
1346*cdf0e10cSrcweir 
1347*cdf0e10cSrcweir 				if(!mpTextureCoordiantes->isUsed())
1348*cdf0e10cSrcweir 				{
1349*cdf0e10cSrcweir 					delete mpTextureCoordiantes;
1350*cdf0e10cSrcweir 					mpTextureCoordiantes = 0L;
1351*cdf0e10cSrcweir 				}
1352*cdf0e10cSrcweir 			}
1353*cdf0e10cSrcweir 		}
1354*cdf0e10cSrcweir 	}
1355*cdf0e10cSrcweir 
1356*cdf0e10cSrcweir 	void flip()
1357*cdf0e10cSrcweir 	{
1358*cdf0e10cSrcweir 		if(maPoints.count() > 1)
1359*cdf0e10cSrcweir 		{
1360*cdf0e10cSrcweir 			maPoints.flip();
1361*cdf0e10cSrcweir 
1362*cdf0e10cSrcweir 			if(mbPlaneNormalValid)
1363*cdf0e10cSrcweir 			{
1364*cdf0e10cSrcweir 				// mirror plane normal
1365*cdf0e10cSrcweir 				maPlaneNormal = -maPlaneNormal;
1366*cdf0e10cSrcweir 			}
1367*cdf0e10cSrcweir 
1368*cdf0e10cSrcweir 			if(mpBColors)
1369*cdf0e10cSrcweir 			{
1370*cdf0e10cSrcweir 				mpBColors->flip();
1371*cdf0e10cSrcweir 			}
1372*cdf0e10cSrcweir 
1373*cdf0e10cSrcweir 			if(mpNormals)
1374*cdf0e10cSrcweir 			{
1375*cdf0e10cSrcweir 				mpNormals->flip();
1376*cdf0e10cSrcweir 			}
1377*cdf0e10cSrcweir 
1378*cdf0e10cSrcweir 			if(mpTextureCoordiantes)
1379*cdf0e10cSrcweir 			{
1380*cdf0e10cSrcweir 				mpTextureCoordiantes->flip();
1381*cdf0e10cSrcweir 			}
1382*cdf0e10cSrcweir 		}
1383*cdf0e10cSrcweir 	}
1384*cdf0e10cSrcweir 
1385*cdf0e10cSrcweir 	bool hasDoublePoints() const
1386*cdf0e10cSrcweir 	{
1387*cdf0e10cSrcweir 		if(mbIsClosed)
1388*cdf0e10cSrcweir 		{
1389*cdf0e10cSrcweir 			// check for same start and end point
1390*cdf0e10cSrcweir 			const sal_uInt32 nIndex(maPoints.count() - 1L);
1391*cdf0e10cSrcweir 
1392*cdf0e10cSrcweir 			if(maPoints.getCoordinate(0L) == maPoints.getCoordinate(nIndex))
1393*cdf0e10cSrcweir 			{
1394*cdf0e10cSrcweir 				const bool bBColorEqual(!mpBColors || (mpBColors->getBColor(0L) == mpBColors->getBColor(nIndex)));
1395*cdf0e10cSrcweir 
1396*cdf0e10cSrcweir 				if(bBColorEqual)
1397*cdf0e10cSrcweir 				{
1398*cdf0e10cSrcweir 					const bool bNormalsEqual(!mpNormals || (mpNormals->getNormal(0L) == mpNormals->getNormal(nIndex)));
1399*cdf0e10cSrcweir 
1400*cdf0e10cSrcweir 					if(bNormalsEqual)
1401*cdf0e10cSrcweir 					{
1402*cdf0e10cSrcweir 						const bool bTextureCoordinatesEqual(!mpTextureCoordiantes || (mpTextureCoordiantes->getTextureCoordinate(0L) == mpTextureCoordiantes->getTextureCoordinate(nIndex)));
1403*cdf0e10cSrcweir 
1404*cdf0e10cSrcweir 						if(bTextureCoordinatesEqual)
1405*cdf0e10cSrcweir 						{
1406*cdf0e10cSrcweir 							return true;
1407*cdf0e10cSrcweir 						}
1408*cdf0e10cSrcweir 					}
1409*cdf0e10cSrcweir 				}
1410*cdf0e10cSrcweir 			}
1411*cdf0e10cSrcweir 		}
1412*cdf0e10cSrcweir 
1413*cdf0e10cSrcweir 		// test for range
1414*cdf0e10cSrcweir 		for(sal_uInt32 a(0L); a < maPoints.count() - 1L; a++)
1415*cdf0e10cSrcweir 		{
1416*cdf0e10cSrcweir 			if(maPoints.getCoordinate(a) == maPoints.getCoordinate(a + 1L))
1417*cdf0e10cSrcweir 			{
1418*cdf0e10cSrcweir 				const bool bBColorEqual(!mpBColors || (mpBColors->getBColor(a) == mpBColors->getBColor(a + 1L)));
1419*cdf0e10cSrcweir 
1420*cdf0e10cSrcweir 				if(bBColorEqual)
1421*cdf0e10cSrcweir 				{
1422*cdf0e10cSrcweir 					const bool bNormalsEqual(!mpNormals || (mpNormals->getNormal(a) == mpNormals->getNormal(a + 1L)));
1423*cdf0e10cSrcweir 
1424*cdf0e10cSrcweir 					if(bNormalsEqual)
1425*cdf0e10cSrcweir 					{
1426*cdf0e10cSrcweir 						const bool bTextureCoordinatesEqual(!mpTextureCoordiantes || (mpTextureCoordiantes->getTextureCoordinate(a) == mpTextureCoordiantes->getTextureCoordinate(a + 1L)));
1427*cdf0e10cSrcweir 
1428*cdf0e10cSrcweir 						if(bTextureCoordinatesEqual)
1429*cdf0e10cSrcweir 						{
1430*cdf0e10cSrcweir 							return true;
1431*cdf0e10cSrcweir 						}
1432*cdf0e10cSrcweir 					}
1433*cdf0e10cSrcweir 				}
1434*cdf0e10cSrcweir 			}
1435*cdf0e10cSrcweir 		}
1436*cdf0e10cSrcweir 
1437*cdf0e10cSrcweir 		return false;
1438*cdf0e10cSrcweir 	}
1439*cdf0e10cSrcweir 
1440*cdf0e10cSrcweir 	void removeDoublePointsAtBeginEnd()
1441*cdf0e10cSrcweir 	{
1442*cdf0e10cSrcweir 		// Only remove DoublePoints at Begin and End when poly is closed
1443*cdf0e10cSrcweir 		if(mbIsClosed)
1444*cdf0e10cSrcweir 		{
1445*cdf0e10cSrcweir 			bool bRemove;
1446*cdf0e10cSrcweir 
1447*cdf0e10cSrcweir 			do
1448*cdf0e10cSrcweir 			{
1449*cdf0e10cSrcweir 				bRemove = false;
1450*cdf0e10cSrcweir 
1451*cdf0e10cSrcweir 				if(maPoints.count() > 1L)
1452*cdf0e10cSrcweir 				{
1453*cdf0e10cSrcweir 					const sal_uInt32 nIndex(maPoints.count() - 1L);
1454*cdf0e10cSrcweir 					bRemove = (maPoints.getCoordinate(0L) == maPoints.getCoordinate(nIndex));
1455*cdf0e10cSrcweir 
1456*cdf0e10cSrcweir 					if(bRemove && mpBColors && !(mpBColors->getBColor(0L) == mpBColors->getBColor(nIndex)))
1457*cdf0e10cSrcweir 					{
1458*cdf0e10cSrcweir 						bRemove = false;
1459*cdf0e10cSrcweir 					}
1460*cdf0e10cSrcweir 
1461*cdf0e10cSrcweir 					if(bRemove && mpNormals && !(mpNormals->getNormal(0L) == mpNormals->getNormal(nIndex)))
1462*cdf0e10cSrcweir 					{
1463*cdf0e10cSrcweir 						bRemove = false;
1464*cdf0e10cSrcweir 					}
1465*cdf0e10cSrcweir 
1466*cdf0e10cSrcweir 					if(bRemove && mpTextureCoordiantes && !(mpTextureCoordiantes->getTextureCoordinate(0L) == mpTextureCoordiantes->getTextureCoordinate(nIndex)))
1467*cdf0e10cSrcweir 					{
1468*cdf0e10cSrcweir 						bRemove = false;
1469*cdf0e10cSrcweir 					}
1470*cdf0e10cSrcweir 				}
1471*cdf0e10cSrcweir 
1472*cdf0e10cSrcweir 				if(bRemove)
1473*cdf0e10cSrcweir 				{
1474*cdf0e10cSrcweir 					const sal_uInt32 nIndex(maPoints.count() - 1L);
1475*cdf0e10cSrcweir 					remove(nIndex, 1L);
1476*cdf0e10cSrcweir 				}
1477*cdf0e10cSrcweir 			} while(bRemove);
1478*cdf0e10cSrcweir 		}
1479*cdf0e10cSrcweir 	}
1480*cdf0e10cSrcweir 
1481*cdf0e10cSrcweir 	void removeDoublePointsWholeTrack()
1482*cdf0e10cSrcweir 	{
1483*cdf0e10cSrcweir 		sal_uInt32 nIndex(0L);
1484*cdf0e10cSrcweir 
1485*cdf0e10cSrcweir 		// test as long as there are at least two points and as long as the index
1486*cdf0e10cSrcweir 		// is smaller or equal second last point
1487*cdf0e10cSrcweir 		while((maPoints.count() > 1L) && (nIndex <= maPoints.count() - 2L))
1488*cdf0e10cSrcweir 		{
1489*cdf0e10cSrcweir 			const sal_uInt32 nNextIndex(nIndex + 1L);
1490*cdf0e10cSrcweir 			bool bRemove(maPoints.getCoordinate(nIndex) == maPoints.getCoordinate(nNextIndex));
1491*cdf0e10cSrcweir 
1492*cdf0e10cSrcweir 			if(bRemove && mpBColors && !(mpBColors->getBColor(nIndex) == mpBColors->getBColor(nNextIndex)))
1493*cdf0e10cSrcweir 			{
1494*cdf0e10cSrcweir 				bRemove = false;
1495*cdf0e10cSrcweir 			}
1496*cdf0e10cSrcweir 
1497*cdf0e10cSrcweir 			if(bRemove && mpNormals && !(mpNormals->getNormal(nIndex) == mpNormals->getNormal(nNextIndex)))
1498*cdf0e10cSrcweir 			{
1499*cdf0e10cSrcweir 				bRemove = false;
1500*cdf0e10cSrcweir 			}
1501*cdf0e10cSrcweir 
1502*cdf0e10cSrcweir 			if(bRemove && mpTextureCoordiantes && !(mpTextureCoordiantes->getTextureCoordinate(nIndex) == mpTextureCoordiantes->getTextureCoordinate(nNextIndex)))
1503*cdf0e10cSrcweir 			{
1504*cdf0e10cSrcweir 				bRemove = false;
1505*cdf0e10cSrcweir 			}
1506*cdf0e10cSrcweir 
1507*cdf0e10cSrcweir 			if(bRemove)
1508*cdf0e10cSrcweir 			{
1509*cdf0e10cSrcweir 				// if next is same as index and the control vectors are unused, delete index
1510*cdf0e10cSrcweir 				remove(nIndex, 1L);
1511*cdf0e10cSrcweir 			}
1512*cdf0e10cSrcweir 			else
1513*cdf0e10cSrcweir 			{
1514*cdf0e10cSrcweir 				// if different, step forward
1515*cdf0e10cSrcweir 				nIndex++;
1516*cdf0e10cSrcweir 			}
1517*cdf0e10cSrcweir 		}
1518*cdf0e10cSrcweir 	}
1519*cdf0e10cSrcweir 
1520*cdf0e10cSrcweir 	void transform(const ::basegfx::B3DHomMatrix& rMatrix)
1521*cdf0e10cSrcweir 	{
1522*cdf0e10cSrcweir 		maPoints.transform(rMatrix);
1523*cdf0e10cSrcweir 
1524*cdf0e10cSrcweir 		// Here, it seems to be possible to transform a valid plane normal and to avoid
1525*cdf0e10cSrcweir 		// invalidation, but it's not true. If the transformation contains shears or e.g.
1526*cdf0e10cSrcweir 		// perspective projection, the orthogonality to the transformed plane will not
1527*cdf0e10cSrcweir 		// be preserved. It may be possible to test that at the matrix to not invalidate in
1528*cdf0e10cSrcweir 		// all cases or to extract a matrix which does not 'shear' the vector which is
1529*cdf0e10cSrcweir 		// a normal in this case. As long as this is not sure, i will just invalidate.
1530*cdf0e10cSrcweir 		invalidatePlaneNormal();
1531*cdf0e10cSrcweir 	}
1532*cdf0e10cSrcweir };
1533*cdf0e10cSrcweir 
1534*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
1535*cdf0e10cSrcweir 
1536*cdf0e10cSrcweir namespace basegfx
1537*cdf0e10cSrcweir {
1538*cdf0e10cSrcweir     namespace { struct DefaultPolygon : public rtl::Static< B3DPolygon::ImplType,
1539*cdf0e10cSrcweir                                                             DefaultPolygon > {}; }
1540*cdf0e10cSrcweir 
1541*cdf0e10cSrcweir 	B3DPolygon::B3DPolygon() :
1542*cdf0e10cSrcweir         mpPolygon(DefaultPolygon::get())
1543*cdf0e10cSrcweir 	{
1544*cdf0e10cSrcweir 	}
1545*cdf0e10cSrcweir 
1546*cdf0e10cSrcweir 	B3DPolygon::B3DPolygon(const B3DPolygon& rPolygon) :
1547*cdf0e10cSrcweir         mpPolygon(rPolygon.mpPolygon)
1548*cdf0e10cSrcweir 	{
1549*cdf0e10cSrcweir 	}
1550*cdf0e10cSrcweir 
1551*cdf0e10cSrcweir 	B3DPolygon::B3DPolygon(const B3DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount) :
1552*cdf0e10cSrcweir         mpPolygon(ImplB3DPolygon(*rPolygon.mpPolygon, nIndex, nCount))
1553*cdf0e10cSrcweir 	{
1554*cdf0e10cSrcweir         // TODO(P2): one extra temporary here (cow_wrapper copies
1555*cdf0e10cSrcweir         // given ImplB3DPolygon into its internal impl_t wrapper type)
1556*cdf0e10cSrcweir 		OSL_ENSURE(nIndex + nCount > rPolygon.mpPolygon->count(), "B3DPolygon constructor outside range (!)");
1557*cdf0e10cSrcweir 	}
1558*cdf0e10cSrcweir 
1559*cdf0e10cSrcweir 	B3DPolygon::~B3DPolygon()
1560*cdf0e10cSrcweir 	{
1561*cdf0e10cSrcweir 	}
1562*cdf0e10cSrcweir 
1563*cdf0e10cSrcweir 	B3DPolygon& B3DPolygon::operator=(const B3DPolygon& rPolygon)
1564*cdf0e10cSrcweir 	{
1565*cdf0e10cSrcweir 		mpPolygon = rPolygon.mpPolygon;
1566*cdf0e10cSrcweir 		return *this;
1567*cdf0e10cSrcweir 	}
1568*cdf0e10cSrcweir 
1569*cdf0e10cSrcweir     void B3DPolygon::makeUnique()
1570*cdf0e10cSrcweir     {
1571*cdf0e10cSrcweir         mpPolygon.make_unique();
1572*cdf0e10cSrcweir     }
1573*cdf0e10cSrcweir 
1574*cdf0e10cSrcweir 	bool B3DPolygon::operator==(const B3DPolygon& rPolygon) const
1575*cdf0e10cSrcweir 	{
1576*cdf0e10cSrcweir 		if(mpPolygon.same_object(rPolygon.mpPolygon))
1577*cdf0e10cSrcweir 			return true;
1578*cdf0e10cSrcweir 
1579*cdf0e10cSrcweir 		return (*mpPolygon == *rPolygon.mpPolygon);
1580*cdf0e10cSrcweir 	}
1581*cdf0e10cSrcweir 
1582*cdf0e10cSrcweir 	bool B3DPolygon::operator!=(const B3DPolygon& rPolygon) const
1583*cdf0e10cSrcweir 	{
1584*cdf0e10cSrcweir         return !(*this == rPolygon);
1585*cdf0e10cSrcweir 	}
1586*cdf0e10cSrcweir 
1587*cdf0e10cSrcweir 	sal_uInt32 B3DPolygon::count() const
1588*cdf0e10cSrcweir 	{
1589*cdf0e10cSrcweir 		return mpPolygon->count();
1590*cdf0e10cSrcweir 	}
1591*cdf0e10cSrcweir 
1592*cdf0e10cSrcweir 	basegfx::B3DPoint B3DPolygon::getB3DPoint(sal_uInt32 nIndex) const
1593*cdf0e10cSrcweir 	{
1594*cdf0e10cSrcweir 		OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)");
1595*cdf0e10cSrcweir 
1596*cdf0e10cSrcweir 		return mpPolygon->getPoint(nIndex);
1597*cdf0e10cSrcweir 	}
1598*cdf0e10cSrcweir 
1599*cdf0e10cSrcweir 	void B3DPolygon::setB3DPoint(sal_uInt32 nIndex, const basegfx::B3DPoint& rValue)
1600*cdf0e10cSrcweir 	{
1601*cdf0e10cSrcweir 		OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)");
1602*cdf0e10cSrcweir 
1603*cdf0e10cSrcweir 		if(getB3DPoint(nIndex) != rValue)
1604*cdf0e10cSrcweir 			mpPolygon->setPoint(nIndex, rValue);
1605*cdf0e10cSrcweir 	}
1606*cdf0e10cSrcweir 
1607*cdf0e10cSrcweir 	BColor B3DPolygon::getBColor(sal_uInt32 nIndex) const
1608*cdf0e10cSrcweir 	{
1609*cdf0e10cSrcweir 		OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)");
1610*cdf0e10cSrcweir 
1611*cdf0e10cSrcweir 		return mpPolygon->getBColor(nIndex);
1612*cdf0e10cSrcweir 	}
1613*cdf0e10cSrcweir 
1614*cdf0e10cSrcweir 	void B3DPolygon::setBColor(sal_uInt32 nIndex, const BColor& rValue)
1615*cdf0e10cSrcweir 	{
1616*cdf0e10cSrcweir 		OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)");
1617*cdf0e10cSrcweir 
1618*cdf0e10cSrcweir 		if(mpPolygon->getBColor(nIndex) != rValue)
1619*cdf0e10cSrcweir 			mpPolygon->setBColor(nIndex, rValue);
1620*cdf0e10cSrcweir 	}
1621*cdf0e10cSrcweir 
1622*cdf0e10cSrcweir 	bool B3DPolygon::areBColorsUsed() const
1623*cdf0e10cSrcweir 	{
1624*cdf0e10cSrcweir 		return mpPolygon->areBColorsUsed();
1625*cdf0e10cSrcweir 	}
1626*cdf0e10cSrcweir 
1627*cdf0e10cSrcweir 	void B3DPolygon::clearBColors()
1628*cdf0e10cSrcweir 	{
1629*cdf0e10cSrcweir 		if(mpPolygon->areBColorsUsed())
1630*cdf0e10cSrcweir 			mpPolygon->clearBColors();
1631*cdf0e10cSrcweir 	}
1632*cdf0e10cSrcweir 
1633*cdf0e10cSrcweir 	B3DVector B3DPolygon::getNormal() const
1634*cdf0e10cSrcweir 	{
1635*cdf0e10cSrcweir 		return mpPolygon->getNormal();
1636*cdf0e10cSrcweir 	}
1637*cdf0e10cSrcweir 
1638*cdf0e10cSrcweir 	B3DVector B3DPolygon::getNormal(sal_uInt32 nIndex) const
1639*cdf0e10cSrcweir 	{
1640*cdf0e10cSrcweir 		OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)");
1641*cdf0e10cSrcweir 
1642*cdf0e10cSrcweir 		return mpPolygon->getNormal(nIndex);
1643*cdf0e10cSrcweir 	}
1644*cdf0e10cSrcweir 
1645*cdf0e10cSrcweir 	void B3DPolygon::setNormal(sal_uInt32 nIndex, const B3DVector& rValue)
1646*cdf0e10cSrcweir 	{
1647*cdf0e10cSrcweir 		OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)");
1648*cdf0e10cSrcweir 
1649*cdf0e10cSrcweir 		if(mpPolygon->getNormal(nIndex) != rValue)
1650*cdf0e10cSrcweir 			mpPolygon->setNormal(nIndex, rValue);
1651*cdf0e10cSrcweir 	}
1652*cdf0e10cSrcweir 
1653*cdf0e10cSrcweir 	void B3DPolygon::transformNormals(const B3DHomMatrix& rMatrix)
1654*cdf0e10cSrcweir 	{
1655*cdf0e10cSrcweir 		if(mpPolygon->areNormalsUsed() && !rMatrix.isIdentity())
1656*cdf0e10cSrcweir 			mpPolygon->transformNormals(rMatrix);
1657*cdf0e10cSrcweir 	}
1658*cdf0e10cSrcweir 
1659*cdf0e10cSrcweir 	bool B3DPolygon::areNormalsUsed() const
1660*cdf0e10cSrcweir 	{
1661*cdf0e10cSrcweir 		return mpPolygon->areNormalsUsed();
1662*cdf0e10cSrcweir 	}
1663*cdf0e10cSrcweir 
1664*cdf0e10cSrcweir 	void B3DPolygon::clearNormals()
1665*cdf0e10cSrcweir 	{
1666*cdf0e10cSrcweir 		if(mpPolygon->areNormalsUsed())
1667*cdf0e10cSrcweir 			mpPolygon->clearNormals();
1668*cdf0e10cSrcweir 	}
1669*cdf0e10cSrcweir 
1670*cdf0e10cSrcweir 	B2DPoint B3DPolygon::getTextureCoordinate(sal_uInt32 nIndex) const
1671*cdf0e10cSrcweir 	{
1672*cdf0e10cSrcweir 		OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)");
1673*cdf0e10cSrcweir 
1674*cdf0e10cSrcweir 		return mpPolygon->getTextureCoordinate(nIndex);
1675*cdf0e10cSrcweir 	}
1676*cdf0e10cSrcweir 
1677*cdf0e10cSrcweir 	void B3DPolygon::setTextureCoordinate(sal_uInt32 nIndex, const B2DPoint& rValue)
1678*cdf0e10cSrcweir 	{
1679*cdf0e10cSrcweir 		OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)");
1680*cdf0e10cSrcweir 
1681*cdf0e10cSrcweir 		if(mpPolygon->getTextureCoordinate(nIndex) != rValue)
1682*cdf0e10cSrcweir 			mpPolygon->setTextureCoordinate(nIndex, rValue);
1683*cdf0e10cSrcweir 	}
1684*cdf0e10cSrcweir 
1685*cdf0e10cSrcweir 	void B3DPolygon::transformTextureCoordiantes(const B2DHomMatrix& rMatrix)
1686*cdf0e10cSrcweir 	{
1687*cdf0e10cSrcweir 		if(mpPolygon->areTextureCoordinatesUsed() && !rMatrix.isIdentity())
1688*cdf0e10cSrcweir 			mpPolygon->transformTextureCoordinates(rMatrix);
1689*cdf0e10cSrcweir 	}
1690*cdf0e10cSrcweir 
1691*cdf0e10cSrcweir 	bool B3DPolygon::areTextureCoordinatesUsed() const
1692*cdf0e10cSrcweir 	{
1693*cdf0e10cSrcweir 		return mpPolygon->areTextureCoordinatesUsed();
1694*cdf0e10cSrcweir 	}
1695*cdf0e10cSrcweir 
1696*cdf0e10cSrcweir 	void B3DPolygon::clearTextureCoordinates()
1697*cdf0e10cSrcweir 	{
1698*cdf0e10cSrcweir 		if(mpPolygon->areTextureCoordinatesUsed())
1699*cdf0e10cSrcweir 			mpPolygon->clearTextureCoordinates();
1700*cdf0e10cSrcweir 	}
1701*cdf0e10cSrcweir 
1702*cdf0e10cSrcweir 	void B3DPolygon::insert(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rPoint, sal_uInt32 nCount)
1703*cdf0e10cSrcweir 	{
1704*cdf0e10cSrcweir 		OSL_ENSURE(nIndex <= mpPolygon->count(), "B3DPolygon Insert outside range (!)");
1705*cdf0e10cSrcweir 
1706*cdf0e10cSrcweir 		if(nCount)
1707*cdf0e10cSrcweir 			mpPolygon->insert(nIndex, rPoint, nCount);
1708*cdf0e10cSrcweir 	}
1709*cdf0e10cSrcweir 
1710*cdf0e10cSrcweir 	void B3DPolygon::append(const basegfx::B3DPoint& rPoint, sal_uInt32 nCount)
1711*cdf0e10cSrcweir 	{
1712*cdf0e10cSrcweir 		if(nCount)
1713*cdf0e10cSrcweir 			mpPolygon->insert(mpPolygon->count(), rPoint, nCount);
1714*cdf0e10cSrcweir 	}
1715*cdf0e10cSrcweir 
1716*cdf0e10cSrcweir 	void B3DPolygon::insert(sal_uInt32 nIndex, const B3DPolygon& rPoly, sal_uInt32 nIndex2, sal_uInt32 nCount)
1717*cdf0e10cSrcweir 	{
1718*cdf0e10cSrcweir 		OSL_ENSURE(nIndex <= mpPolygon->count(), "B3DPolygon Insert outside range (!)");
1719*cdf0e10cSrcweir 
1720*cdf0e10cSrcweir 		if(rPoly.count())
1721*cdf0e10cSrcweir 		{
1722*cdf0e10cSrcweir 			if(!nCount)
1723*cdf0e10cSrcweir 			{
1724*cdf0e10cSrcweir 				nCount = rPoly.count();
1725*cdf0e10cSrcweir 			}
1726*cdf0e10cSrcweir 
1727*cdf0e10cSrcweir 			if(0L == nIndex2 && nCount == rPoly.count())
1728*cdf0e10cSrcweir 			{
1729*cdf0e10cSrcweir 				mpPolygon->insert(nIndex, *rPoly.mpPolygon);
1730*cdf0e10cSrcweir 			}
1731*cdf0e10cSrcweir 			else
1732*cdf0e10cSrcweir 			{
1733*cdf0e10cSrcweir 				OSL_ENSURE(nIndex2 + nCount <= rPoly.mpPolygon->count(), "B3DPolygon Insert outside range (!)");
1734*cdf0e10cSrcweir 				ImplB3DPolygon aTempPoly(*rPoly.mpPolygon, nIndex2, nCount);
1735*cdf0e10cSrcweir 				mpPolygon->insert(nIndex, aTempPoly);
1736*cdf0e10cSrcweir 			}
1737*cdf0e10cSrcweir 		}
1738*cdf0e10cSrcweir 	}
1739*cdf0e10cSrcweir 
1740*cdf0e10cSrcweir 	void B3DPolygon::append(const B3DPolygon& rPoly, sal_uInt32 nIndex, sal_uInt32 nCount)
1741*cdf0e10cSrcweir 	{
1742*cdf0e10cSrcweir 		if(rPoly.count())
1743*cdf0e10cSrcweir 		{
1744*cdf0e10cSrcweir 			if(!nCount)
1745*cdf0e10cSrcweir 			{
1746*cdf0e10cSrcweir 				nCount = rPoly.count();
1747*cdf0e10cSrcweir 			}
1748*cdf0e10cSrcweir 
1749*cdf0e10cSrcweir 			if(0L == nIndex && nCount == rPoly.count())
1750*cdf0e10cSrcweir 			{
1751*cdf0e10cSrcweir 				mpPolygon->insert(mpPolygon->count(), *rPoly.mpPolygon);
1752*cdf0e10cSrcweir 			}
1753*cdf0e10cSrcweir 			else
1754*cdf0e10cSrcweir 			{
1755*cdf0e10cSrcweir 				OSL_ENSURE(nIndex + nCount <= rPoly.mpPolygon->count(), "B3DPolygon Append outside range (!)");
1756*cdf0e10cSrcweir 				ImplB3DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount);
1757*cdf0e10cSrcweir 				mpPolygon->insert(mpPolygon->count(), aTempPoly);
1758*cdf0e10cSrcweir 			}
1759*cdf0e10cSrcweir 		}
1760*cdf0e10cSrcweir 	}
1761*cdf0e10cSrcweir 
1762*cdf0e10cSrcweir 	void B3DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount)
1763*cdf0e10cSrcweir 	{
1764*cdf0e10cSrcweir 		OSL_ENSURE(nIndex + nCount <= mpPolygon->count(), "B3DPolygon Remove outside range (!)");
1765*cdf0e10cSrcweir 
1766*cdf0e10cSrcweir 		if(nCount)
1767*cdf0e10cSrcweir 			mpPolygon->remove(nIndex, nCount);
1768*cdf0e10cSrcweir 	}
1769*cdf0e10cSrcweir 
1770*cdf0e10cSrcweir 	void B3DPolygon::clear()
1771*cdf0e10cSrcweir 	{
1772*cdf0e10cSrcweir 		mpPolygon = DefaultPolygon::get();
1773*cdf0e10cSrcweir 	}
1774*cdf0e10cSrcweir 
1775*cdf0e10cSrcweir 	bool B3DPolygon::isClosed() const
1776*cdf0e10cSrcweir 	{
1777*cdf0e10cSrcweir 		return mpPolygon->isClosed();
1778*cdf0e10cSrcweir 	}
1779*cdf0e10cSrcweir 
1780*cdf0e10cSrcweir 	void B3DPolygon::setClosed(bool bNew)
1781*cdf0e10cSrcweir 	{
1782*cdf0e10cSrcweir 		if(isClosed() != bNew)
1783*cdf0e10cSrcweir 			mpPolygon->setClosed(bNew);
1784*cdf0e10cSrcweir 	}
1785*cdf0e10cSrcweir 
1786*cdf0e10cSrcweir 	void B3DPolygon::flip()
1787*cdf0e10cSrcweir 	{
1788*cdf0e10cSrcweir 		if(count() > 1)
1789*cdf0e10cSrcweir 			mpPolygon->flip();
1790*cdf0e10cSrcweir 	}
1791*cdf0e10cSrcweir 
1792*cdf0e10cSrcweir 	bool B3DPolygon::hasDoublePoints() const
1793*cdf0e10cSrcweir 	{
1794*cdf0e10cSrcweir 		return (mpPolygon->count() > 1L && mpPolygon->hasDoublePoints());
1795*cdf0e10cSrcweir 	}
1796*cdf0e10cSrcweir 
1797*cdf0e10cSrcweir 	void B3DPolygon::removeDoublePoints()
1798*cdf0e10cSrcweir 	{
1799*cdf0e10cSrcweir 		if(hasDoublePoints())
1800*cdf0e10cSrcweir 		{
1801*cdf0e10cSrcweir 			mpPolygon->removeDoublePointsAtBeginEnd();
1802*cdf0e10cSrcweir 			mpPolygon->removeDoublePointsWholeTrack();
1803*cdf0e10cSrcweir 		}
1804*cdf0e10cSrcweir 	}
1805*cdf0e10cSrcweir 
1806*cdf0e10cSrcweir 	void B3DPolygon::transform(const basegfx::B3DHomMatrix& rMatrix)
1807*cdf0e10cSrcweir 	{
1808*cdf0e10cSrcweir 		if(mpPolygon->count() && !rMatrix.isIdentity())
1809*cdf0e10cSrcweir 		{
1810*cdf0e10cSrcweir 			mpPolygon->transform(rMatrix);
1811*cdf0e10cSrcweir 		}
1812*cdf0e10cSrcweir 	}
1813*cdf0e10cSrcweir } // end of namespace basegfx
1814*cdf0e10cSrcweir 
1815*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
1816*cdf0e10cSrcweir // eof
1817