LCOV - code coverage report
Current view: top level - canvas/source/tools - surfacerect.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 54 0.0 %
Date: 2014-11-03 Functions: 0 8 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             : #ifndef INCLUDED_CANVAS_SOURCE_TOOLS_SURFACERECT_HXX
      21             : #define INCLUDED_CANVAS_SOURCE_TOOLS_SURFACERECT_HXX
      22             : 
      23             : #include <basegfx/point/b2ipoint.hxx>
      24             : #include <basegfx/vector/b2isize.hxx>
      25             : 
      26             : namespace canvas
      27             : {
      28             : 
      29             :     // SurfaceRect
      30             : 
      31             : 
      32           0 :     struct SurfaceRect
      33             :     {
      34             :         ::basegfx::B2IPoint maPos;
      35             :         ::basegfx::B2ISize  maSize;
      36             :         ::basegfx::B2IPoint maBackup;
      37             :         bool                bEnabled;
      38             : 
      39           0 :         explicit SurfaceRect( const ::basegfx::B2ISize &rSize ) :
      40             :             maPos(),
      41             :             maSize(rSize),
      42             :             maBackup(),
      43           0 :             bEnabled(true)
      44             :         {
      45           0 :         }
      46             : 
      47             :         // coordinates contained in this rectangle are
      48             :         // constrained to the following rules:
      49             :         // 1) p.x >= pos.x
      50             :         // 2) p.x <= pos.x+size.x
      51             :         // 3) p.y >= pos.y
      52             :         // 4) p.y <= pos.y+size.y
      53             :         // in other words, 'size' means the number of pixels
      54             :         // this rectangle encloses plus one. for example with pos[0,0]
      55             :         // and size[512,512], p[512,512] would return inside.
      56             :         // a size of [0,0] therefore denotes a one-by-one rectangle.
      57           0 :         bool pointInside( sal_Int32 px, sal_Int32 py ) const
      58             :         {
      59           0 :             const sal_Int32 x1(maPos.getX());
      60           0 :             const sal_Int32 y1(maPos.getY());
      61           0 :             const sal_Int32 x2(maPos.getX()+maSize.getX());
      62           0 :             const sal_Int32 y2(maPos.getY()+maSize.getY());
      63           0 :             if(px  < x1) return false;
      64           0 :             if(px >= x2) return false;
      65           0 :             if(py  < y1) return false;
      66           0 :             if(py >= y2) return false;
      67           0 :             return true;
      68             :         }
      69             : 
      70             :         // returns true if the horizontal line intersects the rect.
      71           0 :         bool hLineIntersect( sal_Int32 lx1, sal_Int32 lx2, sal_Int32 ly ) const
      72             :         {
      73           0 :             const sal_Int32 x1(maPos.getX());
      74           0 :             const sal_Int32 y1(maPos.getY());
      75           0 :             const sal_Int32 x2(maPos.getX()+maSize.getX());
      76           0 :             const sal_Int32 y2(maPos.getY()+maSize.getY());
      77           0 :             if(ly < y1) return false;
      78           0 :             if(ly >= y2) return false;
      79           0 :             if((lx1 < x1) && (lx2 < x1)) return false;
      80           0 :             if((lx1 >= x2) && (lx2 >= x2)) return false;
      81           0 :             return true;
      82             :         }
      83             : 
      84             :         //! Returns true if the vertical line intersects the rect.
      85           0 :         bool vLineIntersect( sal_Int32 lx, sal_Int32 ly1, sal_Int32 ly2 ) const
      86             :         {
      87           0 :             const sal_Int32 x1(maPos.getX());
      88           0 :             const sal_Int32 y1(maPos.getY());
      89           0 :             const sal_Int32 x2(maPos.getX()+maSize.getX());
      90           0 :             const sal_Int32 y2(maPos.getY()+maSize.getY());
      91           0 :             if(lx < x1) return false;
      92           0 :             if(lx >= x2) return false;
      93           0 :             if((ly1 < y1) && (ly2 < y1)) return false;
      94           0 :             if((ly1 >= y2) && (ly2 >= y2)) return false;
      95           0 :             return true;
      96             :         }
      97             : 
      98             :         // returns true if the passed rect intersects this one.
      99           0 :         bool intersection( const SurfaceRect& r ) const
     100             :         {
     101           0 :             const sal_Int32 x1(maPos.getX());
     102           0 :             const sal_Int32 y1(maPos.getY());
     103           0 :             const sal_Int32 x2(maPos.getX()+maSize.getX());
     104           0 :             const sal_Int32 y2(maPos.getY()+maSize.getY());
     105           0 :             if(r.hLineIntersect(x1,x2,y1)) return true;
     106           0 :             if(r.hLineIntersect(x1,x2,y2)) return true;
     107           0 :             if(r.vLineIntersect(x1,y1,y2)) return true;
     108           0 :             if(r.vLineIntersect(x2,y1,y2)) return true;
     109           0 :             return false;
     110             :         }
     111             : 
     112           0 :         bool inside( const SurfaceRect& r ) const
     113             :         {
     114           0 :             const sal_Int32 x1(maPos.getX());
     115           0 :             const sal_Int32 y1(maPos.getY());
     116           0 :             const sal_Int32 x2(maPos.getX()+maSize.getX());
     117           0 :             const sal_Int32 y2(maPos.getY()+maSize.getY());
     118           0 :             if(!(r.pointInside(x1,y1))) return false;
     119           0 :             if(!(r.pointInside(x2,y1))) return false;
     120           0 :             if(!(r.pointInside(x2,y2))) return false;
     121           0 :             if(!(r.pointInside(x1,y2))) return false;
     122           0 :             return true;
     123             :         }
     124             :     };
     125             : }
     126             : 
     127             : #endif
     128             : 
     129             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10