LCOV - code coverage report
Current view: top level - include/basegfx/tools - rectcliptools.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 16 16 100.0 %
Date: 2014-11-03 Functions: 4 5 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_BASEGFX_TOOLS_RECTCLIPTOOLS_HXX
      21             : #define INCLUDED_BASEGFX_TOOLS_RECTCLIPTOOLS_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : #include <basegfx/range/b2ibox.hxx>
      25             : 
      26             : 
      27             : 
      28             : namespace basegfx
      29             : {
      30             :     namespace tools
      31             :     {
      32             :         namespace RectClipFlags
      33             :         {
      34             :             static const sal_uInt32 LEFT   = (sal_Int32)0x01;
      35             :             static const sal_uInt32 RIGHT  = (sal_Int32)0x02;
      36             :             static const sal_uInt32 TOP    = (sal_Int32)0x04;
      37             :             static const sal_uInt32 BOTTOM = (sal_Int32)0x08;
      38             :         }
      39             : 
      40             :         /** Calc clip mask for Cohen-Sutherland rectangle clip
      41             : 
      42             :             This function returns a clip mask used for the
      43             :             Cohen-Sutherland rectangle clip method, where one or more
      44             :             of the lower four bits are set, if the given point is
      45             :             outside one or more of the four half planes defining the
      46             :             rectangle (see RectClipFlags for possible values)
      47             :          */
      48             :         template< class Point, class Rect > inline
      49          16 :            sal_uInt32 getCohenSutherlandClipFlags( const Point& rP,
      50             :                                                    const Rect&  rR )
      51             :         {
      52             :             // maxY | minY | maxX | minX
      53          16 :             sal_uInt32 clip  = (rP.getX() < rR.getMinX()) << 0;
      54          16 :                        clip |= (rP.getX() > rR.getMaxX()) << 1;
      55          16 :                        clip |= (rP.getY() < rR.getMinY()) << 2;
      56          16 :                        clip |= (rP.getY() > rR.getMaxY()) << 3;
      57          16 :             return clip;
      58             :         }
      59             : 
      60             :         /// Cohen-Sutherland mask calculation - overload for boxes.
      61             :         template< class Point > inline
      62     9193028 :            sal_uInt32 getCohenSutherlandClipFlags( const Point&  rP,
      63             :                                                    const B2IBox& rB )
      64             :         {
      65             :             // maxY | minY | maxX | minX
      66     9193028 :             sal_uInt32 clip  = (rP.getX() <  rB.getMinX()) << 0;
      67     9193028 :                        clip |= (rP.getX() >= rB.getMaxX()) << 1;
      68     9193028 :                        clip |= (rP.getY() <  rB.getMinY()) << 2;
      69     9193028 :                        clip |= (rP.getY() >= rB.getMaxY()) << 3;
      70     9193028 :             return clip;
      71             :         }
      72             : 
      73             :         /** Determine number of clip planes hit by given clip mask
      74             : 
      75             :             This method returns the number of one bits in the four
      76             :             least significant bits of the argument, which amounts to
      77             :             the number of clip planes hit within the
      78             :             getCohenSutherlandClipFlags() method.
      79             :          */
      80     8650570 :         inline sal_uInt32 getNumberOfClipPlanes( sal_uInt32 nFlags )
      81             :         {
      82             :             // classic bit count algo, see e.g. Reingold, Nievergelt,
      83             :             // Deo: Combinatorial Algorithms, Theory and Practice,
      84             :             // Prentice-Hall 1977
      85     8650570 :             nFlags = (nFlags & 0x05) + ((nFlags >> 1) & 0x05);
      86     8650570 :             nFlags = (nFlags & 0x03) + (nFlags >> 2); // no need for &
      87             :                                                       // 0x03, can't
      88             :                                                       // overflow
      89     8650570 :             return nFlags;
      90             :         }
      91             :     }
      92             : }
      93             : 
      94             : #endif // INCLUDED_BASEGFX_TOOLS_RECTCLIPTOOLS_HXX
      95             : 
      96             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10