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