LCOV - code coverage report
Current view: top level - libreoffice/basegfx/source/tools - tools.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 27 0.0 %
Date: 2012-12-27 Functions: 0 3 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/tools/tools.hxx"
      21             : #include "basegfx/range/b2drange.hxx"
      22             : 
      23             : #include <algorithm>
      24             : 
      25             : 
      26             : namespace basegfx
      27             : {
      28             :     namespace tools
      29             :     {
      30             :         namespace
      31             :         {
      32           0 :             inline double distance( const double&                   nX,
      33             :                                     const double&                   nY,
      34             :                                     const ::basegfx::B2DVector&     rNormal,
      35             :                                     const double&                   nC )
      36             :             {
      37           0 :                 return nX*rNormal.getX() + nY*rNormal.getY() - nC;
      38             :             }
      39             : 
      40           0 :             void moveLineOutsideRect( ::basegfx::B2DPoint&          io_rStart,
      41             :                                       ::basegfx::B2DPoint&          io_rEnd,
      42             :                                       const ::basegfx::B2DVector&   rMoveDirection,
      43             :                                       const ::basegfx::B2DRange&    rFitTarget      )
      44             :             {
      45             :                 // calc c for normal line form equation n x - c = 0
      46           0 :                 const double nC( rMoveDirection.scalar( io_rStart ) );
      47             : 
      48             :                 // calc maximum orthogonal distance for all four bound
      49             :                 // rect corners to the line
      50             :                 const double nMaxDistance( ::std::max(
      51             :                                                0.0,
      52             :                                                ::std::max(
      53           0 :                                                    distance(rFitTarget.getMinX(),
      54           0 :                                                             rFitTarget.getMinY(),
      55             :                                                             rMoveDirection,
      56           0 :                                                             nC),
      57             :                                                    ::std::max(
      58           0 :                                                        distance(rFitTarget.getMinX(),
      59           0 :                                                                 rFitTarget.getMaxY(),
      60             :                                                                 rMoveDirection,
      61           0 :                                                                 nC),
      62             :                                                        ::std::max(
      63           0 :                                                            distance(rFitTarget.getMaxX(),
      64           0 :                                                                     rFitTarget.getMinY(),
      65             :                                                                     rMoveDirection,
      66           0 :                                                                     nC),
      67           0 :                                                            distance(rFitTarget.getMaxX(),
      68           0 :                                                                     rFitTarget.getMaxY(),
      69             :                                                                     rMoveDirection,
      70           0 :                                                                     nC) ) ) ) ) );
      71             : 
      72             :                 // now move line points, such that the bound rect
      73             :                 // points are all either 'on' or on the negative side
      74             :                 // of the half-plane
      75           0 :                 io_rStart += nMaxDistance*rMoveDirection;
      76           0 :                 io_rEnd   += nMaxDistance*rMoveDirection;
      77           0 :             }
      78             :         }
      79             : 
      80           0 :         void infiniteLineFromParallelogram( ::basegfx::B2DPoint&        io_rLeftTop,
      81             :                                             ::basegfx::B2DPoint&        io_rLeftBottom,
      82             :                                             ::basegfx::B2DPoint&        io_rRightTop,
      83             :                                             ::basegfx::B2DPoint&        io_rRightBottom,
      84             :                                             const ::basegfx::B2DRange&  rFitTarget  )
      85             :         {
      86             :             // For the top and bottom border line of the
      87             :             // parallelogram, we determine the distance to all four
      88             :             // corner points of the bound rect (tl, tr, bl, br). When
      89             :             // using the unit normal form for lines (n x - c = 0), and
      90             :             // choosing n to point 'outwards' the parallelogram, then
      91             :             // all bound rect corner points having positive distance
      92             :             // to the line lie outside the extended gradient rect, and
      93             :             // thus, the corresponding border line must be moved the
      94             :             // maximum distance outwards.
      95             : 
      96             :             // don't use the top and bottom border line direction, and
      97             :             // calculate the normal from them. Instead, use the
      98             :             // vertical lines (lt - lb or rt - rb), as they more
      99             :             // faithfully represent the direction of the
     100             :             // to-be-generated infinite line
     101           0 :             ::basegfx::B2DVector aDirectionVertical( io_rLeftTop - io_rLeftBottom );
     102           0 :             aDirectionVertical.normalize();
     103             : 
     104           0 :             const ::basegfx::B2DVector aNormalTop( aDirectionVertical );
     105           0 :             const ::basegfx::B2DVector aNormalBottom( -aDirectionVertical );
     106             : 
     107             :             // now extend parallelogram, such that the bound rect
     108             :             // point are included
     109           0 :             moveLineOutsideRect( io_rLeftTop, io_rRightTop, aNormalTop, rFitTarget );
     110           0 :             moveLineOutsideRect( io_rLeftBottom, io_rRightBottom, aNormalBottom, rFitTarget );
     111           0 :         }
     112             :     }
     113             : }
     114             : 
     115             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10