svgtopt/gfx2d/src/GfxGeom/GfxLine2D.cpp
changeset 46 88edb906c587
equal deleted inserted replaced
-1:000000000000 46:88edb906c587
       
     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 "GfxLine2D.h"
       
    20 #include "GfxLineIteratorP.h"
       
    21 
       
    22 #include "GfxFloatFixPt.h"
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // Constructor
       
    26 // ---------------------------------------------------------------------------
       
    27 // --------------------------------------------------------------------------
       
    28 //  TGfxLine2D::TGfxLine2D( const TFloatFixPt& aX1,
       
    29 // ---------------------------------------------------------------------------
       
    30  TGfxLine2D::TGfxLine2D( const TFloatFixPt& aX1,
       
    31                                  const TFloatFixPt& aY1,
       
    32                                  const TFloatFixPt& aX2,
       
    33                                  const TFloatFixPt& aY2 ) :
       
    34 								 iX1( aX1 ),
       
    35 								 iY1( aY1 ),
       
    36 								 iX2( aX2 ),
       
    37 								 iY2( aY2 )
       
    38 	{
       
    39 	}
       
    40 
       
    41 // --------------------------------------------------------------------------
       
    42 //  TGfxLine2D::TGfxLine2D( TGfxPoint2D /* aP1 */, TGfxPoint2D /* aP2 */ )
       
    43 // ---------------------------------------------------------------------------
       
    44  TGfxLine2D::TGfxLine2D( TGfxPoint2D /* aP1 */, TGfxPoint2D /* aP2 */ )
       
    45     {
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // From MGfxShape
       
    50 // ---------------------------------------------------------------------------
       
    51 // --------------------------------------------------------------------------
       
    52 //  void TGfxLine2D::GetBounds( const TGfxAffineTransform& aAt,
       
    53 // ---------------------------------------------------------------------------
       
    54  void TGfxLine2D::GetBounds( const TGfxAffineTransform& aAt,
       
    55                                      TGfxRectangle2D& aRect )
       
    56     {
       
    57     TGfxPoint2D p1( iX1, iY1 ), p2( iX2, iY2 );
       
    58     aAt.Transform( &p1, & p1, 1 );
       
    59     aAt.Transform( &p2, & p2, 1 );
       
    60     aRect.iX = ( p1.iX > p2.iX ) ? p2.iX : p1.iX;
       
    61     aRect.iY = ( p1.iY > p2.iY ) ? p2.iY : p1.iY;
       
    62     aRect.iWidth = ( p1.iX > p2.iX ) ? p1.iX - p2.iX : p2.iX - p1.iX;
       
    63     aRect.iHeight = ( p1.iY > p2.iY ) ? p1.iY - p2.iY : p2.iY - p1.iY;
       
    64     }
       
    65 
       
    66 // --------------------------------------------------------------------------
       
    67 //  void TGfxLine2D::GetPathIteratorL( TGfxAffineTransform* aAt,
       
    68 // ---------------------------------------------------------------------------
       
    69  void TGfxLine2D::GetPathIteratorL( TGfxAffineTransform* aAt,
       
    70                                             CGfxPathIterator*& aPitr )
       
    71     {
       
    72     aPitr = ( CGfxPathIterator * ) new( ELeave )
       
    73             CGfxLineIteratorP( this, aAt );
       
    74     }
       
    75 
       
    76 // --------------------------------------------------------------------------
       
    77 //  void TGfxLine2D::GetPathIteratorL( TGfxAffineTransform* aAt,
       
    78 // ---------------------------------------------------------------------------
       
    79  void TGfxLine2D::GetPathIteratorL( TGfxAffineTransform* aAt,
       
    80                                             TInt /* aLimit */,
       
    81                                             CGfxPathIterator*& aPitr )
       
    82     {
       
    83     aPitr = new( ELeave ) CGfxLineIteratorP( this, aAt );
       
    84     }
       
    85 
       
    86 // --------------------------------------------------------------------------
       
    87 //  TFloatFixPt TGfxLine2D::Length()
       
    88 // ---------------------------------------------------------------------------
       
    89  TFloatFixPt TGfxLine2D::Length()
       
    90     {
       
    91     TFloatFixPt dx, dy, int0x7f( KMAXFLOATFIX );
       
    92 
       
    93     dx = iX1 - iX2;
       
    94     dy = iY1 - iY2;
       
    95     if ( dx > int0x7f || dy > int0x7f )
       
    96         {
       
    97         // calculate as integer
       
    98         TInt32 tmplen, tx, ty;
       
    99         tx = ( TInt32 ) dx;
       
   100         ty = ( TInt32 ) dy;
       
   101 	#ifdef SVG_FLOAT_BUILD
       
   102         tmplen = TFloatFixPt::Sqrt( tx * tx + ty * ty );
       
   103 	#else
       
   104         tmplen = TFloatFixPt::FixedSqrtGeneral( tx * tx + ty * ty, 0 );
       
   105 	#endif
       
   106         return TFloatFixPt( tmplen );
       
   107         }
       
   108 
       
   109     return TFloatFixPt::Sqrt( dx * dx + dy * dy );
       
   110     }
       
   111 
       
   112 // --------------------------------------------------------------------------
       
   113 // TFloatFixPt TGfxLine2D::AreaSize()
       
   114 // ---------------------------------------------------------------------------
       
   115 TFloatFixPt TGfxLine2D::AreaSize()
       
   116     {
       
   117     return TFloatFixPt( 0 );
       
   118     }
       
   119