1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _BGFX_POLYGON_B2DPOLYGONTOOLS_HXX
25 #define _BGFX_POLYGON_B2DPOLYGONTOOLS_HXX
26 
27 #include <basegfx/point/b2dpoint.hxx>
28 #include <basegfx/vector/b2dvector.hxx>
29 #include <basegfx/range/b2drectangle.hxx>
30 #include <basegfx/polygon/b2dpolypolygon.hxx>
31 #include <basegfx/polygon/b3dpolygon.hxx>
32 #include <com/sun/star/drawing/PointSequence.hpp>
33 #include <com/sun/star/drawing/FlagSequence.hpp>
34 #include <vector>
35 #include <basegfx/basegfxdllapi.h>
36 
37 //////////////////////////////////////////////////////////////////////////////
38 
39 namespace basegfx
40 {
41 	// predefinitions
42 	class B2DPolygon;
43 	class B2DRange;
44 
45 	namespace tools
46 	{
47 		// B2DPolygon tools
48 
49 		// open/close with point add/remove and control point corrections
50 		BASEGFX_DLLPUBLIC void openWithGeometryChange(B2DPolygon& rCandidate);
51 		BASEGFX_DLLPUBLIC void closeWithGeometryChange(B2DPolygon& rCandidate);
52 
53 		/**	Check if given polygon is closed.
54 
55         	This is kind of a 'classic' method to support old polygon
56         	definitions.  Those old polygon definitions define the
57         	closed state of the polygon using identical start and
58         	endpoints. This method corrects this (removes double
59         	start/end points) and sets the Closed()-state of the
60         	polygon correctly.
61 		*/
62 		BASEGFX_DLLPUBLIC void checkClosed(B2DPolygon& rCandidate);
63 
64 		// Get successor and predecessor indices. Returning the same index means there
65 		// is none. Same for successor.
66 		BASEGFX_DLLPUBLIC sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const B2DPolygon& rCandidate);
67 		BASEGFX_DLLPUBLIC sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const B2DPolygon& rCandidate);
68 
69 		// Get orientation of Polygon
70 		BASEGFX_DLLPUBLIC B2VectorOrientation getOrientation(const B2DPolygon& rCandidate);
71 
72 		// isInside tests for B2dPoint and other B2dPolygon. On border is not inside as long as
73 		// not true is given in bWithBorder flag.
74 		BASEGFX_DLLPUBLIC bool isInside(const B2DPolygon& rCandidate, const B2DPoint& rPoint, bool bWithBorder = false);
75 		BASEGFX_DLLPUBLIC bool isInside(const B2DPolygon& rCandidate, const B2DPolygon& rPolygon, bool bWithBorder = false);
76 
77 		/** Get the range of a polygon including bezier control points
78 
79 			For detailed discussion, see B2DPolygon::getB2DRange()
80 
81 			@param rCandidate
82 			The B2DPolygon eventually containing bezier segments
83 
84 			@return
85 			The outer range of the bezier curve containing bezier control points
86 		*/
87 		BASEGFX_DLLPUBLIC B2DRange getRangeWithControlPoints(const B2DPolygon& rCandidate);
88 
89 		/** Get the range of a polygon
90 
91 			This method creates the outer range of the subdivided bezier curve.
92             For detailed discussion see B2DPolygon::getB2DRange()
93 
94             @param rCandidate
95 			The B2DPolygon eventually containing bezier segments
96 
97 			@return
98 			The outer range of the bezier curve
99 		*/
100 		BASEGFX_DLLPUBLIC B2DRange getRange(const B2DPolygon& rCandidate);
101 
102 		// get signed area of polygon
103 		BASEGFX_DLLPUBLIC double getSignedArea(const B2DPolygon& rCandidate);
104 
105 		// get area of polygon
106 		BASEGFX_DLLPUBLIC double getArea(const B2DPolygon& rCandidate);
107 
108 		/** get length of polygon edge from point nIndex to nIndex + 1 */
109 		BASEGFX_DLLPUBLIC double getEdgeLength(const B2DPolygon& rCandidate, sal_uInt32 nIndex);
110 
111 		/** get length of polygon */
112 		BASEGFX_DLLPUBLIC double getLength(const B2DPolygon& rCandidate);
113 
114 		// get position on polygon for absolute given distance. If
115 		// length is given, it is assumed the correct polygon length, if 0.0 it is calculated
116 		// using getLength(...)
117 		BASEGFX_DLLPUBLIC B2DPoint getPositionAbsolute(const B2DPolygon& rCandidate, double fDistance, double fLength = 0.0);
118 
119 		// get position on polygon for relative given distance in range [0.0 .. 1.0]. If
120 		// length is given, it is assumed the correct polygon length, if 0.0 it is calculated
121 		// using getLength(...)
122 		BASEGFX_DLLPUBLIC B2DPoint getPositionRelative(const B2DPolygon& rCandidate, double fDistance, double fLength = 0.0);
123 
124 		// get a snippet from given polygon for absolute distances. The polygon is assumed
125 		// to be opened (not closed). fFrom and fTo need to be in range [0.0 .. fLength], where
126 		// fTo >= fFrom. If length is given, it is assumed the correct polygon length,
127 		// if 0.0 it is calculated using getLength(...)
128 		BASEGFX_DLLPUBLIC B2DPolygon getSnippetAbsolute(const B2DPolygon& rCandidate, double fFrom, double fTo, double fLength = 0.0);
129 
130 		// get a snippet from given polygon for relative distances. The polygon is assumed
131 		// to be opened (not closed). fFrom and fTo need to be in range [0.0 .. 1.0], where
132 		// fTo >= fFrom. If length is given, it is assumed the correct polygon length,
133 		// if 0.0 it is calculated using getLength(...)
134 		BASEGFX_DLLPUBLIC B2DPolygon getSnippetRelative(const B2DPolygon& rCandidate, double fFrom = 0.0, double fTo = 1.0, double fLength = 0.0);
135 
136 		// Continuity check for point with given index
137 		BASEGFX_DLLPUBLIC B2VectorContinuity getContinuityInPoint(const B2DPolygon& rCandidate, sal_uInt32 nIndex);
138 
139 		// Subdivide all contained curves. Use distanceBound value if given.
140 		BASEGFX_DLLPUBLIC B2DPolygon adaptiveSubdivideByDistance(const B2DPolygon& rCandidate, double fDistanceBound = 0.0);
141 
142 		// Subdivide all contained curves. Use angleBound value if given.
143 		BASEGFX_DLLPUBLIC B2DPolygon adaptiveSubdivideByAngle(const B2DPolygon& rCandidate, double fAngleBound = 0.0);
144 
145 		// #i37443# Subdivide all contained curves.
146 		BASEGFX_DLLPUBLIC B2DPolygon adaptiveSubdivideByCount(const B2DPolygon& rCandidate, sal_uInt32 nCount = 0L);
147 
148         // Definitions for the cut flags used from the findCut methods
149 		typedef sal_uInt16 CutFlagValue;
150 
151 		#define	CUTFLAG_NONE			(0x0000)
152 		#define	CUTFLAG_LINE			(0x0001)
153 		#define	CUTFLAG_START1			(0x0002)
154 		#define	CUTFLAG_START2			(0x0004)
155 		#define	CUTFLAG_END1			(0x0008)
156 		#define	CUTFLAG_END2			(0x0010)
157 		#define	CUTFLAG_ALL			(CUTFLAG_LINE|CUTFLAG_START1|CUTFLAG_START2|CUTFLAG_END1|CUTFLAG_END2)
158 		#define	CUTFLAG_DEFAULT		(CUTFLAG_LINE|CUTFLAG_START2|CUTFLAG_END2)
159 
160 		// Calculate cut between the points given by the two indices. pCut1
161 		// and pCut2 will contain the cut coordinate on each edge in ]0.0, 1.0]
162 		// (if given) and the return value will contain a cut description.
163 		BASEGFX_DLLPUBLIC CutFlagValue findCut(
164 			const B2DPolygon& rCandidate,
165 			sal_uInt32 nIndex1, sal_uInt32 nIndex2,
166 			CutFlagValue aCutFlags = CUTFLAG_DEFAULT,
167 			double* pCut1 = 0L, double* pCut2 = 0L);
168 
169 		// This version is working with two indexed edges from different
170 		// polygons.
171 		BASEGFX_DLLPUBLIC CutFlagValue findCut(
172 			const B2DPolygon& rCandidate1, sal_uInt32 nIndex1,
173 			const B2DPolygon& rCandidate2, sal_uInt32 nIndex2,
174 			CutFlagValue aCutFlags = CUTFLAG_DEFAULT,
175 			double* pCut1 = 0L, double* pCut2 = 0L);
176 
177 		// This version works with two points and vectors to define the
178 		// edges for the cut test.
179 		BASEGFX_DLLPUBLIC CutFlagValue findCut(
180 			const B2DPoint& rEdge1Start, const B2DVector& rEdge1Delta,
181 			const B2DPoint& rEdge2Start, const B2DVector& rEdge2Delta,
182 			CutFlagValue aCutFlags = CUTFLAG_DEFAULT,
183 			double* pCut1 = 0L, double* pCut2 = 0L);
184 
185 		// test if point is on the given edge in range ]0.0..1.0[ without
186 		// the start/end points. If so, return true and put the parameter
187 		// value in pCut (if provided)
188 		BASEGFX_DLLPUBLIC bool isPointOnEdge(
189 			const B2DPoint& rPoint,
190 			const B2DPoint& rEdgeStart,
191 			const B2DVector& rEdgeDelta,
192 			double* pCut = 0L);
193 
194 		/** Apply given LineDashing to given polygon
195 
196 			This method is used to cut down line polygons to the needed
197 			pieces when a dashing needs to be applied.
198 			It is now capable of keeping contained bezier segments.
199 			It is also capable of delivering line and non-line portions
200 			depending on what target polygons You provide. This is useful
201 			e.g. for dashed lines with two colors.
202 			If the last and the first snippet in one of the results have
203 			a common start/end ppoint, they will be merged to achieve as
204 			view as needed result line snippets. This is also relevant for
205 			further processing the results.
206 
207 			@param rCandidate
208 			The polygon based on which the snippets will be created.
209 
210 			@param rDotDashArray
211 			The line pattern given as array of length values
212 
213 			@param pLineTarget
214 			The target for line snippets, e.g. the first entry will be
215 			a line segment with length rDotDashArray[0]. The given
216 			polygon will be emptied as preparation.
217 
218 			@param pGapTarget
219 			The target for gap snippets, e.g. the first entry will be
220 			a line segment with length rDotDashArray[1]. The given
221 			polygon will be emptied as preparation.
222 
223 			@param fFullDashDotLen
224 			The sumed-up length of the rDotDashArray. If zero, it will
225 			be calculated internally.
226 		*/
227 		BASEGFX_DLLPUBLIC void applyLineDashing(
228 			const B2DPolygon& rCandidate,
229 			const ::std::vector<double>& rDotDashArray,
230 			B2DPolyPolygon* pLineTarget,
231 			B2DPolyPolygon* pGapTarget = 0,
232 			double fFullDashDotLen = 0.0);
233 
234 		// test if point is inside epsilon-range around an edge defined
235 		// by the two given points. Can be used for HitTesting. The epsilon-range
236 		// is defined to be the rectangle centered to the given edge, using height
237 		// 2 x fDistance, and the circle around both points with radius fDistance.
238 		BASEGFX_DLLPUBLIC bool isInEpsilonRange(const B2DPoint& rEdgeStart, const B2DPoint& rEdgeEnd, const B2DPoint& rTestPosition, double fDistance);
239 
240 		// test if point is inside epsilon-range around the given Polygon. Can be used
241 		// for HitTesting. The epsilon-range is defined to be the rectangle centered
242         // to the given edge, using height 2 x fDistance, and the circle around both points
243         // with radius fDistance.
244 		BASEGFX_DLLPUBLIC bool isInEpsilonRange(const B2DPolygon& rCandidate, const B2DPoint& rTestPosition, double fDistance);
245 
246         /** Create a polygon from a rectangle.
247 
248 			@param rRect
249             The rectangle which describes the polygon size
250 
251 			@param fRadius
252             Radius of the edge rounding, relative to the rectangle size. 0.0 means no
253 			rounding, 1.0 will lead to an ellipse
254          */
255         BASEGFX_DLLPUBLIC B2DPolygon createPolygonFromRect( const B2DRectangle& rRect, double fRadius );
256 
257         /** Create a polygon from a rectangle.
258 
259 			@param rRect
260             The rectangle which describes the polygon size
261 
262 			@param fRadiusX
263 			@param fRadiusY
264             Radius of the edge rounding, relative to the rectangle size. 0.0 means no
265 			rounding, 1.0 will lead to an ellipse
266          */
267 		BASEGFX_DLLPUBLIC B2DPolygon createPolygonFromRect( const B2DRectangle& rRect, double fRadiusX, double fRadiusY );
268 
269         /** Create a polygon from a rectangle.
270          */
271 		BASEGFX_DLLPUBLIC B2DPolygon createPolygonFromRect( const B2DRectangle& rRect );
272 
273         /** Create the unit polygon
274          */
275 		BASEGFX_DLLPUBLIC B2DPolygon createUnitPolygon();
276 
277         /** Create a circle polygon with given radius.
278 
279         	This method creates a circle approximation consisting of
280         	four cubic bezier segments, which approximate the given
281         	circle with an error of less than 0.5 percent.
282 
283         	@param rCenter
284             Center point of the circle
285 
286             @param fRadius
287             Radius of the circle
288          */
289         BASEGFX_DLLPUBLIC B2DPolygon createPolygonFromCircle( const B2DPoint& rCenter, double fRadius );
290 
291         /// create half circle centered on (0,0) from [0 .. F_PI]
292         B2DPolygon createHalfUnitCircle();
293 
294 		/** create a polygon which describes the unit circle and close it
295 
296 			@param nStartQuadrant
297 			To be able to rebuild the old behaviour where the circles started at bottom,
298 			this parameter is used. Default is 0 which is the first quadrant and the
299 			polygon's start point will be the rightmost one. When using e.g. 1, the
300 			first created quadrant will start at the YMax-position (with Y down on screens,
301 			this is the lowest one). This is needed since when lines are dashed, toe old
302 			geometry started at bottom point, else it would look different.
303 		 */
304         BASEGFX_DLLPUBLIC B2DPolygon createPolygonFromUnitCircle(sal_uInt32 nStartQuadrant = 0);
305 
306 		/** Create an ellipse polygon with given radii.
307 
308         	This method creates an ellipse approximation consisting of
309         	four cubic bezier segments, which approximate the given
310         	ellipse with an error of less than 0.5 percent.
311 
312         	@param rCenter
313             Center point of the circle
314 
315             @param fRadiusX
316             Radius of the ellipse in X direction
317 
318             @param fRadiusY
319             Radius of the ellipse in Y direction
320          */
321         BASEGFX_DLLPUBLIC B2DPolygon createPolygonFromEllipse( const B2DPoint& rCenter, double fRadiusX, double fRadiusY );
322 
323 		/** Create an unit ellipse polygon with the given angles, from start to end
324          */
325         BASEGFX_DLLPUBLIC B2DPolygon createPolygonFromEllipseSegment( const B2DPoint& rCenter, double fRadiusX, double fRadiusY, double	fStart, double fEnd );
326 
327         BASEGFX_DLLPUBLIC B2DPolygon createPolygonFromUnitEllipseSegment( double fStart, double fEnd );
328 
329         /** Predicate whether a given polygon is a rectangle.
330 
331         	@param rPoly
332             Polygon to check
333 
334             @return true, if the polygon describes a rectangle
335             (polygon is closed, and the points are either cw or ccw
336             enumerations of a rectangle's vertices). Note that
337             intermediate points and duplicate points are ignored.
338          */
339         BASEGFX_DLLPUBLIC bool isRectangle( const B2DPolygon& rPoly );
340 
341 		// create 3d polygon from given 2d polygon. The given fZCoordinate is used to expand the
342 		// third coordinate.
343 		BASEGFX_DLLPUBLIC B3DPolygon createB3DPolygonFromB2DPolygon(const B2DPolygon& rCandidate, double fZCoordinate = 0.0);
344 
345 		// create 2d PolyPolygon from given 3d PolyPolygon. All coordinates are transformed using the given
346 		// matrix and the resulting x,y is used to form the new polygon.
347 		BASEGFX_DLLPUBLIC B2DPolygon createB2DPolygonFromB3DPolygon(const B3DPolygon& rCandidate, const B3DHomMatrix& rMat);
348 
349 		// create simplified version of the original polygon by
350 		// replacing segments with spikes/loops and self intersections
351 		// by several trivial sub-segments
352 		BASEGFX_DLLPUBLIC B2DPolygon createSimplifiedPolygon(const B2DPolygon&);
353 
354 		// calculate the distance to the given endless ray and return. The relative position on the edge is returned in Cut.
355         // That position may be less than 0.0 or more than 1.0
356 		BASEGFX_DLLPUBLIC double getDistancePointToEndlessRay(const B2DPoint& rPointA, const B2DPoint& rPointB, const B2DPoint& rTestPoint, double& rCut);
357 
358 		// calculate the smallest distance to given edge and return. The relative position on the edge is returned in Cut.
359         // That position is in the range [0.0 .. 1.0] and the returned distance is adapted accordingly to the start or end
360         // point of the edge
361 		BASEGFX_DLLPUBLIC double getSmallestDistancePointToEdge(const B2DPoint& rPointA, const B2DPoint& rPointB, const B2DPoint& rTestPoint, double& rCut);
362 
363 		// for each contained edge calculate the smallest distance. Return the index to the smallest
364 		// edge in rEdgeIndex. The relative position on the edge is returned in rCut.
365 		// If nothing was found (e.g. empty input plygon), DBL_MAX is returned.
366 		BASEGFX_DLLPUBLIC double getSmallestDistancePointToPolygon(const B2DPolygon& rCandidate, const B2DPoint& rTestPoint, sal_uInt32& rEdgeIndex, double& rCut);
367 
368 		// distort single point. rOriginal describes the original range, where the given points describe the distorted corresponding points.
369 		BASEGFX_DLLPUBLIC B2DPoint distort(const B2DPoint& rCandidate, const B2DRange& rOriginal, const B2DPoint& rTopLeft, const B2DPoint& rTopRight, const B2DPoint& rBottomLeft, const B2DPoint& rBottomRight);
370 
371 		// distort polygon. rOriginal describes the original range, where the given points describe the distorted corresponding points.
372 		BASEGFX_DLLPUBLIC B2DPolygon distort(const B2DPolygon& rCandidate, const B2DRange& rOriginal, const B2DPoint& rTopLeft, const B2DPoint& rTopRight, const B2DPoint& rBottomLeft, const B2DPoint& rBottomRight);
373 
374 		// rotate polygon around given point with given angle.
375 		BASEGFX_DLLPUBLIC B2DPolygon rotateAroundPoint(const B2DPolygon& rCandidate, const B2DPoint& rCenter, double fAngle);
376 
377 		// expand all segments (which are not yet) to curve segments. This is done with setting the control
378 		// vectors on the 1/3 resp. 2/3 distances on each segment.
379 		BASEGFX_DLLPUBLIC B2DPolygon expandToCurve(const B2DPolygon& rCandidate);
380 
381 		// expand given segment to curve segment. This is done with setting the control
382 		// vectors on the 1/3 resp. 2/3 distances. The return value describes if a change took place.
383 		BASEGFX_DLLPUBLIC bool expandToCurveInPoint(B2DPolygon& rCandidate, sal_uInt32 nIndex);
384 
385 		// set continuity for the whole curve. If not a curve, nothing will change. Non-curve points are not changed, too.
386 		BASEGFX_DLLPUBLIC B2DPolygon setContinuity(const B2DPolygon& rCandidate, B2VectorContinuity eContinuity);
387 
388 		// set continuity for given index. If not a curve, nothing will change. Non-curve points are not changed, too.
389 		// The return value describes if a change took place.
390 		BASEGFX_DLLPUBLIC bool setContinuityInPoint(B2DPolygon& rCandidate, sal_uInt32 nIndex, B2VectorContinuity eContinuity);
391 
392 		// test if polygon contains neutral points. A neutral point is one whos orientation is neutral
393 		// e.g. positioned on the edge of it's predecessor and successor
394 		BASEGFX_DLLPUBLIC bool hasNeutralPoints(const B2DPolygon& rCandidate);
395 
396 		// remove neutral points. A neutral point is one whos orientation is neutral
397 		// e.g. positioned on the edge of it's predecessor and successor
398 		BASEGFX_DLLPUBLIC B2DPolygon removeNeutralPoints(const B2DPolygon& rCandidate);
399 
400 		// tests if polygon is convex
401 		BASEGFX_DLLPUBLIC bool isConvex(const B2DPolygon& rCandidate);
402 
403 		// calculates the orientation at edge nIndex
404 		BASEGFX_DLLPUBLIC B2VectorOrientation getOrientationForIndex(const B2DPolygon& rCandidate, sal_uInt32 nIndex);
405 
406 		// calculates if given point is on given line, taking care of the numerical epsilon
407 		BASEGFX_DLLPUBLIC bool isPointOnLine(const B2DPoint& rStart, const B2DPoint& rEnd, const B2DPoint& rCandidate, bool bWithPoints = false);
408 
409 		// calculates if given point is on given polygon, taking care of the numerical epsilon. Uses
410 		// isPointOnLine internally
411 		BASEGFX_DLLPUBLIC bool isPointOnPolygon(const B2DPolygon& rCandidate, const B2DPoint& rPoint, bool bWithPoints = true);
412 
413 		// test if candidate is inside triangle
414 		BASEGFX_DLLPUBLIC bool isPointInTriangle(const B2DPoint& rA, const B2DPoint& rB, const B2DPoint& rC, const B2DPoint& rCandidate, bool bWithBorder = false);
415 
416 		// test if candidateA and candidateB are on the same side of the given line
417 		BASEGFX_DLLPUBLIC bool arePointsOnSameSideOfLine(const B2DPoint& rStart, const B2DPoint& rEnd, const B2DPoint& rCandidateA, const B2DPoint& rCandidateB, bool bWithLine = false);
418 
419 		// add triangles for given rCandidate to rTarget. For each triangle, 3 points will be added to rCandidate.
420 		// All triangles will go from the start point of rCandidate to two consecutive points, building (rCandidate.count() - 2)
421 		// triangles.
422 		BASEGFX_DLLPUBLIC void addTriangleFan(const B2DPolygon& rCandidate, B2DPolygon& rTarget);
423 
424 		// grow for polygon. Move all geometry in each point in the direction of the normal in that point
425 		// with the given amount. Value may be negative.
426 		BASEGFX_DLLPUBLIC B2DPolygon growInNormalDirection(const B2DPolygon& rCandidate, double fValue);
427 
428 		// force all sub-polygons to a point count of nSegments
429 		BASEGFX_DLLPUBLIC B2DPolygon reSegmentPolygon(const B2DPolygon& rCandidate, sal_uInt32 nSegments);
430 
431 		// create polygon state at t from 0.0 to 1.0 between the two polygons. Both polygons must have the same
432 		// organisation, e.g. same amount of points
433 		BASEGFX_DLLPUBLIC B2DPolygon interpolate(const B2DPolygon& rOld1, const B2DPolygon& rOld2, double t);
434 
435 		BASEGFX_DLLPUBLIC bool isPolyPolygonEqualRectangle( const B2DPolyPolygon& rPolyPoly, const B2DRange& rRect );
436 
437 		// #i76891# Try to remove existing curve segments if they are simply edges
438 		BASEGFX_DLLPUBLIC B2DPolygon simplifyCurveSegments(const B2DPolygon& rCandidate);
439 
440 		// makes the given indexed point the new polygon start point. To do that, the points in the
441 		// polygon will be rotated. This is only valid for closed polygons, for non-closed ones
442 		// an assertion will be triggered
443 		BASEGFX_DLLPUBLIC B2DPolygon makeStartPoint(const B2DPolygon& rCandidate, sal_uInt32 nIndexOfNewStatPoint);
444 
445         /** create edges of given length along given B2DPolygon
446 
447         	@param rCandidate
448             The polygon to move along. Points at the given polygon are created, starting
449 			at position fStart and stopping at less or equal to fEnd. The closed state is
450 			preserved.
451 			The polygon is subdivided if curve segments are included. That subdivision is the base
452 			for the newly created points.
453 			If the source is closed, the indirectly existing last edge may NOT have the
454 			given length.
455 			If the source is open, all edges will have the given length. You may use the last
456 			point of the original when You want to add the last edge Yourself.
457 
458             @param fLength
459             The length of the created edges. If less or equal zero, an empty polygon is returned.
460 
461             @param fStart
462             The start distance for the first to be generated point. Use 0.0 to get the
463 			original start point. Negative values are truncated to 0.0.
464 
465             @param fEnd
466             The maximum distance for the last point. No more points behind this distance will be created.
467 			Use 0.0 to process the whole polygon. Negative values are truncated to 0.0. It also
468 			needs to be more or equal to fStart, else it is truncated to fStart.
469 
470 			@return
471 			The newly created polygon
472          */
473 		BASEGFX_DLLPUBLIC B2DPolygon createEdgesOfGivenLength(const B2DPolygon& rCandidate, double fLength, double fStart = 0.0, double fEnd = 0.0);
474 
475 		/** Create Waveline along given polygon
476             The implementation is based on createEdgesOfGivenLength and creates a curve
477             segment with the given dimensions for each created line segment. The polygon
478             is treated as if opened (closed state will be ignored) and only for whole
479             edges a curve segment will be created (no rest handling)
480 
481             @param rCandidate
482             The polygon along which the waveline will be created
483 
484             @param fWaveWidth
485             The length of a single waveline curve segment
486 
487             @param fgWaveHeight
488             The height of the waveline (amplitude)
489         */
490 		BASEGFX_DLLPUBLIC B2DPolygon createWaveline(const B2DPolygon& rCandidate, double fWaveWidth, double fWaveHeight);
491 
492         /** split each edge of a polygon in exactly nSubEdges equidistant edges
493 
494             @param rCandidate
495             The source polygon. If too small (no edges), nSubEdges too small (<2)
496             or neither bHandleCurvedEdgesnor bHandleStraightEdges it will just be returned.
497             Else for each edge nSubEdges will be created. Closed state is preserved.
498 
499             @param nSubEdges
500             How many edges shall be created as replacement for each single edge
501 
502             @param bHandleCurvedEdges
503             Process curved edges or not. If to handle the curved edges will be splitted
504             into nSubEdges part curved edges of equidistant bezier distances. If not,
505             curved edges will just be copied.
506 
507             @param bHandleStraightEdges
508             Process straight edges or not. If to handle the straight edges will be splitted
509             into nSubEdges part curved edges of equidistant length. If not,
510             straight edges will just be copied.
511         */
512 		BASEGFX_DLLPUBLIC B2DPolygon reSegmentPolygonEdges(const B2DPolygon& rCandidate, sal_uInt32 nSubEdges, bool bHandleCurvedEdges, bool bHandleStraightEdges);
513 
514 		//////////////////////////////////////////////////////////////////////
515 		// comparators with tolerance for 2D Polygons
516 		BASEGFX_DLLPUBLIC bool equal(const B2DPolygon& rCandidateA, const B2DPolygon& rCandidateB, const double& rfSmallValue);
517 		BASEGFX_DLLPUBLIC bool equal(const B2DPolygon& rCandidateA, const B2DPolygon& rCandidateB);
518 
519 		/** snap some polygon coordinates to discrete coordinates
520 
521 			This method allows to snap some polygon points to discrete (integer) values
522 			which equals e.g. a snap to discrete coordinates. It will snap points of
523 			horizontal and vertical edges
524 
525 			@param rCandidate
526 			The source polygon
527 
528 			@return
529 			The modified version of the source polygon
530 		*/
531 		BASEGFX_DLLPUBLIC B2DPolygon snapPointsOfHorizontalOrVerticalEdges(const B2DPolygon& rCandidate);
532 
533         /** returns true if the Polygon only contains horizontal or vertical edges
534             so that it could be represented by RegionBands
535         */
536         BASEGFX_DLLPUBLIC bool containsOnlyHorizontalAndVerticalEdges(const B2DPolygon& rCandidate);
537 
538         /// get the tangent with which the given point is entered seen from the previous
539         /// polygon path data. Take into account all stuff like closed state, zero-length edges and others.
540         BASEGFX_DLLPUBLIC B2DVector getTangentEnteringPoint(const B2DPolygon& rCandidate, sal_uInt32 nIndex);
541 
542         /// get the tangent with which the given point is left seen from the following
543         /// polygon path data. Take into account all stuff like closed state, zero-length edges and others.
544         BASEGFX_DLLPUBLIC B2DVector getTangentLeavingPoint(const B2DPolygon& rCandidate, sal_uInt32 nIndex);
545 
546         /// converters for com::sun::star::drawing::PointSequence
547         BASEGFX_DLLPUBLIC B2DPolygon UnoPointSequenceToB2DPolygon(
548             const com::sun::star::drawing::PointSequence& rPointSequenceSource,
549             bool bCheckClosed = true);
550         BASEGFX_DLLPUBLIC void B2DPolygonToUnoPointSequence(
551             const B2DPolygon& rPolygon,
552             com::sun::star::drawing::PointSequence& rPointSequenceRetval);
553 
554         /* converters for com::sun::star::drawing::PointSequence and
555            com::sun::star::drawing::FlagSequence to B2DPolygon (curved polygons)
556          */
557         BASEGFX_DLLPUBLIC B2DPolygon UnoPolygonBezierCoordsToB2DPolygon(
558             const com::sun::star::drawing::PointSequence& rPointSequenceSource,
559             const com::sun::star::drawing::FlagSequence& rFlagSequenceSource,
560             bool bCheckClosed = true);
561         BASEGFX_DLLPUBLIC void B2DPolygonToUnoPolygonBezierCoords(
562             const B2DPolygon& rPolyPolygon,
563             com::sun::star::drawing::PointSequence& rPointSequenceRetval,
564             com::sun::star::drawing::FlagSequence& rFlagSequenceRetval);
565 
566         /** Read poly-polygon from SVG.
567 
568             This function imports a poly-polygon from an SVG points
569             attribute (a plain list of coordinate pairs).
570 
571             @param o_rPoly
572             The output polygon. Note that svg:points can only define a
573             single polygon
574 
575             @param rSvgPointsAttribute
576             A valid SVG points attribute string
577 
578             @return true, if the string was successfully parsed
579          */
580         BASEGFX_DLLPUBLIC bool importFromSvgPoints( B2DPolygon&            o_rPoly,
581                                   const ::rtl::OUString& rSvgPointsAttribute );
582 
583         /** Write poly-polygon to SVG.
584 
585             This function imports a non-bezier polygon to SVG points
586             (a plain list of coordinate pairs).
587 
588             @param rPoly
589             The polygon to export
590 
591             @param rSvgPointsAttribute
592             A valid SVG points attribute string
593 
594             @return true, if the string was successfully parsed
595          */
596         BASEGFX_DLLPUBLIC ::rtl::OUString exportToSvgPoints( const B2DPolygon& rPoly );
597 
598     } // end of namespace tools
599 } // end of namespace basegfx
600 
601 #endif /* _BGFX_POLYGON_B2DPOLYGONTOOLS_HXX */
602