1ce9c7ef7SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ce9c7ef7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ce9c7ef7SAndrew Rist * or more contributor license agreements. See the NOTICE file 5ce9c7ef7SAndrew Rist * distributed with this work for additional information 6ce9c7ef7SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ce9c7ef7SAndrew Rist * to you under the Apache License, Version 2.0 (the 8ce9c7ef7SAndrew Rist * "License"); you may not use this file except in compliance 9ce9c7ef7SAndrew Rist * with the License. You may obtain a copy of the License at 10ce9c7ef7SAndrew Rist * 11ce9c7ef7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ce9c7ef7SAndrew Rist * 13ce9c7ef7SAndrew Rist * Unless required by applicable law or agreed to in writing, 14ce9c7ef7SAndrew Rist * software distributed under the License is distributed on an 15ce9c7ef7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ce9c7ef7SAndrew Rist * KIND, either express or implied. See the License for the 17ce9c7ef7SAndrew Rist * specific language governing permissions and limitations 18ce9c7ef7SAndrew Rist * under the License. 19ce9c7ef7SAndrew Rist * 20ce9c7ef7SAndrew Rist *************************************************************/ 21ce9c7ef7SAndrew Rist 22ce9c7ef7SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _BGFX_TOOLS_TOOLS_HXX 25cdf0e10cSrcweir #define _BGFX_TOOLS_TOOLS_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <sal/types.h> 28*b63233d8Sdamjan #include <basegfx/basegfxdllapi.h> 29cdf0e10cSrcweir 30cdf0e10cSrcweir namespace basegfx 31cdf0e10cSrcweir { 32cdf0e10cSrcweir class B2DPoint; 33cdf0e10cSrcweir class B2DRange; 34cdf0e10cSrcweir 35cdf0e10cSrcweir namespace tools 36cdf0e10cSrcweir { 37cdf0e10cSrcweir /** Liang-Barsky 2D line clipping algorithm 38cdf0e10cSrcweir 39cdf0e10cSrcweir This function clips a line given by two points against the 40cdf0e10cSrcweir given rectangle. The resulting line is returned in the 41cdf0e10cSrcweir given points. 42cdf0e10cSrcweir 43cdf0e10cSrcweir @param io_rStart 44cdf0e10cSrcweir Start point of the line. On return, contains the clipped 45cdf0e10cSrcweir start point. 46cdf0e10cSrcweir 47cdf0e10cSrcweir @param io_rEnd 48cdf0e10cSrcweir End point of the line. On return, contains the clipped 49cdf0e10cSrcweir end point. 50cdf0e10cSrcweir 51cdf0e10cSrcweir @param rClipRect 52cdf0e10cSrcweir The rectangle to clip against 53cdf0e10cSrcweir 54cdf0e10cSrcweir @return true, when at least part of the line is visible 55cdf0e10cSrcweir after the clip, false otherwise 56cdf0e10cSrcweir */ 57*b63233d8Sdamjan BASEGFX_DLLPUBLIC bool liangBarskyClip2D( ::basegfx::B2DPoint& io_rStart, 58cdf0e10cSrcweir ::basegfx::B2DPoint& io_rEnd, 59cdf0e10cSrcweir const ::basegfx::B2DRange& rClipRect ); 60cdf0e10cSrcweir 61cdf0e10cSrcweir /** Expand given parallelogram, such that it extends beyond 62cdf0e10cSrcweir bound rect in a given direction. 63cdf0e10cSrcweir 64cdf0e10cSrcweir This method is useful when e.g. generating one-dimensional 65cdf0e10cSrcweir gradients, such as linear or axial gradients: those 66cdf0e10cSrcweir gradients vary only in one direction, the other has 67cdf0e10cSrcweir constant color. Most of the time, those gradients extends 68cdf0e10cSrcweir infinitely in the direction with the constant color, but 69cdf0e10cSrcweir practically, one always has a limiting bound rect into 70cdf0e10cSrcweir which the gradient is painted. The method at hand now 71cdf0e10cSrcweir extends a given parallelogram (e.g. the transformed 72cdf0e10cSrcweir bounding box of a gradient) virtually into infinity to the 73cdf0e10cSrcweir top and to the bottom (i.e. normal to the line io_rLeftTop 74cdf0e10cSrcweir io_rRightTop), such that the given rectangle is guaranteed 75cdf0e10cSrcweir to be covered in that direction. 76cdf0e10cSrcweir 77cdf0e10cSrcweir @attention There might be some peculiarities with this 78cdf0e10cSrcweir method, that might limit its usage to the described 79cdf0e10cSrcweir gradients. One of them is the fact that when determining 80cdf0e10cSrcweir how far the parallelogram has to be extended to the top or 81cdf0e10cSrcweir the bottom, the upper and lower border are assumed to be 82cdf0e10cSrcweir infinite lines. 83cdf0e10cSrcweir 84cdf0e10cSrcweir @param io_rLeftTop 85cdf0e10cSrcweir Left, top edge of the parallelogramm. Note that this need 86cdf0e10cSrcweir not be the left, top edge geometrically, it's just used 87cdf0e10cSrcweir when determining the extension direction. Thus, it's 88cdf0e10cSrcweir perfectly legal to affine-transform a rectangle, and given 89cdf0e10cSrcweir the transformed point here. On method return, this 90cdf0e10cSrcweir parameter will contain the adapted output. 91cdf0e10cSrcweir 92cdf0e10cSrcweir @param io_rLeftBottom 93cdf0e10cSrcweir Left, bottom edge of the parallelogramm. Note that this need 94cdf0e10cSrcweir not be the left, bottom edge geometrically, it's just used 95cdf0e10cSrcweir when determining the extension direction. Thus, it's 96cdf0e10cSrcweir perfectly legal to affine-transform a rectangle, and given 97cdf0e10cSrcweir the transformed point here. On method return, this 98cdf0e10cSrcweir parameter will contain the adapted output. 99cdf0e10cSrcweir 100cdf0e10cSrcweir @param io_rRightTop 101cdf0e10cSrcweir Right, top edge of the parallelogramm. Note that this need 102cdf0e10cSrcweir not be the right, top edge geometrically, it's just used 103cdf0e10cSrcweir when determining the extension direction. Thus, it's 104cdf0e10cSrcweir perfectly legal to affine-transform a rectangle, and given 105cdf0e10cSrcweir the transformed point here. On method return, this 106cdf0e10cSrcweir parameter will contain the adapted output. 107cdf0e10cSrcweir 108cdf0e10cSrcweir @param io_rRightBottom 109cdf0e10cSrcweir Right, bottom edge of the parallelogramm. Note that this need 110cdf0e10cSrcweir not be the right, bottom edge geometrically, it's just used 111cdf0e10cSrcweir when determining the extension direction. Thus, it's 112cdf0e10cSrcweir perfectly legal to affine-transform a rectangle, and given 113cdf0e10cSrcweir the transformed point here. On method return, this 114cdf0e10cSrcweir parameter will contain the adapted output. 115cdf0e10cSrcweir 116cdf0e10cSrcweir @param rFitTarget 117cdf0e10cSrcweir The rectangle to fit the parallelogram into. 118cdf0e10cSrcweir */ 119*b63233d8Sdamjan BASEGFX_DLLPUBLIC void infiniteLineFromParallelogram( ::basegfx::B2DPoint& io_rLeftTop, 120cdf0e10cSrcweir ::basegfx::B2DPoint& io_rLeftBottom, 121cdf0e10cSrcweir ::basegfx::B2DPoint& io_rRightTop, 122cdf0e10cSrcweir ::basegfx::B2DPoint& io_rRightBottom, 123cdf0e10cSrcweir const ::basegfx::B2DRange& rFitTarget ); 124cdf0e10cSrcweir 125cdf0e10cSrcweir } 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir #endif /* _BGFX_TOOLS_TOOLS_HXX */ 129