LCOV - code coverage report
Current view: top level - basegfx/source/range - b2xrange.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 35 0.0 %
Date: 2014-04-14 Functions: 0 4 0.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             : #include <basegfx/range/b2drange.hxx>
      21             : #include <basegfx/range/b2irange.hxx>
      22             : #include <basegfx/range/b2ibox.hxx>
      23             : 
      24             : 
      25             : namespace basegfx
      26             : {
      27             :     namespace
      28             :     {
      29             :         /** Generic implementation of the difference set computation
      30             : 
      31             :             @tpl RangeType
      32             :             Type to operate on. Must provide ValueType and TraitsType
      33             :             nested types.
      34             :          */
      35           0 :         template< class RangeType > void doComputeSetDifference(
      36             :             ::std::vector< RangeType >& o_rRanges,
      37             :             const RangeType&            a,
      38             :             const RangeType&            b )
      39             :         {
      40           0 :             o_rRanges.clear();
      41             : 
      42             :             // special-casing the empty rect case (this will fail most
      43             :             // of the times below, because of the DBL_MIN/MAX special
      44             :             // values denoting emptiness in the rectangle.
      45           0 :             if( a.isEmpty() )
      46             :             {
      47           0 :                 o_rRanges.push_back( b );
      48           0 :                 return;
      49             :             }
      50           0 :             if( b.isEmpty() )
      51             :             {
      52           0 :                 o_rRanges.push_back( a );
      53           0 :                 return;
      54             :             }
      55             : 
      56           0 :             const typename RangeType::ValueType                     ax(a.getMinX());
      57           0 :             const typename RangeType::ValueType                     ay(a.getMinY());
      58           0 :             const typename RangeType::TraitsType::DifferenceType    aw(a.getWidth());
      59           0 :             const typename RangeType::TraitsType::DifferenceType    ah(a.getHeight());
      60           0 :             const typename RangeType::ValueType                     bx(b.getMinX());
      61           0 :             const typename RangeType::ValueType                     by(b.getMinY());
      62           0 :             const typename RangeType::TraitsType::DifferenceType    bw(b.getWidth());
      63           0 :             const typename RangeType::TraitsType::DifferenceType    bh(b.getHeight());
      64             : 
      65           0 :             const typename RangeType::TraitsType::DifferenceType    h0( (by > ay) ? by - ay : 0 );
      66           0 :             const typename RangeType::TraitsType::DifferenceType    h3( (by + bh < ay + ah) ? ay + ah - by - bh : 0 );
      67           0 :             const typename RangeType::TraitsType::DifferenceType    w1( (bx > ax) ? bx - ax : 0 );
      68           0 :             const typename RangeType::TraitsType::DifferenceType    w2( (ax + aw > bx + bw) ? ax + aw - bx - bw : 0 );
      69           0 :             const typename RangeType::TraitsType::DifferenceType    h12( (h0 + h3 < ah) ? ah - h0 - h3 : 0 );
      70             : 
      71             :             // TODO(E2): Use numeric_cast instead of static_cast here,
      72             :             // need range checks!
      73           0 :             if (h0 > 0)
      74           0 :                 o_rRanges.push_back(
      75             :                     RangeType(ax,ay,
      76             :                               static_cast<typename RangeType::ValueType>(ax+aw),
      77             :                               static_cast<typename RangeType::ValueType>(ay+h0)) );
      78             : 
      79           0 :             if (w1 > 0 && h12 > 0)
      80           0 :                 o_rRanges.push_back(
      81             :                     RangeType(ax,
      82             :                               static_cast<typename RangeType::ValueType>(ay+h0),
      83             :                               static_cast<typename RangeType::ValueType>(ax+w1),
      84             :                               static_cast<typename RangeType::ValueType>(ay+h0+h12)) );
      85             : 
      86           0 :             if (w2 > 0 && h12 > 0)
      87           0 :                 o_rRanges.push_back(
      88             :                     RangeType(static_cast<typename RangeType::ValueType>(bx+bw),
      89             :                               static_cast<typename RangeType::ValueType>(ay+h0),
      90             :                               static_cast<typename RangeType::ValueType>(bx+bw+w2),
      91             :                               static_cast<typename RangeType::ValueType>(ay+h0+h12)) );
      92             : 
      93           0 :             if (h3 > 0)
      94           0 :                 o_rRanges.push_back(
      95             :                     RangeType(ax,
      96             :                               static_cast<typename RangeType::ValueType>(ay+h0+h12),
      97             :                               static_cast<typename RangeType::ValueType>(ax+aw),
      98             :                               static_cast<typename RangeType::ValueType>(ay+h0+h12+h3)) );
      99             :         }
     100             :     }
     101             : 
     102           0 :     ::std::vector< B2IRange >& computeSetDifference( ::std::vector< B2IRange >& o_rResult,
     103             :                                                      const B2IRange&            rFirst,
     104             :                                                      const B2IRange&            rSecond )
     105             :     {
     106           0 :         doComputeSetDifference( o_rResult, rFirst, rSecond );
     107             : 
     108           0 :         return o_rResult;
     109             :     }
     110             : 
     111           0 :     ::std::vector< B2DRange >& computeSetDifference( ::std::vector< B2DRange >& o_rResult,
     112             :                                                      const B2DRange&            rFirst,
     113             :                                                      const B2DRange&            rSecond )
     114             :     {
     115           0 :         doComputeSetDifference( o_rResult, rFirst, rSecond );
     116             : 
     117           0 :         return o_rResult;
     118             :     }
     119             : 
     120             : } // end of namespace basegfx
     121             : 
     122             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10