svgtopt/gfx2d/src/GfxGeom/GfxRectangularShape.cpp
changeset 0 d46562c3d99d
equal deleted inserted replaced
-1:000000000000 0:d46562c3d99d
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Graphics Extension Library source file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "GfxRectangularShape.h"
       
    20 #include "GfxRectangle2D.h"
       
    21 
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // Constructor
       
    25 // ---------------------------------------------------------------------------
       
    26 // --------------------------------------------------------------------------
       
    27 //  TGfxRectangularShape::TGfxRectangularShape()
       
    28 // ---------------------------------------------------------------------------
       
    29  TGfxRectangularShape::TGfxRectangularShape()
       
    30     {
       
    31     }
       
    32 
       
    33 // --------------------------------------------------------------------------
       
    34 //  TGfxRectangularShape::TGfxRectangularShape( const TFloatFixPt& aX,
       
    35 // ---------------------------------------------------------------------------
       
    36  TGfxRectangularShape::TGfxRectangularShape( const TFloatFixPt& aX,
       
    37                                                      const TFloatFixPt& aY,
       
    38                                                      const TFloatFixPt& aWidth,
       
    39                                                      const TFloatFixPt& aHeight )
       
    40 													 :iWidth(aWidth),
       
    41 													 iHeight(aHeight),
       
    42 													 iX(aX),
       
    43 													 iY(aY)
       
    44 	{
       
    45 	}
       
    46 
       
    47 
       
    48 // --------------------------------------------------------------------------
       
    49 //  void TGfxRectangularShape::GetBounds( const TGfxAffineTransform& aAt,
       
    50 // ---------------------------------------------------------------------------
       
    51  void TGfxRectangularShape::GetBounds( const TGfxAffineTransform& aAt,
       
    52                                                TGfxRectangle2D& aRect )
       
    53     {
       
    54     TGfxPoint2D p[4];
       
    55     p[0].iX = iX;
       
    56     p[0].iY = iY;
       
    57     p[1].iX = iX + iWidth;
       
    58     p[1].iY = iY;
       
    59     p[2].iX = iX + iWidth;
       
    60     p[2].iY = iY + iHeight;
       
    61     p[3].iX = iX;
       
    62     p[3].iY = iY + iHeight;
       
    63     aAt.Transform( p, p, 4 );
       
    64 
       
    65     TFloatFixPt xMin( KMAXFLOATFIX ), yMin( KMAXFLOATFIX ), xMax( KMINFLOATFIX ), yMax( KMINFLOATFIX );
       
    66     for ( TInt32 i = 0; i < 4; i++ )
       
    67         {
       
    68         if ( p[i].iX < xMin )
       
    69             xMin = p[i].iX;
       
    70         if ( p[i].iX > xMax )
       
    71             xMax = p[i].iX;
       
    72         if ( p[i].iY < yMin )
       
    73             yMin = p[i].iY;
       
    74         if ( p[i].iY > yMax )
       
    75             yMax = p[i].iY;
       
    76         }
       
    77 
       
    78     aRect.iX = xMin;
       
    79     aRect.iY = yMin;
       
    80     aRect.iWidth = xMax - xMin;
       
    81     aRect.iHeight = yMax - yMin;
       
    82     }
       
    83 
       
    84 // --------------------------------------------------------------------------
       
    85 //  TFloatFixPt TGfxRectangularShape::AreaSize()
       
    86 // ---------------------------------------------------------------------------
       
    87  TFloatFixPt TGfxRectangularShape::AreaSize()
       
    88     {
       
    89     if ( iWidth > KMAXFLOATFIX || iHeight > KMAXFLOATFIX )
       
    90         {
       
    91         TInt area = ( ( TInt ) iWidth ) * ( ( TInt ) iHeight );
       
    92         if ( area < KMAXFLOATFIXVALUE )
       
    93             return TFloatFixPt( area );
       
    94         else
       
    95             return KMAXFLOATFIX;
       
    96         }
       
    97     else
       
    98         {
       
    99         return iWidth * iHeight;
       
   100         }
       
   101     }
       
   102 
       
   103 // --------------------------------------------------------------------------
       
   104 //  TFloatFixPt TGfxRectangularShape::CenterX()
       
   105 // ---------------------------------------------------------------------------
       
   106  TFloatFixPt TGfxRectangularShape::CenterX()
       
   107   {
       
   108 	#ifdef SVG_FLOAT_BUILD
       
   109     return ( iX + (iWidth * TFloatFixPt(.5f)));
       
   110 	#else
       
   111     return ( iX + (iWidth >> 1));
       
   112 	#endif
       
   113 	}
       
   114 
       
   115 
       
   116 // --------------------------------------------------------------------------
       
   117 //  TFloatFixPt TGfxRectangularShape::CenterY()
       
   118 // ---------------------------------------------------------------------------
       
   119  TFloatFixPt TGfxRectangularShape::CenterY()
       
   120     {
       
   121 	#ifdef SVG_FLOAT_BUILD
       
   122     return ( iY + (iHeight * TFloatFixPt(.5f))) ;
       
   123 	#else
       
   124     return ( iY + (iHeight >> 1)) ;
       
   125 	#endif
       
   126     }
       
   127 
       
   128 
       
   129 // --------------------------------------------------------------------------
       
   130 //  TFloatFixPt TGfxRectangularShape::MinX()
       
   131 // ---------------------------------------------------------------------------
       
   132  TFloatFixPt TGfxRectangularShape::MinX()
       
   133     {
       
   134     return TFloatFixPt( iX );
       
   135     }
       
   136 
       
   137 // --------------------------------------------------------------------------
       
   138 //  TFloatFixPt TGfxRectangularShape::MinY()
       
   139 // ---------------------------------------------------------------------------
       
   140  TFloatFixPt TGfxRectangularShape::MinY()
       
   141     {
       
   142     return TFloatFixPt( iY );
       
   143     }
       
   144 
       
   145 // --------------------------------------------------------------------------
       
   146 //  TFloatFixPt TGfxRectangularShape::MaxX()
       
   147 // ---------------------------------------------------------------------------
       
   148  TFloatFixPt TGfxRectangularShape::MaxX()
       
   149     {
       
   150     return TFloatFixPt( iX + iWidth );
       
   151     }
       
   152 
       
   153 // --------------------------------------------------------------------------
       
   154 //  TFloatFixPt TGfxRectangularShape::MaxY()
       
   155 // ---------------------------------------------------------------------------
       
   156  TFloatFixPt TGfxRectangularShape::MaxY()
       
   157     {
       
   158     return TFloatFixPt( iY + iHeight );
       
   159     }
       
   160