xref: /trunk/main/basegfx/source/inc/PolygonPoint.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 #ifndef _POLYGON_POINT_HXX
29*cdf0e10cSrcweir #define _POLYGON_POINT_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <vector>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir template < class Point > class SimplePointEntry
36*cdf0e10cSrcweir {
37*cdf0e10cSrcweir     Point                                           maPoint;
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir public:
40*cdf0e10cSrcweir     SimplePointEntry()
41*cdf0e10cSrcweir     :   maPoint(Point::getEmptyPoint())
42*cdf0e10cSrcweir     {
43*cdf0e10cSrcweir     }
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir     SimplePointEntry(const Point& rInitPoint)
46*cdf0e10cSrcweir     :   maPoint(rInitPoint)
47*cdf0e10cSrcweir     {
48*cdf0e10cSrcweir     }
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir     const Point& getPoint() const
51*cdf0e10cSrcweir     {
52*cdf0e10cSrcweir         return maPoint;
53*cdf0e10cSrcweir     }
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir     void setPoint(const Point& rValue)
56*cdf0e10cSrcweir     {
57*cdf0e10cSrcweir         maPoint = rValue;
58*cdf0e10cSrcweir     }
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir     bool operator==(const SimplePointEntry& rEntry) const
61*cdf0e10cSrcweir     {
62*cdf0e10cSrcweir         return (maPoint == rEntry.maPoint);
63*cdf0e10cSrcweir     }
64*cdf0e10cSrcweir };
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir template < class Vector > class SimpleBezierEntry
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir     Vector                                          maBackward;
71*cdf0e10cSrcweir     Vector                                          maForward;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir public:
74*cdf0e10cSrcweir     SimpleBezierEntry()
75*cdf0e10cSrcweir     :   maBackward(Vector::getEmptyVector()),
76*cdf0e10cSrcweir         maForward(Vector::getEmptyVector())
77*cdf0e10cSrcweir     {
78*cdf0e10cSrcweir     }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     SimpleBezierEntry(const Vector& rInitBackward, const Vector& rInitForward)
81*cdf0e10cSrcweir     :   maBackward(rInitBackward),
82*cdf0e10cSrcweir         maForward(rInitForward)
83*cdf0e10cSrcweir     {
84*cdf0e10cSrcweir     }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir     const Vector& getBackwardVector() const
87*cdf0e10cSrcweir     {
88*cdf0e10cSrcweir         return maBackward;
89*cdf0e10cSrcweir     }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     void setBackwardVector(const Vector& rValue)
92*cdf0e10cSrcweir     {
93*cdf0e10cSrcweir         maBackward = rValue;
94*cdf0e10cSrcweir     }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir     const Vector& getForwardVector() const
97*cdf0e10cSrcweir     {
98*cdf0e10cSrcweir         return maForward;
99*cdf0e10cSrcweir     }
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir     void setForwardVector(const Vector& rValue)
102*cdf0e10cSrcweir     {
103*cdf0e10cSrcweir         maForward = rValue;
104*cdf0e10cSrcweir     }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     bool isBezierNeeded()
107*cdf0e10cSrcweir     {
108*cdf0e10cSrcweir         if(maBackward != Vector::getEmptyVector() || maForward != Vector::getEmptyVector())
109*cdf0e10cSrcweir             return true;
110*cdf0e10cSrcweir         return false;
111*cdf0e10cSrcweir     }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     bool operator==(const SimpleBezierEntry& rEntry) const
114*cdf0e10cSrcweir     {
115*cdf0e10cSrcweir         return ((maBackward == rEntry.maBackward) && (maForward == rEntry.maForward));
116*cdf0e10cSrcweir     }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     void doInvertForFlip()
119*cdf0e10cSrcweir     {
120*cdf0e10cSrcweir         maBackward = -maBackward;
121*cdf0e10cSrcweir         maForward = -maForward;
122*cdf0e10cSrcweir     }
123*cdf0e10cSrcweir };
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir template < class Point, class Vector > class PolygonPointList
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir     typedef SimplePointEntry< Point > LocalSimplePointEntry;
130*cdf0e10cSrcweir     typedef SimpleBezierEntry< Vector > LocalSimpleBezierEntry;
131*cdf0e10cSrcweir     typedef ::std::vector< LocalSimplePointEntry > SimplePointVector;
132*cdf0e10cSrcweir     typedef ::std::vector< LocalSimpleBezierEntry > SimpleBezierVector;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     sal_uInt32                                      mnBezierCount;
135*cdf0e10cSrcweir     SimplePointVector                               maPoints;
136*cdf0e10cSrcweir     SimpleBezierVector*                             mpVectors;
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir     unsigned                                        mbIsClosed : 1;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     void implTryToReduceToPointVector()
141*cdf0e10cSrcweir     {
142*cdf0e10cSrcweir         if(!mnBezierCount && mpVectors)
143*cdf0e10cSrcweir         {
144*cdf0e10cSrcweir             delete mpVectors;
145*cdf0e10cSrcweir             mpVectors = 0L;
146*cdf0e10cSrcweir         }
147*cdf0e10cSrcweir     }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir public:
150*cdf0e10cSrcweir     bool isBezier() const
151*cdf0e10cSrcweir     {
152*cdf0e10cSrcweir         return bool(mnBezierCount);
153*cdf0e10cSrcweir     }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     bool isClosed() const
156*cdf0e10cSrcweir     {
157*cdf0e10cSrcweir         return bool(mbIsClosed);
158*cdf0e10cSrcweir     }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     void setClosed(bool bNew)
161*cdf0e10cSrcweir     {
162*cdf0e10cSrcweir         mbIsClosed = bNew;
163*cdf0e10cSrcweir     }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     sal_uInt32 count() const
166*cdf0e10cSrcweir     {
167*cdf0e10cSrcweir         return maPoints.size();
168*cdf0e10cSrcweir     }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     PolygonPointList()
171*cdf0e10cSrcweir     :   mnBezierCount(0L),
172*cdf0e10cSrcweir         mpVectors(0L),
173*cdf0e10cSrcweir         mbIsClosed(false)
174*cdf0e10cSrcweir     {
175*cdf0e10cSrcweir         // complete initialization with defaults
176*cdf0e10cSrcweir     }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir     PolygonPointList(const PolygonPointList& rSource)
179*cdf0e10cSrcweir     :   mnBezierCount(0L),
180*cdf0e10cSrcweir         maPoints(rSource.maPoints),
181*cdf0e10cSrcweir         mpVectors(0L),
182*cdf0e10cSrcweir         mbIsClosed(rSource.mbIsClosed)
183*cdf0e10cSrcweir     {
184*cdf0e10cSrcweir         // complete initialization using copy
185*cdf0e10cSrcweir         if(rSource.mpVectors && rSource.mnBezierCount)
186*cdf0e10cSrcweir         {
187*cdf0e10cSrcweir             mpVectors = new SimpleBezierVector(*rSource.mpVectors);
188*cdf0e10cSrcweir             mnBezierCount = rSource.mnBezierCount;
189*cdf0e10cSrcweir         }
190*cdf0e10cSrcweir     }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     PolygonPointList(const PolygonPointList& rSource, sal_uInt32 nIndex, sal_uInt32 nCount)
193*cdf0e10cSrcweir     :   mnBezierCount(0L),
194*cdf0e10cSrcweir         maPoints(nCount),
195*cdf0e10cSrcweir         mpVectors(0L),
196*cdf0e10cSrcweir         mbIsClosed(rSource.mbIsClosed)
197*cdf0e10cSrcweir     {
198*cdf0e10cSrcweir         // complete initialization using partly copy
199*cdf0e10cSrcweir         if(nCount)
200*cdf0e10cSrcweir         {
201*cdf0e10cSrcweir             // copy point data
202*cdf0e10cSrcweir             {
203*cdf0e10cSrcweir                 SimplePointVector::const_iterator aStart(rSource.maPoints.begin());
204*cdf0e10cSrcweir                 aStart += nIndex;
205*cdf0e10cSrcweir                 SimplePointVector::const_iterator aEnd(aStart);
206*cdf0e10cSrcweir                 aEnd += nCount;
207*cdf0e10cSrcweir                 maPoints.insert(0L, aStart, aEnd);
208*cdf0e10cSrcweir             }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir             // copy bezier data
211*cdf0e10cSrcweir             if(rSource.mpVectors && rSource.mnBezierCount)
212*cdf0e10cSrcweir             {
213*cdf0e10cSrcweir                 mpVectors = new SimpleBezierVector();
214*cdf0e10cSrcweir                 mpVectors->reserve(nCount);
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir                 SimpleBezierVector::iterator aStart(mpVectors->begin());
217*cdf0e10cSrcweir                 aStart += nIndex;
218*cdf0e10cSrcweir                 SimpleBezierVector::iterator aEnd(aStart);
219*cdf0e10cSrcweir                 aEnd += nCount;
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir                 for( ; aStart != aEnd; ++aStart )
222*cdf0e10cSrcweir                 {
223*cdf0e10cSrcweir                     if(aStart->IsBezierNeeded())
224*cdf0e10cSrcweir                     {
225*cdf0e10cSrcweir                         mnBezierCount++;
226*cdf0e10cSrcweir                     }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir                     mpVectors->push_back(*aStart);
229*cdf0e10cSrcweir                 }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir                 // maybe vectors are not needed anymore, try to reduce memory footprint
232*cdf0e10cSrcweir                 implTryToReduceToPointVector();
233*cdf0e10cSrcweir             }
234*cdf0e10cSrcweir         }
235*cdf0e10cSrcweir     }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir     ~PolygonPointList()
238*cdf0e10cSrcweir     {
239*cdf0e10cSrcweir         if(mpVectors)
240*cdf0e10cSrcweir         {
241*cdf0e10cSrcweir             delete mpVectors;
242*cdf0e10cSrcweir         }
243*cdf0e10cSrcweir     }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir     bool isEqual(const PolygonPointList& rPointList) const
246*cdf0e10cSrcweir     {
247*cdf0e10cSrcweir         // same point count?
248*cdf0e10cSrcweir         if(maPoints.size() != rPointList.maPoints.size())
249*cdf0e10cSrcweir             return false;
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir         // if zero points the polys are equal
252*cdf0e10cSrcweir         if(!maPoints.size())
253*cdf0e10cSrcweir             return true;
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir         // if bezier count used it needs to be equal
256*cdf0e10cSrcweir         if(mnBezierCount != rPointList.mnBezierCount)
257*cdf0e10cSrcweir             return false;
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir         // compare point content
260*cdf0e10cSrcweir         if(maPoints != rPointList.maPoints)
261*cdf0e10cSrcweir             return false;
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir         // beziercounts are equal: if it's zero, we are done
264*cdf0e10cSrcweir         if(!mnBezierCount)
265*cdf0e10cSrcweir             return true;
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir         // beziercounts are equal and not zero; compare them
268*cdf0e10cSrcweir         OSL_ENSURE(0L != mpVectors, "Error: Bezier list needs to exist here(!)");
269*cdf0e10cSrcweir         OSL_ENSURE(0L != rPointList.mpVectors, "Error: Bezier list needs to exist here(!)");
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir         return (*mpVectors == *rPointList.mpVectors);
272*cdf0e10cSrcweir     }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir     const Point& getPoint(sal_uInt32 nIndex) const
275*cdf0e10cSrcweir     {
276*cdf0e10cSrcweir         return maPoints[nIndex].getPoint();
277*cdf0e10cSrcweir     }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir     void setPoint(sal_uInt32 nIndex, const Point& rValue)
280*cdf0e10cSrcweir     {
281*cdf0e10cSrcweir         maPoints[nIndex].setPoint(rValue);
282*cdf0e10cSrcweir     }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir     const Vector& getBackwardVector(sal_uInt32 nIndex) const
285*cdf0e10cSrcweir     {
286*cdf0e10cSrcweir         if(mpVectors)
287*cdf0e10cSrcweir             return ((*mpVectors)[nIndex]).getBackwardVector();
288*cdf0e10cSrcweir         else
289*cdf0e10cSrcweir             return Vector::getEmptyVector();
290*cdf0e10cSrcweir     }
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir     void setBackwardVector(sal_uInt32 nIndex, const Vector& rValue)
293*cdf0e10cSrcweir     {
294*cdf0e10cSrcweir         if(mpVectors)
295*cdf0e10cSrcweir         {
296*cdf0e10cSrcweir             LocalSimpleBezierEntry& rDest = (*mpVectors)[nIndex];
297*cdf0e10cSrcweir             bool bBezierNeededBefore(rDest.isBezierNeeded());
298*cdf0e10cSrcweir             ((*mpVectors)[nIndex]).setBackwardVector(rValue);
299*cdf0e10cSrcweir             bool bBezierNeededAfter(rDest.isBezierNeeded());
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir             if(bBezierNeededBefore != bBezierNeededAfter)
302*cdf0e10cSrcweir             {
303*cdf0e10cSrcweir                 if(bBezierNeededAfter)
304*cdf0e10cSrcweir                     mnBezierCount++;
305*cdf0e10cSrcweir                 else
306*cdf0e10cSrcweir                     mnBezierCount--;
307*cdf0e10cSrcweir             }
308*cdf0e10cSrcweir         }
309*cdf0e10cSrcweir         else
310*cdf0e10cSrcweir         {
311*cdf0e10cSrcweir             bool bEmptyVector(rValue == Vector::getEmptyVector());
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir             if(bEmptyVector)
314*cdf0e10cSrcweir                 return;
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir             mpVectors = new SimpleBezierVector(maPoints.size());
317*cdf0e10cSrcweir             ((*mpVectors)[nIndex]).setBackwardVector(rValue);
318*cdf0e10cSrcweir             mnBezierCount++;
319*cdf0e10cSrcweir         }
320*cdf0e10cSrcweir     }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir     const Vector& getForwardVector(sal_uInt32 nIndex) const
323*cdf0e10cSrcweir     {
324*cdf0e10cSrcweir         if(mpVectors)
325*cdf0e10cSrcweir             return ((*mpVectors)[nIndex]).getForwardVector();
326*cdf0e10cSrcweir         else
327*cdf0e10cSrcweir             return Vector::getEmptyVector();
328*cdf0e10cSrcweir     }
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir     void setForwardVector(sal_uInt32 nIndex, const Vector& rValue)
331*cdf0e10cSrcweir     {
332*cdf0e10cSrcweir         if(mpVectors)
333*cdf0e10cSrcweir         {
334*cdf0e10cSrcweir             LocalSimpleBezierEntry& rDest = (*mpVectors)[nIndex];
335*cdf0e10cSrcweir             bool bBezierNeededBefore(rDest.isBezierNeeded());
336*cdf0e10cSrcweir             ((*mpVectors)[nIndex]).setForwardVector(rValue);
337*cdf0e10cSrcweir             bool bBezierNeededAfter(rDest.isBezierNeeded());
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir             if(bBezierNeededBefore != bBezierNeededAfter)
340*cdf0e10cSrcweir             {
341*cdf0e10cSrcweir                 if(bBezierNeededAfter)
342*cdf0e10cSrcweir                     mnBezierCount++;
343*cdf0e10cSrcweir                 else
344*cdf0e10cSrcweir                     mnBezierCount--;
345*cdf0e10cSrcweir             }
346*cdf0e10cSrcweir         }
347*cdf0e10cSrcweir         else
348*cdf0e10cSrcweir         {
349*cdf0e10cSrcweir             bool bEmptyVector(rValue == Vector::getEmptyVector());
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir             if(bEmptyVector)
352*cdf0e10cSrcweir                 return;
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir             mpVectors = new SimpleBezierVector(maPoints.size());
355*cdf0e10cSrcweir             ((*mpVectors)[nIndex]).setForwardVector(rValue);
356*cdf0e10cSrcweir             mnBezierCount++;
357*cdf0e10cSrcweir         }
358*cdf0e10cSrcweir     }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir     void insert(sal_uInt32 nIndex, const Point& rPoint, sal_uInt32 nCount)
361*cdf0e10cSrcweir     {
362*cdf0e10cSrcweir         if(nCount)
363*cdf0e10cSrcweir         {
364*cdf0e10cSrcweir             // maybe vectors are not needed anymore, try to reduce memory footprint
365*cdf0e10cSrcweir             implTryToReduceToPointVector();
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir             // add nCount copies of rPoint
368*cdf0e10cSrcweir             {
369*cdf0e10cSrcweir                 LocalSimplePointEntry aNode(rPoint);
370*cdf0e10cSrcweir                 SimplePointVector::iterator aIndex(maPoints.begin());
371*cdf0e10cSrcweir                 aIndex += nIndex;
372*cdf0e10cSrcweir                 maPoints.insert(aIndex, nCount, aNode);
373*cdf0e10cSrcweir             }
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir             // add nCount empty entries to keep indices synchronized
376*cdf0e10cSrcweir             if(mpVectors)
377*cdf0e10cSrcweir             {
378*cdf0e10cSrcweir                 LocalSimpleBezierEntry aNode;
379*cdf0e10cSrcweir                 SimpleBezierVector::iterator aIndex(mpVectors->begin());
380*cdf0e10cSrcweir                 aIndex += nIndex;
381*cdf0e10cSrcweir                 mpVectors->insert(aIndex, nCount, aNode);
382*cdf0e10cSrcweir             }
383*cdf0e10cSrcweir         }
384*cdf0e10cSrcweir     }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir     void insert(sal_uInt32 nIndex, const PolygonPointList& rSource)
387*cdf0e10cSrcweir     {
388*cdf0e10cSrcweir         const sal_uInt32 nCount(rSource.maPoints.size());
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir         if(nCount)
391*cdf0e10cSrcweir         {
392*cdf0e10cSrcweir             // instert point data
393*cdf0e10cSrcweir             {
394*cdf0e10cSrcweir                 SimplePointVector::iterator aIndex(maPoints.begin());
395*cdf0e10cSrcweir                 aIndex += nIndex;
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir                 SimplePointVector::const_iterator aStart(rSource.maPoints.begin());
398*cdf0e10cSrcweir                 SimplePointVector::const_iterator aEnd(rSource.maPoints.end());
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir                 maPoints.insert(aIndex, aStart, aEnd);
401*cdf0e10cSrcweir             }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir             // insert bezier data
404*cdf0e10cSrcweir             if(rSource.mpVectors && rSource.mnBezierCount)
405*cdf0e10cSrcweir             {
406*cdf0e10cSrcweir                 SimpleBezierVector::iterator aIndex(mpVectors->begin());
407*cdf0e10cSrcweir                 aIndex += nIndex;
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir                 SimpleBezierVector::iterator aStart(rSource.mpVectors->begin());
410*cdf0e10cSrcweir                 SimpleBezierVector::iterator aEnd(rSource.mpVectors->end());
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir                 if(!mpVectors)
413*cdf0e10cSrcweir                 {
414*cdf0e10cSrcweir                     mpVectors = new SimpleBezierVector(maPoints.size() - nCount);
415*cdf0e10cSrcweir                 }
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir                 mpVectors->insert(aIndex, aStart, aEnd);
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir                 mnBezierCount += rSource.mnBezierCount;
420*cdf0e10cSrcweir             }
421*cdf0e10cSrcweir             else
422*cdf0e10cSrcweir             {
423*cdf0e10cSrcweir                 // maybe vectors are not needed anymore, try to reduce memory footprint
424*cdf0e10cSrcweir                 implTryToReduceToPointVector();
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir                 // add nCount empty entries to keep indices synchronized
427*cdf0e10cSrcweir                 if(mpVectors)
428*cdf0e10cSrcweir                 {
429*cdf0e10cSrcweir                     LocalSimpleBezierEntry aNode;
430*cdf0e10cSrcweir                     SimpleBezierVector::iterator aIndex(mpVectors->begin());
431*cdf0e10cSrcweir                     aIndex += nIndex;
432*cdf0e10cSrcweir                     mpVectors->insert(aIndex, nCount, aNode);
433*cdf0e10cSrcweir                 }
434*cdf0e10cSrcweir             }
435*cdf0e10cSrcweir         }
436*cdf0e10cSrcweir     }
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir     void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
439*cdf0e10cSrcweir     {
440*cdf0e10cSrcweir         if(nCount)
441*cdf0e10cSrcweir         {
442*cdf0e10cSrcweir             // maybe vectors are not needed anymore, try to reduce memory footprint
443*cdf0e10cSrcweir             implTryToReduceToPointVector();
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir             // remove point data
446*cdf0e10cSrcweir             {
447*cdf0e10cSrcweir                 SimplePointVector::iterator aStart(maPoints.begin());
448*cdf0e10cSrcweir                 aStart += nIndex;
449*cdf0e10cSrcweir                 const SimplePointVector::iterator aEnd(aStart + nCount);
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir                 maPoints.erase(aStart, aEnd);
452*cdf0e10cSrcweir             }
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir             // remove bezier data
455*cdf0e10cSrcweir             if(mpVectors)
456*cdf0e10cSrcweir             {
457*cdf0e10cSrcweir                 SimpleBezierVector::iterator aStart(mpVectors->begin());
458*cdf0e10cSrcweir                 aStart += nIndex;
459*cdf0e10cSrcweir                 const SimpleBezierVector::iterator aEnd(aStart + nCount);
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir                 // take care for correct mnBezierCount BEFORE erase
462*cdf0e10cSrcweir                 if(mnBezierCount)
463*cdf0e10cSrcweir                 {
464*cdf0e10cSrcweir                     SimpleBezierVector::iterator aTestIter(aStart);
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir                     for( ; mnBezierCount && aTestIter != aEnd; ++aTestIter)
467*cdf0e10cSrcweir                     {
468*cdf0e10cSrcweir                         if(aTestIter->isBezierNeeded())
469*cdf0e10cSrcweir                             mnBezierCount--;
470*cdf0e10cSrcweir                     }
471*cdf0e10cSrcweir                 }
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir                 if(mnBezierCount)
474*cdf0e10cSrcweir                 {
475*cdf0e10cSrcweir                     // erase nodes
476*cdf0e10cSrcweir                     mpVectors->erase(aStart, aEnd);
477*cdf0e10cSrcweir                 }
478*cdf0e10cSrcweir                 else
479*cdf0e10cSrcweir                 {
480*cdf0e10cSrcweir                     // try to reduce, maybe 0L == mnBezierCount
481*cdf0e10cSrcweir                     implTryToReduceToPointVector();
482*cdf0e10cSrcweir                 }
483*cdf0e10cSrcweir             }
484*cdf0e10cSrcweir         }
485*cdf0e10cSrcweir     }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir     void flip()
488*cdf0e10cSrcweir     {
489*cdf0e10cSrcweir         if(maPoints.size() > 1)
490*cdf0e10cSrcweir         {
491*cdf0e10cSrcweir             // maybe vectors are not needed anymore, try to reduce memory footprint
492*cdf0e10cSrcweir             implTryToReduceToPointVector();
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir             // calculate half size
495*cdf0e10cSrcweir             const sal_uInt32 nHalfSize(maPoints.size() >> 1L);
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir             // flip point data
498*cdf0e10cSrcweir             {
499*cdf0e10cSrcweir                 SimplePointVector::iterator aStart(maPoints.begin());
500*cdf0e10cSrcweir                 SimplePointVector::iterator aEnd(maPoints.end());
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir                 for(sal_uInt32 a(0); a < nHalfSize; a++)
503*cdf0e10cSrcweir                 {
504*cdf0e10cSrcweir                     LocalSimplePointEntry aTemp = *aStart;
505*cdf0e10cSrcweir                     *aStart++ = *aEnd;
506*cdf0e10cSrcweir                     *aEnd-- = aTemp;
507*cdf0e10cSrcweir                 }
508*cdf0e10cSrcweir             }
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir             // flip bezier data
511*cdf0e10cSrcweir             if(mpVectors)
512*cdf0e10cSrcweir             {
513*cdf0e10cSrcweir                 SimpleBezierVector::iterator aStart(mpVectors->begin());
514*cdf0e10cSrcweir                 SimpleBezierVector::iterator aEnd(mpVectors->end());
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir                 for(sal_uInt32 a(0); a < nHalfSize; a++)
517*cdf0e10cSrcweir                 {
518*cdf0e10cSrcweir                     LocalSimpleBezierEntry aTemp = *aStart;
519*cdf0e10cSrcweir                     aTemp.doInvertForFlip();
520*cdf0e10cSrcweir                     *aStart = *aEnd;
521*cdf0e10cSrcweir                     aStart->doInvertForFlip();
522*cdf0e10cSrcweir                     aStart++;
523*cdf0e10cSrcweir                     *aEnd-- = aTemp;
524*cdf0e10cSrcweir                 }
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir                 // also flip vectors of middle point (if existing)
527*cdf0e10cSrcweir                 if(maPoints.size() % 2)
528*cdf0e10cSrcweir                 {
529*cdf0e10cSrcweir                     (*mpVectors)[nHalfSize].doInvertForFlip();
530*cdf0e10cSrcweir                 }
531*cdf0e10cSrcweir             }
532*cdf0e10cSrcweir         }
533*cdf0e10cSrcweir     }
534*cdf0e10cSrcweir };
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir #endif _POLYGON_POINT_HXX
539