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

Generated by: LCOV version 1.10