LCOV - code coverage report
Current view: top level - basegfx/inc/basegfx/tools - rectcliptools.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 6 0.0 %
Date: 2012-08-25 Functions: 0 1 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 6 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef _BGFX_TOOLS_RECTCLIPTOOLS_HXX
      30                 :            : #define _BGFX_TOOLS_RECTCLIPTOOLS_HXX
      31                 :            : 
      32                 :            : #include <sal/types.h>
      33                 :            : #include <basegfx/range/b2ibox.hxx>
      34                 :            : 
      35                 :            : //////////////////////////////////////////////////////////////////////////////
      36                 :            : 
      37                 :            : namespace basegfx
      38                 :            : {
      39                 :            :     namespace tools
      40                 :            :     {
      41                 :            :         namespace RectClipFlags
      42                 :            :         {
      43                 :            :             static const sal_uInt32 LEFT   = (sal_Int32)0x01;
      44                 :            :             static const sal_uInt32 RIGHT  = (sal_Int32)0x02;
      45                 :            :             static const sal_uInt32 TOP    = (sal_Int32)0x04;
      46                 :            :             static const sal_uInt32 BOTTOM = (sal_Int32)0x08;
      47                 :            :         }
      48                 :            : 
      49                 :            :         /** Calc clip mask for Cohen-Sutherland rectangle clip
      50                 :            : 
      51                 :            :             This function returns a clip mask used for the
      52                 :            :             Cohen-Sutherland rectangle clip method, where one or more
      53                 :            :             of the lower four bits are set, if the given point is
      54                 :            :             outside one or more of the four half planes defining the
      55                 :            :             rectangle (see RectClipFlags for possible values)
      56                 :            :          */
      57                 :            :         template< class Point, class Rect > inline
      58                 :          0 :            sal_uInt32 getCohenSutherlandClipFlags( const Point& rP,
      59                 :            :                                                    const Rect&  rR )
      60                 :            :         {
      61                 :            :             // maxY | minY | maxX | minX
      62                 :          0 :             sal_uInt32 clip  = (rP.getX() < rR.getMinX()) << 0;
      63         [ #  # ]:          0 :                        clip |= (rP.getX() > rR.getMaxX()) << 1;
      64         [ #  # ]:          0 :                        clip |= (rP.getY() < rR.getMinY()) << 2;
      65         [ #  # ]:          0 :                        clip |= (rP.getY() > rR.getMaxY()) << 3;
      66                 :          0 :             return clip;
      67                 :            :         }
      68                 :            : 
      69                 :            :         /// Cohen-Sutherland mask calculation - overload for boxes.
      70                 :            :         template< class Point > inline
      71                 :            :            sal_uInt32 getCohenSutherlandClipFlags( const Point&  rP,
      72                 :            :                                                    const B2IBox& rB )
      73                 :            :         {
      74                 :            :             // maxY | minY | maxX | minX
      75                 :            :             sal_uInt32 clip  = (rP.getX() <  rB.getMinX()) << 0;
      76                 :            :                        clip |= (rP.getX() >= rB.getMaxX()) << 1;
      77                 :            :                        clip |= (rP.getY() <  rB.getMinY()) << 2;
      78                 :            :                        clip |= (rP.getY() >= rB.getMaxY()) << 3;
      79                 :            :             return clip;
      80                 :            :         }
      81                 :            : 
      82                 :            :         /** Determine number of clip planes hit by given clip mask
      83                 :            : 
      84                 :            :             This method returns the number of one bits in the four
      85                 :            :             least significant bits of the argument, which amounts to
      86                 :            :             the number of clip planes hit within the
      87                 :            :             getCohenSutherlandClipFlags() method.
      88                 :            :          */
      89                 :            :         inline sal_uInt32 getNumberOfClipPlanes( sal_uInt32 nFlags )
      90                 :            :         {
      91                 :            :             // classic bit count algo, see e.g. Reingold, Nievergelt,
      92                 :            :             // Deo: Combinatorial Algorithms, Theory and Practice,
      93                 :            :             // Prentice-Hall 1977
      94                 :            :             nFlags = (nFlags & 0x05) + ((nFlags >> 1) & 0x05);
      95                 :            :             nFlags = (nFlags & 0x03) + (nFlags >> 2); // no need for &
      96                 :            :                                                       // 0x03, can't
      97                 :            :                                                       // overflow
      98                 :            :             return nFlags;
      99                 :            :         }
     100                 :            :     }
     101                 :            : }
     102                 :            : 
     103                 :            : #endif // _BGFX_TOOLS_RECTCLIPTOOLS_HXX
     104                 :            : 
     105                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10