TAPs 0.7.7.3
TAPsVector2.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsVector2.hpp
00003 ******************************************************************************/
00007 /******************************************************************************
00008 SUKITTI PUNAK   (09/09/2004)
00009 UPDATE          (08/27/2010)
00010 ******************************************************************************/
00011 #ifndef TAPs_VECTOR2_HPP
00012 #define TAPs_VECTOR2_HPP
00013 
00014 #include "TAPsVector.hpp"
00015 
00016 template <typename T> class ColMatrix2x2;
00017 
00018 BEGIN_NAMESPACE_TAPs
00019 //=============================================================================
00020 template <typename T>
00021 class Vector2 : public Vector<T,2> {
00022 //=============================================================================
00023 public:
00024     //-------------------------------------------------------------------------
00025     // Constructors
00026     Vector2 ();
00027     Vector2 ( T const af[2] );
00028     Vector2 ( Vector2<T> const &v );
00029     Vector2 ( T x, T y );
00030     //-------------------------------------------------------------------------
00031     // Assignment Operator
00032     inline Vector2<T> & operator= ( Vector2<T> const &v );
00033     //-------------------------------------------------------------------------
00034     // Comparison Operators
00035     inline bool operator== ( Vector2<T> const &v ) const;
00036     inline bool operator!= ( Vector2<T> const &v ) const;
00037     inline bool operator<= ( Vector2<T> const &v ) const;
00038     inline bool operator<  ( Vector2<T> const &v ) const;
00039     inline bool operator>= ( Vector2<T> const &v ) const;
00040     inline bool operator>  ( Vector2<T> const &v ) const;
00041     //-------------------------------------------------------------------------
00042     // Arithmetic Operators
00043     inline Vector2<T> operator- () const;   // negation
00044     inline Vector2<T> operator+ ( Vector2<T> const &v ) const;
00045     inline Vector2<T> operator- ( Vector2<T> const &v ) const;
00046     inline Vector2<T> operator* ( T s ) const;
00047     inline Vector2<T> operator/ ( T s ) const;
00048     friend inline Vector2<T> operator* ( T s, Vector2<T> const &v ) { return v*s; }
00049     //-------------------------------------------------------------------------
00050     // Arithmetic Update Operators
00051     inline Vector2<T> & operator+= ( Vector2<T> const &v );
00052     inline Vector2<T> & operator-= ( Vector2<T> const &v );
00053     inline Vector2<T> & operator*= ( T s );
00054     inline Vector2<T> & operator/= ( T s );
00055     //-------------------------------------------------------------------------
00056     // Vector Operations
00057     inline T Length () const;
00058     inline T Magnitude () const;
00059     inline T SquaredLength () const;
00060     inline Vector2<T> GetUnit ( T tolerance = TAPs::Math<T>::EPSILON ) const;
00061     inline Vector2<T> & Normalized ( T tolerance = TAPs::Math<T>::EPSILON );
00062     inline T Dot ( Vector2<T> const &v ) const;         // Dot Product
00063     inline T operator* ( Vector2<T> const &v ) const;   // Dot Product Operator
00064 
00066     inline Vector2<T> ComponentWiseMult ( Vector2<T> const &v ) const;
00068     inline Vector2<T> ComponentWiseDivs ( Vector2<T> const &v ) const;
00070     inline void UpdateByComponentWiseMult ( Vector2<T> const &v );
00072     inline void UpdateByComponentWiseDivs ( Vector2<T> const &v );
00073 
00074     //-------------------------------------------------------------------------
00075     // Get/Set Fn(s)
00076     inline T GetX() const { return this->t[0]; }
00077     inline T GetY() const { return this->t[1]; }
00078     inline void GetXY( T &x, T &y ) const { x = this->t[0]; y = this->t[1]; }
00079     inline void SetX( T x ) { this->t[0] = x; }
00080     inline void SetY( T y ) { this->t[1] = y; }
00081     inline void SetXY( T x, T y ) { this->t[0] = x; this->t[1] = y; }
00082     //-------------------------------------------------------------------------
00083     // Vector * ColMatrix
00084     Vector2<T> operator* ( ColMatrix2x2<T> const &M ) const;
00085     //-------------------------------------------------------------------------
00086 }; // END CLASS Vector2
00087 //=============================================================================
00088 //-----------------------------------------------------------------------------
00089 // Define Vector2s
00090 typedef Vector2<int>            Vector2i;
00091 typedef Vector2<float>          Vector2f;
00092 typedef Vector2<double>         Vector2d;
00093 typedef Vector2<long double>    Vector2ld;
00094 //-----------------------------------------------------------------------------
00095 //=============================================================================
00096 // class Point2 is a vector2.
00097 template <typename T>
00098 class Point2 : public Vector2<T> {
00099 public:
00100     //-------------------------------------------------------------------------
00101     // Output Operator <<
00102     friend std::ostream & operator<< ( std::ostream &output, Point2<T> const &p )
00103     {
00104         output  << "Point2<" << typeid(T).name() << ">( "
00105                 << p.t[0] << ", " << p.t[1]
00106                 << " )'";
00107         return output;
00108     }
00109     //-------------------------------------------------------------------------
00110     // Constructors
00111     Point2 () : Vector2<T>() {}
00112     Point2 ( T const at[2] ) : Vector2<T>( at ) {}
00113     Point2 ( Point2<T> const &p ) : Vector2<T>( p ) {}
00114     Point2 ( T x, T y ) : Vector2<T>( x, y ) {}
00115     //-------------------------------------------------------------------------
00116 }; // END CLASS Point2
00117 //=============================================================================
00118 //-----------------------------------------------------------------------------
00119 typedef Point2<int>    Point2i;
00120 typedef Point2<float>  Point2f;
00121 typedef Point2<double> Point2d;
00122 //-----------------------------------------------------------------------------
00123 //=============================================================================
00124 END_NAMESPACE_TAPs
00125 //-----------------------------------------------------------------------------
00126 // Include definition if TAPs_USE_EXPORT is not defined
00127 //#if !defined( TAPs_USE_EXPORT )
00128     #include "TAPsVector2.cpp"
00129 //#endif
00130 //-----------------------------------------------------------------------------
00131 #endif
00132 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00133 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines