xref: /AOO41X/main/basegfx/inc/basegfx/polygon/b2dlinegeometry.hxx (revision 6da5f31158a7dd09f46f041b4f15bb7ae3eb92a4)
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_B2DLINEGEOMETRY_HXX
25 #define _BGFX_POLYGON_B2DLINEGEOMETRY_HXX
26 
27 #include <sal/types.h>
28 #include <basegfx/numeric/ftools.hxx>
29 #include <basegfx/polygon/b2dpolypolygon.hxx>
30 #include <basegfx/polygon/b2dpolygon.hxx>
31 
32 //////////////////////////////////////////////////////////////////////////////
33 
34 namespace basegfx
35 {
36 	namespace tools
37 	{
38 		/** Create line start/end geometry element, mostly arrows and things like that.
39 
40             @param rCandidate
41             The polygon which needs to get that line ends and needs to have two points
42             at least.
43 
44 		    @param rArrow
45             The line start/end geometry. It is assumed that the tip is pointing
46 		    upwards. Result will be rotated and scaled to fit.
47 
48             @param bStart
49             describes if creation is for start or end of candidate.
50 
51 		    @param fWidth
52             defines the size of the element, it's describing the target width in X
53 		    of the arrow.
54 
55             @param fDockingPosition needs to be in [0.0 ..1.0] range, where 0.0 means
56             that the tip of the arrow will be aligned with the polygon start, 1.0 means
57             the bottom. The default of 0.5 describes a centered arrow.
58 
59             @param pConsumedLength
60             Using this parameter it is possible to get back how much from the candidate
61 		    geometry is overlapped by the created element (consumed).
62 
63             @param fCandidateLength
64             This should contain the length of rCandidate to allow work without
65 		    again calculating the length (which may be expensive with beziers). If 0.0 is
66 		    given, the length is calculated on demand.
67 
68             @return
69             The Line start and end polygon, correctly rotated and scaled
70         */
71 		B2DPolyPolygon createAreaGeometryForLineStartEnd(
72 			const B2DPolygon& rCandidate,
73 			const B2DPolyPolygon& rArrow,
74 			bool bStart,
75 			double fWidth,
76 			double fCandidateLength = 0.0, // 0.0 -> calculate self
77 			double fDockingPosition = 0.5, // 0->top, 1->bottom
78 			double* pConsumedLength = 0L);
79 
80         /** create filled polygon geometry for lines with a line width
81 
82             This method will create bezier based, fillable polygons which
83             will resample the curve if it was extended for the given half
84             line width. It will remove extrema positions from contained
85             bezier segments and get as close as possible and defined by
86             the given parameters to the ideal result.
87 
88             It will check edges for trivial bezier to avoid unnecessary
89             bezier polygons. Care is taken to produce the in-between
90             polygon points (the ones original on the source poygon) since
91             it has showed that without those, the raster converters leave
92             non-filled gaps.
93 
94             @param rCandidate
95             The source polygon defining the hairline polygon path
96 
97             @param fHalfLineWidth
98             The width of the line to one side
99 
100             @param eJoin
101             The LineJoin if the edges meeting in a point do not have a C1
102             or C2 continuity
103 
104             @param fMaxAllowedAngle
105             Allows to hand over the maximum allowed angle between an edge and
106             it's control vectors. The smaller, the more subdivisions will be
107             needed to create the filled geometry. Allowed range is cropped to
108             [F_PI2 .. 0.01 * F_PI2].
109 
110             @param fMaxPartOfEdge
111             Allows to influence from with relative length of a control vector
112             compared to it's edge a split is forced. The smaller, the more
113             subdivisions will be needed to create the filled geometry. Allowed
114             range is cropped to [1.0 .. 0.01]
115 
116             @praram fMiterMinimumAngle
117             The minimum wanted angle between two edges when edge rounding
118             is using miter. When an edge is smaller than this (tighter)
119             the usual fallback to bevel is used. Allowed range is cropped
120             to [F_PI .. 0.01 * F_PI].
121 
122             @return
123             The PolyPolygon containing the geometry of the extended line by
124             it's line width. Contains bezier segments and edge roundings as
125             needed and defined.
126         */
127         B2DPolyPolygon createAreaGeometry(
128             const B2DPolygon& rCandidate,
129             double fHalfLineWidth,
130             B2DLineJoin eJoin = B2DLINEJOIN_ROUND,
131             double fMaxAllowedAngle = (12.5 * F_PI180),
132 			double fMaxPartOfEdge = 0.4,
133             double fMiterMinimumAngle = (15.0 * F_PI180));
134 	} // end of namespace tools
135 } // end of namespace basegfx
136 
137 //////////////////////////////////////////////////////////////////////////////
138 
139 #endif /* _BGFX_POLYGON_B2DLINEGEOMETRY_HXX */
140 // eof
141