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