SIBCVector2Dd.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Crosswalk team
00004 //
00005 // Copyright 2008 Autodesk, Inc.  All rights reserved.  
00006 // Use of this software is subject to the terms of the Autodesk license agreement 
00007 // provided at the time of installation or download, or which otherwise accompanies 
00008 // this software in either electronic or hard copy form.
00009 //
00010 //***************************************************************************************
00011 
00012 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
00013 #pragma once
00014 #endif
00015 
00016 //******************************************************************************
00017 // Defines
00018 //******************************************************************************
00019 #ifndef _VECTOR2_H_
00020 #define _VECTOR2_H_
00021 
00022 //******************************************************************************
00023 // Includes
00024 //****************************************************************************** 
00025 #include "SIBCMathLib.h"
00026 
00027 //******************************************************************************
00028 // Typedefs
00029 //******************************************************************************
00030 
00031 //******************************************************************************
00032 // CSIBCVector2Dd | General 2D vector.
00033 //******************************************************************************
00034 
00036 
00046 class XSICOREEXPORT CSIBCVector2Dd
00047 {
00048     // Public members
00049     public:
00050 
00051         //****************************************
00052         // IMPLEMENTATION
00053 
00057         CSIBCVector2Dd( );
00058 
00064         CSIBCVector2Dd( const double  in_dX, const double in_dY );
00065 
00070         CSIBCVector2Dd( const double in_dXY[2] );
00071 
00076         CSIBCVector2Dd( int in_nIndex, double in_dVal );
00077 
00078         ~CSIBCVector2Dd();
00079 
00086         const double * GetArray() const;
00087     
00094         double GetX( void ) const;
00095 
00102         double GetY( void ) const;
00103 
00111         double Get( const int in_nIndex ) const;
00112 
00120         void    Get( double& out_dX, double& out_dY ) const;
00121 
00131         double GetMaxComponent( bool in_bInAbs = true ) const;
00132 
00142         double GetMinComponent( bool in_bInAbs = true ) const;
00143 
00152         int GetIndexOfMaxComponent( bool in_bInAbs = true ) const;
00153 
00162         int GetIndexOfMinComponent( bool in_bInAbs = true ) const;
00163 
00171         CSIBCVector2Dd& SetX ( const double in_dVal );
00172 
00180         CSIBCVector2Dd& SetY ( const double in_dVal );
00181 
00190         CSIBCVector2Dd& Set( const CSIBCVector2Dd& in_vct );
00191 
00199         CSIBCVector2Dd& Set( const int in_nIndex, const double in_dVal );
00200 
00210         CSIBCVector2Dd& Set( const double in_dX, const double in_dY );
00211 
00217         CSIBCVector2Dd& SetNull( void );
00218 
00227         bool IsNull( const double in_dEpsilon=PICO_EPS ) const;
00228 
00241         CSIBCVector2Dd& SetMinimal ( bool in_bInAbs = true, const double in_dEpsilon=PICO_EPS );
00242 
00256         CSIBCVector2Dd& SetMinimal ( const CSIBCVector2Dd & in_vct, bool in_bInAbs = true );
00257 
00258 
00269         friend bool AreAlmostEqual( const CSIBCVector2Dd& in_vct1,
00270                                     const CSIBCVector2Dd& in_vct2,
00271                                     const double in_dEpsilon = PICO_EPS );
00272 
00273 
00281         bool operator == ( const CSIBCVector2Dd& in_vct ) const;
00282 
00290         bool operator != ( const CSIBCVector2Dd& in_vct ) const;
00291 
00297         CSIBCVector2Dd& Negate( const CSIBCVector2Dd& in_vct );
00298         
00303         CSIBCVector2Dd& Negate( void );
00304 
00311         double GetSquaredLength( void ) const;
00312 
00319         double GetLength( void ) const;
00320 
00328         bool SetLength( const double in_dLength );
00329 
00336         bool Normalize( void );
00337 
00338         // Efficient arithmetic operations.
00339 
00346         CSIBCVector2Dd& Add( const CSIBCVector2Dd&  in_vct  );
00347 
00355         CSIBCVector2Dd& Add( const CSIBCVector2Dd&  in_vct1, const CSIBCVector2Dd& in_vct2 );
00356 
00363         CSIBCVector2Dd& Sub( const CSIBCVector2Dd&  in_vct );
00364 
00372         CSIBCVector2Dd& Sub( const CSIBCVector2Dd&  in_vct1, const CSIBCVector2Dd& in_vct2 );
00373 
00383         CSIBCVector2Dd& Mul( const double in_dFactor );
00384 
00395         CSIBCVector2Dd& Mul( const double in_dFactor, const CSIBCVector2Dd& in_vct );
00396 
00407         CSIBCVector2Dd& Mul( const CSIBCVector2Dd& in_vct, const double in_dFactor );
00408 
00418         CSIBCVector2Dd& Div( const double in_dFactor );
00419 
00430         CSIBCVector2Dd& Div( const CSIBCVector2Dd& in_vct, const double in_dFactor );
00431 
00442         CSIBCVector2Dd& MulComp( const CSIBCVector2Dd& in_vct1, const CSIBCVector2Dd& in_vct2  );
00443 
00453         CSIBCVector2Dd& MulComp( const CSIBCVector2Dd& in_vct );
00454 
00464         CSIBCVector2Dd& DivComp( const CSIBCVector2Dd& in_vct ); 
00465 
00476         CSIBCVector2Dd& DivComp( const CSIBCVector2Dd& in_vct1, const CSIBCVector2Dd& in_vct2 );
00477 
00478         // TODO  Remove set of functions to multiply by CSIBCRotMatd as soon as 
00479         //       CSIBCRotMatd and CSIBCMatrix33d will both derived public from a
00480         //       common base matrix class.
00481 
00494         CSIBCVector2Dd& Mul( const CSIBCVector3Dd&  in_vct, const CSIBCRotMatd& in_mat );
00495 
00508         CSIBCVector2Dd& Mul( const CSIBCRotMatd& in_mat, const CSIBCVector3Dd& in_vct );
00509 
00515         friend double GetDot( const CSIBCVector2Dd& in_vct1, const CSIBCVector2Dd& in_vct2 );
00516 
00523         bool SetProjection( const CSIBCVector2Dd& in_vct );
00524 
00531         CSIBCVector2Dd& SetMirror( const CSIBCVector2Dd& in_vct1,
00532                                     const CSIBCVector2Dd& in_vct2 );
00533 
00534 
00542         friend double GetDistance( const CSIBCVector2Dd& in_pnt1, 
00543                                     const CSIBCVector2Dd& in_pnt2 );
00544 
00552         friend double GetSquaredDistance( const CSIBCVector2Dd& in_pnt1, 
00553                                     const CSIBCVector2Dd& in_pnt2 );
00554         
00563         friend int Get2DPntSide(    const CSIBCVector2Dd& in_pnt,   
00564                                     const CSIBCVector2Dd& in_pntOrigin,
00565                                     const CSIBCVector2Dd& in_pntTip );
00566 
00575         friend bool FSegmentIntersect(  const CSIBCVector2Dd& a0,
00576                                         const CSIBCVector2Dd& a1,
00577                                         const CSIBCVector2Dd& b0,
00578                                         const CSIBCVector2Dd& b1 );
00579 
00586         CSIBCVector2Dd& SetMidpoint(    const CSIBCVector2Dd& in_pnt1,
00587                                         const CSIBCVector2Dd& in_pnt2 );
00588 
00597         CSIBCVector2Dd& LinearPositionInterpolate( const CSIBCVector2Dd& in_vct1,
00598                                     const CSIBCVector2Dd& in_vct2, const double in_dT );
00599 
00601         // To be implemented later //
00603         // The following methods will be implemented later.
00604 
00605         // Cardinal & Bezier Position Interpolate doens't exist in SI3D3.7
00606         // What about Linear, Cardinal & Bezier VectorInterpolate
00607 
00608         // SetBounds    | Readjust boundaries (min and max) to contain a given point.
00610         void SetBounds( const CSIBCVector2Dd& in_pnt,
00611                                     CSIBCVector2Dd& io_min, CSIBCVector2Dd& io_max );
00612 
00613         // Combine      | Compute this=s1*v1 + s2*v2.
00615         CSIBCVector2Dd& Combine( const CSIBCVector2Dd& in_vct1, const double in_dS1,
00616                                     const CSIBCVector2Dd& in_vct2, const double in_dS2 );
00617 
00619         // To finish implementing.   //
00621 
00622         // BsplinePositionInterpolate | Interpolates a BSpline position between four 2D vectors.
00624         CSIBCVector2Dd& BsplinePositionInterpolate( const CSIBCVector2Dd& in_vct1,
00625                                     const CSIBCVector2Dd& in_vct2, const CSIBCVector2Dd& in_vct3,
00626                                     const CSIBCVector2Dd& in_vct4, const double in_dT );
00627         // BsplineVectorInterpolate | Interpolates a BSpline vector between four 2D vectors.
00629         CSIBCVector2Dd& BsplineVectorInterpolate( const CSIBCVector2Dd& in_vct1,
00630                                     const CSIBCVector2Dd& in_vct2, const CSIBCVector2Dd& in_vct3,
00631                                     const CSIBCVector2Dd& in_vct4, const double in_dT );
00632 
00633         // ArePntsCollinear | Verify if three points are collinear.
00635         friend bool ArePntsCollinear( const CSIBCVector2Dd& in_pnt1,
00636                                         const CSIBCVector2Dd& in_pnt2,
00637                                         const CSIBCVector2Dd& in_pnt3,
00638                                         const double in_dEpsilon = PICO_EPS );
00639 
00640     // Private Members
00641     private:
00642 
00643         CSIBCVector2Dd( const CSIBCVector2Dd& in_vct );
00644         
00645         //****************************************
00646         // ATTRIBUTES
00647         //****************************************
00648         // double | CSIBCVector2Dd | m_dX | X component of the vector.
00649         // double | CSIBCVector2Dd | m_dY | Y component of the vector.
00650         double  m_dX, m_dY;
00651 };
00652 
00653 //******************************************************************************
00654 //
00655 // Author       : Michel Carigan
00656 // Date         : 08/05/96
00657 // Updated by   : Eric Cabot (02/25/97)
00658 //
00659 // Set each component to be at least epsilon (in absolute or not depending on in_bInAbs).
00660 //
00661 // A reference on this.
00662 //
00663 // This function works like the macro _SI_VCT_EPS in v3.51
00664 // That is, each component are set to eps only if they are less than epsilon.
00665 // In that case the sign is unchanged.
00666 //
00667 //
00668 //******************************************************************************
00669 inline CSIBCVector2Dd&
00670 CSIBCVector2Dd::SetMinimal
00671     (
00672         bool in_bInAbs,             // Tells if the test is done in absolute value or not (true by default).
00673         const double in_dEpsilon    // The epsilon to compare with (#PICO_EPS by default).
00674     )
00675 {
00676 
00677     if( in_bInAbs )
00678     {
00679 
00680         if( fabs(m_dX) < in_dEpsilon )
00681             m_dX = ( ( m_dX >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
00682         if( fabs(m_dY) < in_dEpsilon )
00683             m_dY = ( ( m_dY >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
00684     }
00685     else
00686     {
00687         if( m_dX < in_dEpsilon )
00688         {
00689             m_dX = in_dEpsilon;
00690         }
00691         if( m_dY < in_dEpsilon )
00692         {
00693             m_dY = in_dEpsilon;
00694         }
00695     }
00696 
00697     return *this;
00698 }
00699 
00700 #endif