xref: /aoo42x/main/basegfx/inc/basegfx/tools/tools.hxx (revision b63233d8)
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_TOOLS_TOOLS_HXX
25 #define _BGFX_TOOLS_TOOLS_HXX
26 
27 #include <sal/types.h>
28 #include <basegfx/basegfxdllapi.h>
29 
30 namespace basegfx
31 {
32     class B2DPoint;
33     class B2DRange;
34 
35     namespace tools
36     {
37         /** Liang-Barsky 2D line clipping algorithm
38 
39         	This function clips a line given by two points against the
40         	given rectangle. The resulting line is returned in the
41         	given points.
42 
43             @param io_rStart
44             Start point of the line. On return, contains the clipped
45             start point.
46 
47             @param io_rEnd
48             End point of the line. On return, contains the clipped
49             end point.
50 
51             @param rClipRect
52             The rectangle to clip against
53 
54             @return true, when at least part of the line is visible
55             after the clip, false otherwise
56          */
57         BASEGFX_DLLPUBLIC bool liangBarskyClip2D( ::basegfx::B2DPoint& 		io_rStart,
58                                 ::basegfx::B2DPoint& 		io_rEnd,
59                                 const ::basegfx::B2DRange&	rClipRect );
60 
61         /** Expand given parallelogram, such that it extends beyond
62             bound rect in a given direction.
63 
64             This method is useful when e.g. generating one-dimensional
65             gradients, such as linear or axial gradients: those
66             gradients vary only in one direction, the other has
67             constant color. Most of the time, those gradients extends
68             infinitely in the direction with the constant color, but
69             practically, one always has a limiting bound rect into
70             which the gradient is painted. The method at hand now
71             extends a given parallelogram (e.g. the transformed
72             bounding box of a gradient) virtually into infinity to the
73             top and to the bottom (i.e. normal to the line io_rLeftTop
74             io_rRightTop), such that the given rectangle is guaranteed
75             to be covered in that direction.
76 
77             @attention There might be some peculiarities with this
78             method, that might limit its usage to the described
79             gradients. One of them is the fact that when determining
80             how far the parallelogram has to be extended to the top or
81             the bottom, the upper and lower border are assumed to be
82             infinite lines.
83 
84             @param io_rLeftTop
85             Left, top edge of the parallelogramm. Note that this need
86             not be the left, top edge geometrically, it's just used
87             when determining the extension direction. Thus, it's
88             perfectly legal to affine-transform a rectangle, and given
89             the transformed point here. On method return, this
90             parameter will contain the adapted output.
91 
92             @param io_rLeftBottom
93             Left, bottom edge of the parallelogramm. Note that this need
94             not be the left, bottom edge geometrically, it's just used
95             when determining the extension direction. Thus, it's
96             perfectly legal to affine-transform a rectangle, and given
97             the transformed point here. On method return, this
98             parameter will contain the adapted output.
99 
100             @param io_rRightTop
101             Right, top edge of the parallelogramm. Note that this need
102             not be the right, top edge geometrically, it's just used
103             when determining the extension direction. Thus, it's
104             perfectly legal to affine-transform a rectangle, and given
105             the transformed point here. On method return, this
106             parameter will contain the adapted output.
107 
108             @param io_rRightBottom
109             Right, bottom edge of the parallelogramm. Note that this need
110             not be the right, bottom edge geometrically, it's just used
111             when determining the extension direction. Thus, it's
112             perfectly legal to affine-transform a rectangle, and given
113             the transformed point here. On method return, this
114             parameter will contain the adapted output.
115 
116             @param rFitTarget
117             The rectangle to fit the parallelogram into.
118          */
119         BASEGFX_DLLPUBLIC void infiniteLineFromParallelogram( ::basegfx::B2DPoint& 		io_rLeftTop,
120                                             ::basegfx::B2DPoint& 		io_rLeftBottom,
121                                             ::basegfx::B2DPoint& 		io_rRightTop,
122                                             ::basegfx::B2DPoint& 		io_rRightBottom,
123                                             const ::basegfx::B2DRange&	rFitTarget	);
124 
125     }
126 }
127 
128 #endif /* _BGFX_TOOLS_TOOLS_HXX */
129