SIBCVector2Dd.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Softimage 3D Games & 3D Bridge team
00004 //
00005 // (c) Copyright 1999-2002 Avid Technology, Inc. . All rights reserved.
00006 //
00007 // SIBCVector2Dd.h | Main header file for CSIBCVector2Dd implementation.
00008 //***************************************************************************************
00009 
00010 /****************************************************************************************
00011 THIS CODE IS PUBLISHED AS A SAMPLE ONLY AND IS PROVIDED "AS IS".
00012 IN NO EVENT SHALL SOFTIMAGE, AVID TECHNOLOGY, INC. AND/OR THEIR RESPECTIVE
00013 SUPPLIERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
00014 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00015 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00016 CONNECTION WITH THE USE OR PERFORMANCE OF THIS CODE .
00017 
00018 COPYRIGHT NOTICE. Copyright © 1999-2002 Avid Technology Inc. . All rights reserved. 
00019 
00020 SOFTIMAGE is a registered trademark of Avid Technology Inc. or its subsidiaries 
00021 or divisions. Windows NT is a registered trademark of Microsoft Corp. All other
00022 trademarks contained herein are the property of their respective owners. 
00023 ****************************************************************************************/
00024 
00025 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
00026 #pragma once
00027 #endif
00028 
00029 //******************************************************************************
00030 // Defines
00031 //******************************************************************************
00032 #ifndef _VECTOR2_H_
00033 #define _VECTOR2_H_
00034 
00035 //******************************************************************************
00036 // Includes
00037 //****************************************************************************** 
00038 #include "SIBCMathLib.h"
00039 
00040 //******************************************************************************
00041 // Typedefs
00042 //******************************************************************************
00043 
00044 //******************************************************************************
00045 // CSIBCVector2Dd | General 2D vector.
00046 //******************************************************************************
00047 
00049 
00059 class XSICOREEXPORT CSIBCVector2Dd
00060 {
00061     // Public members
00062     public:
00063 
00064         //****************************************
00065         // IMPLEMENTATION
00066 
00070         CSIBCVector2Dd( );
00071 
00077         CSIBCVector2Dd( const double  in_dX, const double in_dY );
00078 
00083         CSIBCVector2Dd( const double in_dXY[2] );
00084 
00089         CSIBCVector2Dd( int in_nIndex, double in_dVal );
00090 
00091         ~CSIBCVector2Dd();
00092 
00099         const double * GetArray() const;
00100     
00107         double GetX( void ) const;
00108 
00115         double GetY( void ) const;
00116 
00124         double Get( const int in_nIndex ) const;
00125 
00133         void    Get( double& out_dX, double& out_dY ) const;
00134 
00144         double GetMaxComponent( bool in_bInAbs = true ) const;
00145 
00155         double GetMinComponent( bool in_bInAbs = true ) const;
00156 
00165         int GetIndexOfMaxComponent( bool in_bInAbs = true ) const;
00166 
00175         int GetIndexOfMinComponent( bool in_bInAbs = true ) const;
00176 
00184         CSIBCVector2Dd& SetX ( const double in_dVal );
00185 
00193         CSIBCVector2Dd& SetY ( const double in_dVal );
00194 
00203         CSIBCVector2Dd& Set( const CSIBCVector2Dd& in_vct );
00204 
00212         CSIBCVector2Dd& Set( const int in_nIndex, const double in_dVal );
00213 
00223         CSIBCVector2Dd& Set( const double in_dX, const double in_dY );
00224 
00230         CSIBCVector2Dd& SetNull( void );
00231 
00240         bool IsNull( const double in_dEpsilon=PICO_EPS ) const;
00241 
00254         CSIBCVector2Dd& SetMinimal ( bool in_bInAbs = true, const double in_dEpsilon=PICO_EPS );
00255 
00269         CSIBCVector2Dd& SetMinimal ( const CSIBCVector2Dd & in_vct, bool in_bInAbs = true );
00270 
00271 
00282         friend bool AreAlmostEqual( const CSIBCVector2Dd& in_vct1,
00283                                     const CSIBCVector2Dd& in_vct2,
00284                                     const double in_dEpsilon = PICO_EPS );
00285 
00286 
00294         bool operator == ( const CSIBCVector2Dd& in_vct ) const;
00295 
00303         bool operator != ( const CSIBCVector2Dd& in_vct ) const;
00304 
00310         CSIBCVector2Dd& Negate( const CSIBCVector2Dd& in_vct );
00311         
00316         CSIBCVector2Dd& Negate( void );
00317 
00324         double GetSquaredLength( void ) const;
00325 
00332         double GetLength( void ) const;
00333 
00341         bool SetLength( const double in_dLength );
00342 
00349         bool Normalize( void );
00350 
00351         // Efficient arithmetic operations.
00352 
00359         CSIBCVector2Dd& Add( const CSIBCVector2Dd&  in_vct  );
00360 
00368         CSIBCVector2Dd& Add( const CSIBCVector2Dd&  in_vct1, const CSIBCVector2Dd& in_vct2 );
00369 
00376         CSIBCVector2Dd& Sub( const CSIBCVector2Dd&  in_vct );
00377 
00385         CSIBCVector2Dd& Sub( const CSIBCVector2Dd&  in_vct1, const CSIBCVector2Dd& in_vct2 );
00386 
00396         CSIBCVector2Dd& Mul( const double in_dFactor );
00397 
00408         CSIBCVector2Dd& Mul( const double in_dFactor, const CSIBCVector2Dd& in_vct );
00409 
00420         CSIBCVector2Dd& Mul( const CSIBCVector2Dd& in_vct, const double in_dFactor );
00421 
00431         CSIBCVector2Dd& Div( const double in_dFactor );
00432 
00443         CSIBCVector2Dd& Div( const CSIBCVector2Dd& in_vct, const double in_dFactor );
00444 
00455         CSIBCVector2Dd& MulComp( const CSIBCVector2Dd& in_vct1, const CSIBCVector2Dd& in_vct2  );
00456 
00466         CSIBCVector2Dd& MulComp( const CSIBCVector2Dd& in_vct );
00467 
00477         CSIBCVector2Dd& DivComp( const CSIBCVector2Dd& in_vct ); 
00478 
00489         CSIBCVector2Dd& DivComp( const CSIBCVector2Dd& in_vct1, const CSIBCVector2Dd& in_vct2 );
00490 
00491         // TODO  Remove set of functions to multiply by CSIBCRotMatd as soon as 
00492         //       CSIBCRotMatd and CSIBCMatrix33d will both derived public from a
00493         //       common base matrix class.
00494 
00507         CSIBCVector2Dd& Mul( const CSIBCVector3Dd&  in_vct, const CSIBCRotMatd& in_mat );
00508 
00521         CSIBCVector2Dd& Mul( const CSIBCRotMatd& in_mat, const CSIBCVector3Dd& in_vct );
00522 
00528         friend double GetDot( const CSIBCVector2Dd& in_vct1, const CSIBCVector2Dd& in_vct2 );
00529 
00536         bool SetProjection( const CSIBCVector2Dd& in_vct );
00537 
00544         CSIBCVector2Dd& SetMirror( const CSIBCVector2Dd& in_vct1,
00545                                     const CSIBCVector2Dd& in_vct2 );
00546 
00547 
00555         friend double GetDistance( const CSIBCVector2Dd& in_pnt1, 
00556                                     const CSIBCVector2Dd& in_pnt2 );
00557 
00565         friend double GetSquaredDistance( const CSIBCVector2Dd& in_pnt1, 
00566                                     const CSIBCVector2Dd& in_pnt2 );
00567         
00576         friend int Get2DPntSide(    const CSIBCVector2Dd& in_pnt,   
00577                                     const CSIBCVector2Dd& in_pntOrigin,
00578                                     const CSIBCVector2Dd& in_pntTip );
00579 
00588         friend bool FSegmentIntersect(  const CSIBCVector2Dd& a0,
00589                                         const CSIBCVector2Dd& a1,
00590                                         const CSIBCVector2Dd& b0,
00591                                         const CSIBCVector2Dd& b1 );
00592 
00599         CSIBCVector2Dd& SetMidpoint(    const CSIBCVector2Dd& in_pnt1,
00600                                         const CSIBCVector2Dd& in_pnt2 );
00601 
00610         CSIBCVector2Dd& LinearPositionInterpolate( const CSIBCVector2Dd& in_vct1,
00611                                     const CSIBCVector2Dd& in_vct2, const double in_dT );
00612 
00614         // To be implemented later //
00616         // The following methods will be implemented later.
00617 
00618         // Cardinal & Bezier Position Interpolate doens't exist in SI3D3.7
00619         // What about Linear, Cardinal & Bezier VectorInterpolate
00620 
00621         // SetBounds    | Readjust boundaries (min and max) to contain a given point.
00623         void SetBounds( const CSIBCVector2Dd& in_pnt,
00624                                     CSIBCVector2Dd& io_min, CSIBCVector2Dd& io_max );
00625 
00626         // Combine      | Compute this=s1*v1 + s2*v2.
00628         CSIBCVector2Dd& Combine( const CSIBCVector2Dd& in_vct1, const double in_dS1,
00629                                     const CSIBCVector2Dd& in_vct2, const double in_dS2 );
00630 
00632         // To finish implementing.   //
00634 
00635         // BsplinePositionInterpolate | Interpolates a BSpline position between four 2D vectors.
00637         CSIBCVector2Dd& BsplinePositionInterpolate( const CSIBCVector2Dd& in_vct1,
00638                                     const CSIBCVector2Dd& in_vct2, const CSIBCVector2Dd& in_vct3,
00639                                     const CSIBCVector2Dd& in_vct4, const double in_dT );
00640         // BsplineVectorInterpolate | Interpolates a BSpline vector between four 2D vectors.
00642         CSIBCVector2Dd& BsplineVectorInterpolate( const CSIBCVector2Dd& in_vct1,
00643                                     const CSIBCVector2Dd& in_vct2, const CSIBCVector2Dd& in_vct3,
00644                                     const CSIBCVector2Dd& in_vct4, const double in_dT );
00645 
00646         // ArePntsCollinear | Verify if three points are collinear.
00648         friend bool ArePntsCollinear( const CSIBCVector2Dd& in_pnt1,
00649                                         const CSIBCVector2Dd& in_pnt2,
00650                                         const CSIBCVector2Dd& in_pnt3,
00651                                         const double in_dEpsilon = PICO_EPS );
00652 
00653     // Private Members
00654     private:
00655 
00656         CSIBCVector2Dd( const CSIBCVector2Dd& in_vct );
00657         
00658         //****************************************
00659         // ATTRIBUTES
00660         //****************************************
00661         // double | CSIBCVector2Dd | m_dX | X component of the vector.
00662         // double | CSIBCVector2Dd | m_dY | Y component of the vector.
00663         double  m_dX, m_dY;
00664 };
00665 
00666 //******************************************************************************
00667 //
00668 // Author       : Michel Carigan
00669 // Date         : 08/05/96
00670 // Updated by   : Eric Cabot (02/25/97)
00671 //
00672 // Set each component to be at least epsilon (in absolute or not depending on in_bInAbs).
00673 //
00674 // A reference on this.
00675 //
00676 // This function works like the macro _SI_VCT_EPS in v3.51
00677 // That is, each component are set to eps only if they are less than epsilon.
00678 // In that case the sign is unchanged.
00679 //
00680 //
00681 //******************************************************************************
00682 inline CSIBCVector2Dd&
00683 CSIBCVector2Dd::SetMinimal
00684     (
00685         bool in_bInAbs,             // Tells if the test is done in absolute value or not (true by default).
00686         const double in_dEpsilon    // The epsilon to compare with (#PICO_EPS by default).
00687     )
00688 {
00689 
00690     if( in_bInAbs )
00691     {
00692 
00693         if( fabs(m_dX) < in_dEpsilon )
00694             m_dX = ( ( m_dX >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
00695         if( fabs(m_dY) < in_dEpsilon )
00696             m_dY = ( ( m_dY >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
00697     }
00698     else
00699     {
00700         if( m_dX < in_dEpsilon )
00701         {
00702             m_dX = in_dEpsilon;
00703         }
00704         if( m_dY < in_dEpsilon )
00705         {
00706             m_dY = in_dEpsilon;
00707         }
00708     }
00709 
00710     return *this;
00711 }
00712 
00713 #endif