1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _BGFX_POLYPOLYGON_B2DPOLYGONTOOLS_HXX
21 #define _BGFX_POLYPOLYGON_B2DPOLYGONTOOLS_HXX
23 #include <basegfx/point/b2dpoint.hxx>
24 #include <basegfx/vector/b2dvector.hxx>
25 #include <basegfx/polygon/b2dpolygon.hxx>
26 #include <basegfx/polygon/b3dpolypolygon.hxx>
28 #include <basegfx/basegfxdllapi.h>
31 //////////////////////////////////////////////////////////////////////////////
41 // B2DPolyPolygon tools
43 // Check and evtl. correct orientations of all contained Polygons so that
44 // the orientations of contained polygons will variate to express areas and
46 BASEGFX_DLLPUBLIC B2DPolyPolygon
correctOrientations(const B2DPolyPolygon
& rCandidate
);
48 // make sure polygon with index 0L is not a hole. This may evtl. change the
49 // sequence of polygons, but allows to use polygon with index 0L to
50 // get the correct normal for the whole polyPolygon
51 BASEGFX_DLLPUBLIC B2DPolyPolygon
correctOutmostPolygon(const B2DPolyPolygon
& rCandidate
);
53 // Subdivide all contained curves. Use distanceBound value if given.
54 BASEGFX_DLLPUBLIC B2DPolyPolygon
adaptiveSubdivideByDistance(const B2DPolyPolygon
& rCandidate
, double fDistanceBound
= 0.0);
56 // Subdivide all contained curves. Use distanceBound value if given. Else, a convenient one
58 BASEGFX_DLLPUBLIC B2DPolyPolygon
adaptiveSubdivideByAngle(const B2DPolyPolygon
& rCandidate
, double fAngleBound
= 0.0);
60 // Subdivide all contained curves. Use nCount divisions if given. Else, a convenient one
62 BASEGFX_DLLPUBLIC B2DPolyPolygon
adaptiveSubdivideByCount(const B2DPolyPolygon
& rCandidate
, sal_uInt32 nCount
= 0L);
64 // isInside test for B2dPoint. On border is not inside as long as not true is given
65 // in bWithBorder flag. It is assumed that the orientations of the given polygon are correct.
66 BASEGFX_DLLPUBLIC
bool isInside(const B2DPolyPolygon
& rCandidate
, const B2DPoint
& rPoint
, bool bWithBorder
= false);
68 /** Get the range of a polyPolygon
70 For detailed description look at getRange(const B2DPolygon&).
71 This method just expands by the range of every sub-Polygon.
74 The B2DPolyPolygon eventually containing bezier segments
77 The outer range of the polygon
79 BASEGFX_DLLPUBLIC B2DRange
getRange(const B2DPolyPolygon
& rCandidate
);
81 /** Apply given LineDashing to given polyPolygon
83 For a description see applyLineDashing in b2dpolygontoos.hxx
85 BASEGFX_DLLPUBLIC
void applyLineDashing(
86 const B2DPolyPolygon
& rCandidate
,
87 const ::std::vector
<double>& rDotDashArray
,
88 B2DPolyPolygon
* pLineTarget
,
89 B2DPolyPolygon
* pGapTarget
= 0,
90 double fFullDashDotLen
= 0.0);
92 // test if point is inside epsilon-range around the given PolyPolygon. Can be used
93 // for HitTesting. The epsilon-range is defined to be the tube around the PolyPolygon
94 // with distance fDistance and rounded edges (start and end point).
95 BASEGFX_DLLPUBLIC
bool isInEpsilonRange(const B2DPolyPolygon
& rCandidate
, const B2DPoint
& rTestPosition
, double fDistance
);
97 /** Read poly-polygon from SVG.
99 This function imports a poly-polygon from an SVG-D
103 The output poly-polygon
105 @param rSvgDAttribute
106 A valid SVG-D attribute string
108 @param rWrongPositionAfterZ
109 Indicates wheter the generator interprets wrongly
110 the position in the path after Z or z elements
111 https://bugs.freedesktop.org/show_bug.cgi?id=47406
113 @return true, if the string was successfully parsed
115 BASEGFX_DLLPUBLIC
bool importFromSvgD( B2DPolyPolygon
& o_rPolyPoly
,
116 const OUString
& rSvgDAttribute
, bool bWrongPositionAfterZ
= false );
118 /** Read poly-polygon from SVG.
120 This function imports a poly-polygon from an SVG points
121 attribute (a plain list of coordinate pairs).
124 The output polygon. Note that svg:points can only define a
127 @param rSvgPointsAttribute
128 A valid SVG points attribute string
130 @return true, if the string was successfully parsed
132 BASEGFX_DLLPUBLIC
bool importFromSvgPoints( B2DPolygon
& o_rPoly
,
133 const OUString
& rSvgPointsAttribute
);
136 // grow for polyPolygon. Move all geometry in each point in the direction of the normal in that point
137 // with the given amount. Value may be negative.
138 BASEGFX_DLLPUBLIC B2DPolyPolygon
growInNormalDirection(const B2DPolyPolygon
& rCandidate
, double fValue
);
140 // This method will correct a pair of polyPolygons where the goal is to keep same point count
141 // to allow direct point association and also to remove self-intersections produced by shrinks.
142 // This method will eventually change both polyPolygons to reach that goal because there are cases
143 // where it is necessary to add new cut points to the original
144 BASEGFX_DLLPUBLIC
void correctGrowShrinkPolygonPair(B2DPolyPolygon
& rOriginal
, B2DPolyPolygon
& rGrown
);
146 // force all sub-polygons to a point count of nSegments
147 BASEGFX_DLLPUBLIC B2DPolyPolygon
reSegmentPolyPolygon(const B2DPolyPolygon
& rCandidate
, sal_uInt32 nSegments
);
149 // create polygon state at t from 0.0 to 1.0 between the two polygons. Both polygons must have the same
150 // organisation, e.g. same amount of polygons
151 BASEGFX_DLLPUBLIC B2DPolyPolygon
interpolate(const B2DPolyPolygon
& rOld1
, const B2DPolyPolygon
& rOld2
, double t
);
153 // create 3d PolyPolygon from given 2d PolyPolygon. The given fZCoordinate is used to expand the
155 BASEGFX_DLLPUBLIC B3DPolyPolygon
createB3DPolyPolygonFromB2DPolyPolygon(const B2DPolyPolygon
& rCandidate
, double fZCoordinate
= 0.0);
157 // create 2d PolyPolygon from given 3d PolyPolygon. All coordinates are transformed using the given
158 // matrix and the resulting x,y is used to form the new polygon.
159 BASEGFX_DLLPUBLIC B2DPolyPolygon
createB2DPolyPolygonFromB3DPolyPolygon(const B3DPolyPolygon
& rCandidate
, const B3DHomMatrix
& rMat
);
161 // for each contained edge in each contained polygon calculate the smallest distance. Return the index to the smallest
162 // edge in rEdgeIndex and the index to the polygon in rPolygonIndex. The relative position on the edge is returned in rCut.
163 // If nothing was found (e.g. empty input plygon), DBL_MAX is returned.
164 BASEGFX_DLLPUBLIC
double getSmallestDistancePointToPolyPolygon(const B2DPolyPolygon
& rCandidate
, const B2DPoint
& rTestPoint
, sal_uInt32
& rPolygonIndex
, sal_uInt32
& rEdgeIndex
, double& rCut
);
166 // distort PolyPolygon. rOriginal describes the original range, where the given points describe the distorted
167 // corresponding points.
168 BASEGFX_DLLPUBLIC B2DPolyPolygon
distort(const B2DPolyPolygon
& rCandidate
, const B2DRange
& rOriginal
, const B2DPoint
& rTopLeft
, const B2DPoint
& rTopRight
, const B2DPoint
& rBottomLeft
, const B2DPoint
& rBottomRight
);
170 // expand all segments (which are not yet) to curve segments. This is done with setting the control
171 // vectors on the 1/3 resp. 2/3 distances on each segment.
172 BASEGFX_DLLPUBLIC B2DPolyPolygon
expandToCurve(const B2DPolyPolygon
& rCandidate
);
174 /** Predicate whether a given poly-polygon is a rectangle.
179 @return true, if the poly-polygon describes a rectangle
180 (contains exactly one polygon, polygon is closed, and the
181 points are either cw or ccw enumerations of a rectangle's
182 vertices). Note that intermediate points and duplicate
185 BASEGFX_DLLPUBLIC
bool isRectangle( const B2DPolyPolygon
& rPoly
);
187 /** Export poly-polygon to SVG.
189 This function exports a poly-polygon into an SVG-D
190 statement. Currently, output of relative point sequences
191 is not yet supported (might cause slightly larger output)
194 The poly-polygon to export
196 @param bUseRelativeCoordinates
197 When true, all coordinate values are exported as relative
198 to the current position. This tends to save some space,
199 since fewer digits needs to be written.
201 @param bDetectQuadraticBeziers
202 When true, the export tries to detect cubic bezier
203 segments in the input polygon, which can be represented by
204 quadratic bezier segments. Note that the generated string
205 causes versions prior to OOo2.0 to crash.
207 @return the generated SVG-D statement (the XML d attribute
208 value alone, without any "<path ...>" or "d="...")
210 BASEGFX_DLLPUBLIC OUString
exportToSvgD( const B2DPolyPolygon
& rPolyPoly
,
211 bool bUseRelativeCoordinates
=true,
212 bool bDetectQuadraticBeziers
=true );
214 // #i76891# Try to remove existing curve segments if they are simply edges
215 BASEGFX_DLLPUBLIC B2DPolyPolygon
simplifyCurveSegments(const B2DPolyPolygon
& rCandidate
);
217 /** snap some polygon coordinates to discrete coordinates
219 This method allows to snap some polygon points to discrete (integer) values
220 which equals e.g. a snap to discrete coordinates. It will snap points of
221 horizontal and vertical edges
227 The modified version of the source polygon
229 BASEGFX_DLLPUBLIC B2DPolyPolygon
snapPointsOfHorizontalOrVerticalEdges(const B2DPolyPolygon
& rCandidate
);
231 } // end of namespace tools
232 } // end of namespace basegfx
234 #endif /* _BGFX_POLYPOLYGON_B2DPOLYGONTOOLS_HXX */
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */