OSGVector.inl

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038
00039 OSG_BEGIN_NAMESPACE
00040
00041 //---------------------------------------------------------------------------
00042 //  VecStorage1
00043 //---------------------------------------------------------------------------
00044
00053 #if defined(__hpux)
00054 template <class ValueTypeT>
00055 const UInt32 VecStorage1<ValueTypeT>::_uiSize;
00056 #endif
00057 
00058
00059 template <class ValueTypeT> inline
00060 VecStorage1<ValueTypeT>::VecStorage1(void)
00061 {
00062     for(UInt32 i = 0; i < _uiSize; i++)
00063     {
00064         _values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00065     }
00066 }
00067
00068
00069 template <class ValueTypeT> inline
00070 VecStorage1<ValueTypeT>::~VecStorage1(void)
00071 {
00072 }
00073
00074
00075 template <class ValueTypeT> inline
00076 void VecStorage1<ValueTypeT>::setValues(const ValueTypeT rVal1)
00077 {
00078     _values[0] = rVal1;
00079 }
00080
00081
00082 template <class ValueTypeT> inline
00083 void VecStorage1<ValueTypeT>::getSeparateValues(ValueTypeT &rVal1) const
00084 {
00085     rVal1 = _values[0];
00086 }
00087
00088
00089 template <class ValueTypeT> inline
00090 ValueTypeT VecStorage1<ValueTypeT>::x(void) const
00091 {
00092     return _values[0];
00093 }
00094
00095
00096
00097 //---------------------------------------------------------------------------
00098 //  VecStorage2
00099 //---------------------------------------------------------------------------
00100
00109 #if defined(__hpux)
00110 template <class ValueTypeT>
00111 const UInt32 VecStorage2<ValueTypeT>::_uiSize;
00112 #endif
00113 
00114
00115 template <class ValueTypeT> inline
00116 VecStorage2<ValueTypeT>::VecStorage2(void)
00117 {
00118     for(UInt32 i = 0; i < _uiSize; i++)
00119     {
00120         _values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00121     }
00122 }
00123
00124
00125 template <class ValueTypeT> inline
00126 VecStorage2<ValueTypeT>::~VecStorage2(void)
00127 {
00128 }
00129
00130
00131 template <class ValueTypeT> inline
00132 void VecStorage2<ValueTypeT>::setValues(const ValueTypeT rVal1,
00133                                         const ValueTypeT rVal2)
00134 {
00135     _values[0] = rVal1;
00136     _values[1] = rVal2;
00137 }
00138
00139
00140 template <class ValueTypeT> inline
00141 void VecStorage2<ValueTypeT>::getSeparateValues(ValueTypeT &rVal1,
00142                                                 ValueTypeT &rVal2) const
00143 {
00144     rVal1 = _values[0];
00145     rVal2 = _values[1];
00146 }
00147
00148
00149 template <class ValueTypeT> inline
00150 ValueTypeT VecStorage2<ValueTypeT>::x(void) const
00151 {
00152     return _values[0];
00153 }
00154
00155
00156 template <class ValueTypeT> inline
00157 ValueTypeT VecStorage2<ValueTypeT>::y(void) const
00158 {
00159     return _values[1];
00160 }
00161
00162
00163
00164
00165 //---------------------------------------------------------------------------
00166 //  VecStorage3
00167 //---------------------------------------------------------------------------
00168
00177 #if defined(__hpux)
00178 template <class ValueTypeT>
00179 const UInt32 VecStorage3<ValueTypeT>::_uiSize;
00180 #endif
00181 
00182
00183 template <class ValueTypeT> inline
00184 VecStorage3<ValueTypeT>::VecStorage3(void)
00185 {
00186     for(UInt32 i = 0; i < _uiSize; i++)
00187     {
00188         _values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00189     }
00190 }
00191
00192
00193 template <class ValueTypeT> inline
00194 VecStorage3<ValueTypeT>::~VecStorage3(void)
00195 {
00196 }
00197
00198
00199 template <class ValueTypeT> inline
00200 void VecStorage3<ValueTypeT>::setValues(const ValueTypeT rVal1,
00201                                         const ValueTypeT rVal2,
00202                                         const ValueTypeT rVal3)
00203 {
00204     _values[0] = rVal1;
00205     _values[1] = rVal2;
00206     _values[2] = rVal3;
00207 }
00208
00209
00210 template <class ValueTypeT> inline
00211 void VecStorage3<ValueTypeT>::getSeparateValues(ValueTypeT &rVal1,
00212                                                 ValueTypeT &rVal2,
00213                                                 ValueTypeT &rVal3) const
00214 {
00215     rVal1 = _values[0];
00216     rVal2 = _values[1];
00217     rVal3 = _values[2];
00218 }
00219
00220
00221 template <class ValueTypeT> inline
00222 ValueTypeT VecStorage3<ValueTypeT>::x(void) const
00223 {
00224     return _values[0];
00225 }
00226
00227
00228 template <class ValueTypeT> inline
00229 ValueTypeT VecStorage3<ValueTypeT>::y(void) const
00230 {
00231     return _values[1];
00232 }
00233
00234
00235 template <class ValueTypeT> inline
00236 ValueTypeT VecStorage3<ValueTypeT>::z(void) const
00237 {
00238     return _values[2];
00239 }
00240
00241
00242
00243
00244 //---------------------------------------------------------------------------
00245 //  VecStorage4
00246 //---------------------------------------------------------------------------
00247
00256 #if defined(__hpux)
00257 template <class ValueTypeT> inline
00258 const UInt32 VecStorage4<ValueTypeT>::_uiSize;
00259 #endif
00260 
00261
00262 template <class ValueTypeT> inline
00263 VecStorage4<ValueTypeT>::VecStorage4(void)
00264 {
00265     for(UInt32 i = 0; i < _uiSize; i++)
00266     {
00267         _values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00268     }
00269 }
00270
00271
00272 template <class ValueTypeT> inline
00273 VecStorage4<ValueTypeT>::~VecStorage4(void)
00274 {
00275 }
00276
00277
00278 template <class ValueTypeT> inline
00279 void VecStorage4<ValueTypeT>::setValues(const ValueTypeT rVal1,
00280                                         const ValueTypeT rVal2,
00281                                         const ValueTypeT rVal3,
00282                                         const ValueTypeT rVal4)
00283 {
00284     _values[0] = rVal1;
00285     _values[1] = rVal2;
00286     _values[2] = rVal3;
00287     _values[3] = rVal4;
00288 }
00289
00290
00291 template <class ValueTypeT> inline
00292 void VecStorage4<ValueTypeT>::getSeparateValues(ValueTypeT &rVal1,
00293                                                 ValueTypeT &rVal2,
00294                                                 ValueTypeT &rVal3,
00295                                                 ValueTypeT &rVal4) const
00296 {
00297     rVal1 = _values[0];
00298     rVal2 = _values[1];
00299     rVal3 = _values[2];
00300     rVal4 = _values[3];
00301 }
00302
00303
00304 template <class ValueTypeT> inline
00305 ValueTypeT VecStorage4<ValueTypeT>::x(void) const
00306 {
00307     return _values[0];
00308 }
00309
00310
00311 template <class ValueTypeT> inline
00312 ValueTypeT VecStorage4<ValueTypeT>::y(void) const
00313 {
00314     return _values[1];
00315 }
00316
00317
00318 template <class ValueTypeT> inline
00319 ValueTypeT VecStorage4<ValueTypeT>::z(void) const
00320 {
00321     return _values[2];
00322 }
00323
00324
00325 template <class ValueTypeT> inline
00326 ValueTypeT VecStorage4<ValueTypeT>::w(void) const
00327 {
00328     return _values[3];
00329 }
00330
00331
00332
00333 //---------------------------------------------------------------------------
00334 //  Class
00335 //---------------------------------------------------------------------------
00336
00357 #ifndef darwinXXX
00358 template <class  ValueTypeT,
00359           UInt32 SizeI      >
00360 const Point<ValueTypeT, SizeI>
00361     Point<ValueTypeT, SizeI>::Null;
00362 #endif
00363 
00364
00365 template <class  ValueTypeT,
00366           UInt32 SizeI      > inline
00367 Point<ValueTypeT, SizeI>::Point(void) :
00368     Inherited()
00369 {
00370 }
00371
00377 template <class  ValueTypeT,
00378           UInt32 SizeI      > inline
00379 Point<ValueTypeT, SizeI>::Point(const ValueTypeT *pVals) :
00380     Inherited()
00381 {
00382     if(pVals == NULL)
00383     {
00384         for(UInt32 i = 0; i < Self::_uiSize; i++)
00385         {
00386             Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00387         }
00388     }
00389     else
00390     {
00391         for(UInt32 i = 0; i < Self::_uiSize; i++)
00392         {
00393             Self::_values[i] = pVals[i];
00394         }
00395     }
00396 }
00397
00403 template <class  ValueTypeT,
00404           UInt32 SizeI      > inline
00405 Point<ValueTypeT, SizeI>::Point(ValueTypeT *pVals) :
00406     Inherited()
00407 {
00408     if(pVals == NULL)
00409     {
00410         for(UInt32 i = 0; i < Self::_uiSize; i++)
00411         {
00412             Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00413         }
00414     }
00415     else
00416     {
00417         for(UInt32 i = 0; i < Self::_uiSize; i++)
00418         {
00419             Self::_values[i] = pVals[i];
00420         }
00421     }
00422 }
00423
00424 template <class  ValueTypeT,
00425           UInt32 SizeI       >
00426 template <class  ValueType2T,
00427           UInt32 Size2I      > inline
00428 Point<ValueTypeT, SizeI>::Point(const Point<ValueType2T, Size2I> &pnt)
00429 {
00430     typedef Point<ValueType2T, Size2I> Point2T;
00431
00432     if(Self::_uiSize <= Point2T::_uiSize)
00433     {
00434         for(UInt32 i = 0; i < Self::_uiSize; i++)
00435         {
00436             Self::_values[i] = pnt.getValues()[i];
00437         }
00438     }
00439     else
00440     {
00441         UInt32 i;
00442         for(i = 0; i < Point2T::_uiSize; i++)
00443         {
00444             Self::_values[i] = pnt.getValues()[i];
00445         }
00446         for(i = Point2T::_uiSize; i < Self::_uiSize; i++)
00447         {
00448             Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00449         }
00450     }
00451 }
00452
00453 template <class  ValueTypeT,
00454           UInt32 SizeI       >
00455 template <class  ValueType2T,
00456           UInt32 Size2I      > inline
00457 Point<ValueTypeT, SizeI>::Point(const Vector<ValueType2T, Size2I> &vec)
00458 {
00459     typedef Vector<ValueType2T, Size2I> Vector2T;
00460
00461     if(Self::_uiSize <= Vector2T::_uiSize)
00462     {
00463         for(UInt32 i = 0; i < Self::_uiSize; i++)
00464         {
00465             Self::_values[i] = vec.getValues()[i];
00466         }
00467     }
00468     else
00469     {
00470         UInt32 i;
00471         for(i = 0; i < Vector2T::_uiSize; i++)
00472         {
00473             Self::_values[i] = vec.getValues()[i];
00474         }
00475         for(i = Vector2T::_uiSize; i < Self::_uiSize; i++)
00476         {
00477             Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00478         }
00479     }
00480 }
00481
00482
00483 template <class  ValueTypeT,
00484           UInt32 SizeI      > inline
00485 Point<ValueTypeT, SizeI>::Point(const Point &source) :
00486
00487     Inherited()
00488 {
00489     for(UInt32 i = 0; i < Self::_uiSize; i++)
00490     {
00491         Self::_values[i] = source._values[i];
00492     }
00493 }
00494
00495
00496
00497 template <class  ValueTypeT,
00498           UInt32 SizeI      > inline
00499 Point<ValueTypeT, SizeI>::Point(const ValueType rVal1)
00500 {
00501     UInt32 i;
00502
00503     Self::_values[0] = rVal1;
00504
00505     for(i = 1; i < Self::_uiSize; i++)
00506     {
00507         Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00508     }
00509 }
00510
00511
00512
00513 #ifdef __sgi
00514 #pragma set woff 1209
00515 #endif
00516 
00518
00519 template <class  ValueTypeT,
00520           UInt32 SizeI      > inline
00521 Point<ValueTypeT, SizeI>::Point(const ValueType rVal1,
00522                                 const ValueType rVal2) :
00523     Inherited()
00524 {
00525     Self::_values[0] = rVal1;
00526
00527     if(Self::_uiSize == 2)
00528     {
00529         Self::_values[1] = rVal2;
00530     }
00531     else if(Self::_uiSize >= 3)
00532     {
00533         Self::_values[1] = rVal2;
00534
00535         for(UInt32 i = 2; i < Self::_uiSize; i++)
00536         {
00537             Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00538         }
00539     }
00540 }
00541
00542 #ifdef __sgi
00543 #pragma reset woff 1209
00544 
00545 #pragma set woff 1209
00546 #endif
00547 
00549
00550 template <class  ValueTypeT,
00551           UInt32 SizeI      > inline
00552 Point<ValueTypeT, SizeI>::Point(const ValueTypeT rVal1,
00553                                 const ValueTypeT rVal2,
00554                                 const ValueTypeT rVal3) :
00555     Inherited()
00556 {
00557     Self::_values[0] = rVal1;
00558
00559     if(Self::_uiSize == 2)
00560     {
00561         Self::_values[1] = rVal2;
00562     }
00563     else if(Self::_uiSize == 3)
00564     {
00565         Self::_values[1] = rVal2;
00566         Self::_values[2] = rVal3;
00567     }
00568     else if(Self::_uiSize >= 4)
00569     {
00570         Self::_values[1] = rVal2;
00571         Self::_values[2] = rVal3;
00572
00573         for(UInt32 i = 3; i < Self::_uiSize; i++)
00574         {
00575             Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00576         }
00577     }
00578 }
00579
00580 #ifdef __sgi
00581 #pragma reset woff 1209
00582 
00583 #pragma set woff 1209
00584 #endif
00585 
00587
00588 template <class  ValueTypeT,
00589           UInt32 SizeI      > inline
00590 Point<ValueTypeT, SizeI>::Point(const ValueTypeT rVal1,
00591                                 const ValueTypeT rVal2,
00592                                 const ValueTypeT rVal3,
00593                                 const ValueTypeT rVal4 ) :
00594     Inherited()
00595 {
00596     Self::_values[0] = rVal1;
00597
00598     if(Self::_uiSize == 2)
00599     {
00600         Self::_values[1] = rVal2;
00601     }
00602     else if(Self::_uiSize == 3)
00603     {
00604         Self::_values[1] = rVal2;
00605         Self::_values[2] = rVal3;
00606     }
00607     else if(Self::_uiSize == 4)
00608     {
00609         Self::_values[1] = rVal2;
00610         Self::_values[2] = rVal3;
00611         Self::_values[3] = rVal4;
00612     }
00613     else if(Self::_uiSize >= 5)
00614     {
00615         Self::_values[1] = rVal2;
00616         Self::_values[2] = rVal3;
00617         Self::_values[3] = rVal4;
00618
00619         for(UInt32 i = 4; i < Self::_uiSize; i++)
00620         {
00621             Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00622         }
00623     }
00624 }
00625
00626 #ifdef __sgi
00627 #pragma reset woff 1209
00628 #endif
00629 
00630 /*-------------------------------------------------------------------------*/
00631 /*                             Destructor                                  */
00632
00633 template <class  ValueTypeT,
00634           UInt32 SizeI      > inline
00635 Point<ValueTypeT, SizeI>::~Point(void)
00636 {
00637 }
00638
00639 /*-------------------------------------------------------------------------*/
00640 /*                                Set                                      */
00641
00642 template <class  ValueTypeT,
00643           UInt32 SizeI      > inline
00644 void Point<ValueTypeT, SizeI>::setNull(void)
00645 {
00646     for(UInt32 i = 0; i < Self::_uiSize; i++)
00647     {
00648         Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00649     }
00650 }
00651
00652 template <class  ValueTypeT,
00653           UInt32 SizeI      > inline
00654 void Point<ValueTypeT, SizeI>::setValue(const Point &pnt)
00655 {
00656     for(UInt32 i = 0; i < Self::_uiSize; i++)
00657     {
00658         Self::_values[i] = pnt._values[i];
00659     }
00660 }
00661
00662 template <class  ValueTypeT,
00663           UInt32 SizeI       >
00664 template <class  ValueType2T,
00665           UInt32 Size2I      > inline
00666 void Point<ValueTypeT, SizeI>::setValue(const Point<ValueType2T, Size2I> &pnt)
00667 {
00668     typedef Point<ValueType2T, Size2I> Point2T;
00669
00670     static const UInt32 nElementsToCopy =
00671         Self::_uiSize < Point2T::_uiSize ? Self::_uiSize : Point2T::_uiSize;
00672
00673     for(UInt32 i = 0; i < nElementsToCopy; ++i)
00674     {
00675         Self::_values[i] = pnt.getValues()[i];
00676     }
00677 }
00678
00679 template <class  ValueTypeT,
00680           UInt32 SizeI      > inline
00681 void Point<ValueTypeT, SizeI>::setValue(const ValueType *pVals)
00682 {
00683     for(UInt32 i = 0; i < Self::_uiSize; i++)
00684     {
00685         Self::_values[i] = pVals[i];
00686     }
00687 }
00688
00690
00691 template <class  ValueTypeT,
00692           UInt32 SizeI      > inline
00693 void Point<ValueTypeT, SizeI>::setValue(ValueType *pVals)
00694 {
00695     setValue(static_cast<const ValueType *>(pVals));
00696 }
00697
00702 template <class  ValueTypeT,
00703           UInt32 SizeI      > inline
00704 void Point<ValueTypeT, SizeI>::setValueFromCString(const Char8 *szString)
00705 {
00706     UInt32 i;
00707     UInt32 numOfToken = Self::_uiSize;
00708
00709     Char8 *c      = const_cast<Char8 *>(szString);
00710     Char8 *tokenC = 0;
00711
00712     Char8  token[256];
00713
00714     if(szString == NULL || (*szString) == '\0')
00715     {
00716         for(i = 0; i < Self::_uiSize; i++)
00717             Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00718
00719         return;
00720     }
00721
00722     for (i = 0; i < numOfToken; c++)
00723     {
00724         switch (*c)
00725         {
00726             case '\0':
00727                 if(tokenC)
00728                 {
00729                     *tokenC = 0;
00730                     Self::_values[i++] =
00731                         TypeTraits<ValueTypeT>::getFromCString(token);
00732                 }
00733
00734                 while (i < numOfToken)
00735                 {
00736                     Self::_values[i++] =
00737                         TypeTraits<ValueTypeT>::getZeroElement();
00738                 }
00739                 break;
00740
00741             case ' ' :
00742             case '\t':
00743             case '\n':
00744             case ',':
00745                 if(tokenC)
00746                 {
00747                     *tokenC = 0;
00748                     Self::_values[i++] =
00749                         TypeTraits<ValueTypeT>::getFromCString(token);
00750                     tokenC = 0;
00751                 }
00752                 break;
00753             default:
00754                 if(!tokenC)
00755                 {
00756                     tokenC = token;
00757                 }
00758                 *tokenC++ = *c;
00759                 break;
00760         }
00761     }
00762 }
00763
00768 template <class  ValueTypeT,
00769           UInt32 SizeI      > inline
00770 void Point<ValueTypeT, SizeI>::setValueFromCString(Char8 *szString)
00771 {
00772     setValueFromCString(static_cast<const Char8 *>(szString));
00773 }
00774
00775 #ifndef OSG_DISABLE_DEPRECATED
00776 template <class  ValueTypeT,
00777           UInt32 SizeI      > inline
00778 void Point<ValueTypeT, SizeI>::setValue(const Char8 *szString)
00779 {
00780     setValueFromCString(szString);
00781 }
00782
00783 template <class  ValueTypeT,
00784           UInt32 SizeI      > inline
00785 void Point<ValueTypeT, SizeI>::setValue(Char8 *szString)
00786 {
00787     setValueFromCString(szString);
00788 }
00789 #endif
00790 
00791 /*-------------------------------------------------------------------------*/
00792 /*                                Get                                      */
00793
00795
00796 template <class  ValueTypeT,
00797           UInt32 SizeI      > inline
00798 ValueTypeT *Point<ValueTypeT, SizeI>::getValues(void)
00799 {
00800     return Self::_values;
00801 }
00802
00804
00805 template <class  ValueTypeT,
00806           UInt32 SizeI      > inline
00807 const ValueTypeT *Point<ValueTypeT, SizeI>::getValues(void) const
00808 {
00809     return Self::_values;
00810 }
00811
00812 /*-------------------------------------------------------------------------*/
00813 /*                        Common Math                                      */
00814
00816
00817 template <class  ValueTypeT,
00818           UInt32 SizeI      > inline
00819 bool Point<ValueTypeT, SizeI>::isZero(void) const
00820 {
00821     bool returnValue = true;
00822
00823     for(UInt32 i = 0; i < Self::_uiSize; i++)
00824     {
00825         returnValue &= ((Self::_values[i] <=  Eps) &&
00826                         (Self::_values[i] >= -Eps));
00827     }
00828
00829     return returnValue;
00830 }
00831
00833
00834 template <class  ValueTypeT,
00835           UInt32 SizeI      > inline
00836 void Point<ValueTypeT, SizeI>::negate(void)
00837 {
00838     for(UInt32 i = 0; i < Self::_uiSize; i++)
00839     {
00840         Self::_values[i] = -Self::_values[i];
00841     }
00842 }
00843
00845
00846 template <class  ValueTypeT,
00847           UInt32 SizeI      > inline
00848 bool Point<ValueTypeT, SizeI>::equals(
00849     const Point      &pnt,
00850     const ValueType   tolerance) const
00851 {
00852     bool returnValue = true;
00853
00854     for(UInt32 i = 0; i < Self::_uiSize; i++)
00855     {
00856         returnValue &=
00857             ( (Self::_values[i] - pnt  ._values[i] <= tolerance) &&
00858               (pnt  ._values[i] - Self::_values[i] <= tolerance));
00859     }
00860
00861     return returnValue;
00862 }
00863
00865
00866 template <class  ValueTypeT,
00867           UInt32 SizeI      > inline
00868 typename Point<ValueTypeT, SizeI>::VectorType &
00869     Point<ValueTypeT, SizeI>::subZero(void)
00870 {
00871     return *(static_cast<VectorType *>(this));
00872 }
00873
00875
00876 template <class  ValueTypeT,
00877           UInt32 SizeI      > inline
00878 const typename Point<ValueTypeT, SizeI>::VectorType &
00879     Point<ValueTypeT, SizeI>::subZero(void) const
00880 {
00881     return *(static_cast<const VectorType *>(this));
00882 }
00883
00884
00886
00887 template <class  ValueTypeT,
00888           UInt32 SizeI      > inline
00889 typename Point<ValueTypeT, SizeI>::RealReturnType
00890     Point<ValueTypeT, SizeI>::dist(const Point &pnt) const
00891 {
00892     return osgSqrt(dist2(pnt));
00893 }
00894
00896
00897 template <class  ValueTypeT,
00898           UInt32 SizeI      > inline
00899 typename Point<ValueTypeT, SizeI>::RealReturnType
00900     Point<ValueTypeT, SizeI>::dist2(const Point &pnt) 
00901     const
00902 {
00903     RealReturnType returnValue = 0;
00904     RealReturnType tmp;
00905
00906     for(UInt32 i = 0; i < Self::_uiSize; i++)
00907     {
00908         tmp = Self::_values[i] - pnt._values[i];
00909
00910         returnValue += tmp * tmp;
00911     }
00912
00913     return returnValue;
00914 }
00915
00917
00918 template <class  ValueTypeT,
00919           UInt32 SizeI      > inline
00920 typename Point<ValueTypeT, SizeI>::RealReturnType
00921     Point<ValueTypeT, SizeI>::maxValue(void) const
00922 {
00923     RealReturnType returnValue = TypeTraits<RealReturnType>::getMin();
00924
00925     for(UInt32 i = 0; i < Self::_uiSize; i++)
00926     {
00927         if(Self::_values[i] > returnValue)
00928             returnValue = Self::_values[i];
00929     }
00930
00931     return returnValue;
00932 }
00933
00934 /*-------------------------------------------------------------------------*/
00935 /*                                Math                                     */
00936
00938
00939 template <class  ValueTypeT,
00940           UInt32 SizeI      > inline
00941 void Point<ValueTypeT, SizeI>::operator *=(const ValueType val)
00942 {
00943     for(UInt32 i = 0; i < Self::_uiSize; i++)
00944     {
00945         Self::_values[i] *= val;
00946     }
00947 }
00948
00950
00951 template <class  ValueTypeT,
00952           UInt32 SizeI      > inline
00953 void Point<ValueTypeT, SizeI>::operator /=(const ValueType  val)
00954 {
00955     for(UInt32 i = 0; i < Self::_uiSize; i++)
00956     {
00957         Self::_values[i] /= val;
00958     }
00959 }
00960
00961
00963
00964 template <class  ValueTypeT,
00965           UInt32 SizeI      > inline
00966 typename Point<ValueTypeT, SizeI>::VectorType
00967     Point<ValueTypeT, SizeI>::operator -(const Point &pnt) const
00968 {
00969     VectorType returnValue(*this);
00970
00971     for(UInt32 i = 0; i < Self::_uiSize; i++)
00972     {
00973         returnValue[i] -= pnt[i];
00974     }
00975
00976     return returnValue;
00977 }
00978
00980
00981 template <class  ValueTypeT,
00982           UInt32 SizeI      > inline
00983 Point<ValueTypeT, SizeI>
00984     Point<ValueTypeT, SizeI>::operator + (const VectorType &vec) const
00985 {
00986     Point<ValueTypeT, SizeI> returnValue;
00987
00988     for(UInt32 i = 0; i < Self::_uiSize; i++)
00989     {
00990         returnValue[i] = Self::_values[i] + vec[i];
00991     }
00992
00993     return returnValue;
00994 }
00995
00997
00998 template <class  ValueTypeT,
00999           UInt32 SizeI      > inline
01000 Point<ValueTypeT, SizeI>
01001     Point<ValueTypeT, SizeI>::operator - (const VectorType &vec) const
01002 {
01003     Point<ValueTypeT, SizeI> returnValue;
01004
01005     for(UInt32 i = 0; i < Self::_uiSize; i++)
01006     {
01007         returnValue[i] = Self::_values[i] - vec[i];
01008     }
01009
01010     return returnValue;
01011 }
01012
01014
01015 template <class  ValueTypeT,
01016           UInt32 SizeI      > inline
01017 Point <ValueTypeT, SizeI>
01018     Point<ValueTypeT, SizeI>::operator * (const ValueType rVal) const
01019 {
01020     Point<ValueTypeT, SizeI> returnValue;
01021
01022     for(UInt32 i = 0; i < Self::_uiSize; i++)
01023     {
01024         returnValue[i] = Self::_values[i] * rVal;
01025     }
01026
01027     return returnValue;
01028 }
01029
01031
01032 template <class  ValueTypeT,
01033           UInt32 SizeI      > inline
01034 Point<ValueTypeT, SizeI>
01035     Point<ValueTypeT, SizeI>::operator -(void)
01036 {
01037     Point<ValueTypeT, SizeI> returnValue;
01038
01039     for(UInt32 i = 0; i < Self::_uiSize; i++)
01040     {
01041         returnValue._values[i] = - Self::_values[i];
01042     }
01043
01044     return returnValue;
01045 }
01046
01048
01049 template <class  ValueTypeT,
01050           UInt32 SizeI      > inline
01051 void Point<ValueTypeT, SizeI>::operator +=(const VectorType &vec)
01052 {
01053     for(UInt32 i = 0; i < Self::_uiSize; i++)
01054     {
01055         Self::_values[i] += vec._values[i];
01056     }
01057 }
01058
01060
01061 template <class  ValueTypeT,
01062           UInt32 SizeI      > inline
01063 void Point<ValueTypeT, SizeI>::operator -=(const VectorType &vec)
01064 {
01065     for(UInt32 i = 0; i < Self::_uiSize; i++)
01066     {
01067         Self::_values[i] -= vec._values[i];
01068     }
01069 }
01070
01071 /*-------------------------------------------------------------------------*/
01072 /*                          Element Access                                 */
01073
01074 template <class  ValueTypeT,
01075           UInt32 SizeI      > inline
01076 ValueTypeT &Point<ValueTypeT, SizeI>::operator[](const UInt32 uiVal)
01077 {
01078     return Self::_values[uiVal];
01079 }
01080
01081 template <class  ValueTypeT,
01082           UInt32 SizeI      > inline
01083 const ValueTypeT &
01084     Point<ValueTypeT, SizeI>::operator[](const UInt32 uiVal) const
01085 {
01086     return Self::_values[uiVal];
01087 }
01088
01089 /*-------------------------------------------------------------------------*/
01090 /*                             Assignment                                  */
01091
01092 template <class  ValueTypeT,
01093           UInt32 SizeI      > inline
01094 Point<ValueTypeT, SizeI> &
01095     Point<ValueTypeT, SizeI>::operator =(const Point &source)
01096 {
01097     if(this == &source)
01098         return *this;
01099
01100     for(UInt32 i = 0; i < Self::_uiSize; i++)
01101     {
01102         Self::_values[i] = source._values[i];
01103     }
01104
01105     return *this;
01106 }
01107
01108 template <class  ValueTypeT,
01109           UInt32 SizeI      > inline
01110 Point<ValueTypeT, SizeI> &
01111     Point<ValueTypeT, SizeI>::operator =(const VectorType &source)
01112 {
01113     Point<ValueTypeT, SizeI>::error_cannot_assign_vector;
01114
01115     return *this;
01116 }
01117
01118 /*-------------------------------------------------------------------------*/
01119 /*                             Comparison                                  */
01120
01121 template <class  ValueTypeT,
01122           UInt32 SizeI      > inline
01123 bool Point<ValueTypeT, SizeI>::operator < (const Point &other) const
01124 {
01125     bool ret = false;
01126
01127     for(UInt32 i = 0; i < Self::_uiSize; i++)
01128     {
01129         if(Self::_values[i] > other._values[i])
01130         {
01131             break;
01132         }
01133
01134         if(Self::_values[i] < other._values[i])
01135         {
01136             ret = true;
01137             break;
01138         }
01139     }
01140
01141     return ret;
01142 }
01143
01145
01146 template <class  ValueTypeT,
01147           UInt32 SizeI      > inline
01148 bool Point<ValueTypeT, SizeI>::operator == (const Point &other) const
01149 {
01150     return Self::equals(other, ValueTypeT(Eps));
01151 }
01152
01154
01155 template <class  ValueTypeT,
01156           UInt32 SizeI      > inline
01157 bool Point<ValueTypeT, SizeI>::operator != (const Point &other) const
01158 {
01159     return ! (*this == other);
01160 }
01161
01162 /*-------------------------------------------------------------------------*/
01163 /*                               Functions                                 */
01164
01166
01167 template <class  ValueTypeT,
01168           UInt32 SizeI      > inline
01169 Point<ValueTypeT, SizeI>
01170     operator *(const ValueTypeT                val,
01171                const Point<ValueTypeT, SizeI> &pnt )
01172 {
01173     Point<ValueTypeT, SizeI> returnValue;
01174
01175     for(UInt32 i = 0; i < Point<ValueTypeT, SizeI>::_uiSize; i++)
01176     {
01177         returnValue[i] = pnt[i] * val;
01178     }
01179
01180     return returnValue;
01181 }
01182
01184 /*
01185 template <class  ValueTypeT,
01186           UInt32 SizeI      > inline
01187 std::ostream &operator <<(      std::ostream             &os,
01188                           const Point<ValueTypeT, SizeI> &pnt)
01189 {
01190     for(UInt32 i = 0; i < Point<ValueTypeT, SizeI>::_uiSize; i++)
01191     {
01192         os << pnt[i];
01193 
01194         if(i != Point<ValueTypeT, SizeI>::_uiSize - 1)
01195             os << ", ";
01196     }
01197 
01198     return os;
01199 }*/
01200
01201
01203 //  as ASCII characters
01204 /*
01205 template <UInt32 SizeI> inline
01206 std::ostream &operator <<(      std::ostream        &os,
01207                           const Point<UInt8, SizeI> &pnt)
01208 {
01209     for(UInt32 i = 0; i < Point<UInt8, SizeI>::_uiSize; i++)
01210     {
01211         os << static_cast<UInt16>(pnt[i]);
01212 
01213         if(i != Point<UInt8, SizeI>::_uiSize - 1)
01214             os << ", ";
01215     }
01216 
01217     return os;
01218 }
01219 
01220 template <UInt32 SizeI> inline
01221 std::ostream &operator <<(      std::ostream       &os,
01222                           const Point<Int8, SizeI> &pnt)
01223 {
01224     for(UInt32 i = 0; i < Point<Int8, SizeI>::_uiSize; i++)
01225     {
01226         os << static_cast<Int16>(pnt[i]);
01227 
01228         if(i != Point<Int8, SizeI>::_uiSize - 1)
01229             os << ", ";
01230     }
01231 
01232     return os;
01233 }*/
01234
01235
01236 //---------------------------------------------------------------------------
01237 //  Class
01238 //---------------------------------------------------------------------------
01239
01252 template <class  ValueTypeT,
01253           UInt32 SizeI      >
01254 const Vector<ValueTypeT, SizeI>  Vector<ValueTypeT, SizeI>::Null;
01255
01256 /*-------------------------------------------------------------------------*/
01257 /*                            Constructors                                 */
01258
01259 template <class  ValueTypeT,
01260           UInt32 SizeI      > inline
01261 Vector<ValueTypeT, SizeI>::Vector(void) :
01262     Inherited()
01263 {
01264     for(UInt32 i = 0; i < Self::_uiSize; i++)
01265     {
01266         Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
01267     }
01268 }
01269
01270
01276 template <class  ValueTypeT,
01277           UInt32 SizeI      > inline
01278 Vector<ValueTypeT, SizeI>::Vector(const ValueTypeT *pVals) :
01279     Inherited(pVals)
01280 {
01281 }
01282
01288 template <class  ValueTypeT,
01289           UInt32 SizeI      > inline
01290 Vector<ValueTypeT, SizeI>::Vector(ValueTypeT *pVals) :
01291     Inherited(pVals)
01292 {
01293 }
01294
01295 template <class  ValueTypeT,
01296           UInt32 SizeI       >
01297 template <class  ValueType2T,
01298           UInt32 Size2I      > inline
01299 Vector<ValueTypeT, SizeI>::Vector(const Point<ValueType2T, Size2I> &pnt) :
01300
01301     Inherited(pnt)
01302 {
01303 }
01304
01305 template <class  ValueTypeT,
01306           UInt32 SizeI       >
01307 template <class  ValueType2T,
01308           UInt32 Size2I      > inline
01309 Vector<ValueTypeT, SizeI>::Vector(const Vector<ValueType2T, Size2I> &vec) :
01310
01311     Inherited(vec)
01312 {
01313 }
01314
01315
01316 template <class  ValueTypeT,
01317           UInt32 SizeI      > inline
01318 Vector<ValueTypeT, SizeI>::Vector(const Vector &source) :
01319
01320     Inherited(source)
01321 {
01322 }
01323
01324 template <class  ValueTypeT,
01325           UInt32 SizeI      > inline
01326 Vector<ValueTypeT, SizeI>::Vector(const ValueType rVal1)
01327 {
01328     UInt32 i;
01329
01330     Self::_values[0] = rVal1;
01331
01332     for(i = 1; i < Self::_uiSize; i++)
01333     {
01334         Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
01335     }
01336 }
01337
01338 template <class  ValueTypeT,
01339           UInt32 SizeI      > inline
01340 Vector<ValueTypeT, SizeI>::Vector(const ValueType rVal1,
01341                                   const ValueType rVal2) :
01342
01343     Inherited(rVal1, rVal2)
01344 {
01345 }
01346
01347 template <class  ValueTypeT,
01348           UInt32 SizeI      > inline
01349 Vector<ValueTypeT, SizeI>::Vector(const ValueType rVal1,
01350                                   const ValueType rVal2,
01351                                   const ValueType rVal3) :
01352
01353     Inherited(rVal1, rVal2, rVal3)
01354 {
01355 }
01356
01357 template <class  ValueTypeT,
01358           UInt32 SizeI      > inline
01359 Vector<ValueTypeT, SizeI>::Vector(const ValueType rVal1,
01360                                   const ValueType rVal2,
01361                                   const ValueType rVal3,
01362                                   const ValueType rVal4) :
01363
01364     Inherited(rVal1, rVal2, rVal3, rVal4)
01365 {
01366 }
01367
01368
01369 /*-------------------------------------------------------------------------*/
01370 /*                             Destructor                                  */
01371
01372 template <class  ValueTypeT,
01373           UInt32 SizeI      > inline
01374 Vector<ValueTypeT, SizeI>::~Vector(void)
01375 {
01376 }
01377
01378 /*-------------------------------------------------------------------------*/
01379 /*                          Common Math                                    */
01380
01382
01383 template <class  ValueTypeT,
01384           UInt32 SizeI      > inline
01385 typename Vector<ValueTypeT, SizeI>::RealReturnType
01386     Vector<ValueTypeT, SizeI>::squareLength(void) const
01387 {
01388     RealReturnType rTmpVal = RealReturnType(Self::_values[0] *
01389                                             Self::_values[0] );
01390
01391     for(UInt32 i = 1; i < Self::_uiSize; i++)
01392     {
01393         rTmpVal += Self::_values[i] * Self::_values[i];
01394     }
01395
01396     return rTmpVal;
01397 }
01398
01400
01401 template <class  ValueTypeT,
01402           UInt32 SizeI      > inline
01403 typename Vector<ValueTypeT, SizeI>::RealReturnType
01404     Vector<ValueTypeT, SizeI>::length(void) const
01405 {
01406     return osgSqrt(Self::squareLength());
01407 }
01408
01409
01411
01412 template <class  ValueTypeT,
01413           UInt32 SizeI      > inline
01414 void Vector<ValueTypeT, SizeI>::normalize(void)
01415 {
01416     ValueTypeT rLength = ValueTypeT(length());
01417
01418     if(osgAbs(rLength) < Eps)
01419     {
01420         rLength = TypeTraits<ValueTypeT>::getOneElement();
01421     }
01422     else
01423     {
01424         rLength = TypeTraits<ValueTypeT>::getOneElement() / rLength;
01425     }
01426
01427     for(UInt32 i = 0; i < Self::_uiSize; i++)
01428     {
01429         Self::_values[i] *= rLength;
01430     }
01431 }
01432
01433 #ifdef __sgi
01434 #pragma set woff 1209
01435 #endif
01436 
01441 template <class  ValueTypeT,
01442           UInt32 SizeI      > inline
01443 Vector<ValueTypeT, SizeI>
01444     Vector<ValueTypeT, SizeI>::cross(const Vector &vec) const
01445 {
01446     Vector<ValueTypeT, SizeI> returnValue;
01447
01448     if(Self::_uiSize >= 3)
01449     {
01450         returnValue[0] =
01451             Self::_values[1] * vec._values[2] -
01452             Self::_values[2] * vec._values[1];
01453         returnValue[1] =
01454             Self::_values[2] * vec._values[0] -
01455             Self::_values[0] * vec._values[2];
01456         returnValue[2] =
01457             Self::_values[0] * vec._values[1] -
01458             Self::_values[1] * vec._values[0];
01459     }
01460     else
01461     {
01462         // Must be changed
01463         fprintf(stderr, "cross only implemented for size 3\n");
01464     }
01465
01466     return returnValue;
01467 }
01468
01469 template <class  ValueTypeT,
01470           UInt32 SizeI      > inline
01471 Vector<ValueTypeT, SizeI>
01472     Vector<ValueTypeT, SizeI>::operator % (const Vector &vec) const
01473 {
01474     return this->cross(vec);
01475 }
01476
01481 template <class  ValueTypeT,
01482           UInt32 SizeI      > inline
01483 void Vector<ValueTypeT, SizeI>::crossThis(const Vector &vec)
01484 {
01485     if(Self::_uiSize >= 3)
01486     {
01487         ValueTypeT rTmp[2];
01488
01489         rTmp[0] =
01490             Self::_values[1] * vec._values[2] -
01491             Self::_values[2] * vec._values[1];
01492         rTmp[1] =
01493             Self::_values[2] * vec._values[0] -
01494             Self::_values[0] * vec._values[2];
01495
01496         Self::_values[2] =
01497             Self::_values[0] * vec._values[1] -
01498             Self::_values[1] * vec._values[0];
01499
01500         Self::_values[0] = rTmp[0];
01501         Self::_values[1] = rTmp[1];
01502     }
01503     else
01504     {
01505         // Must be changed
01506         fprintf(stderr, "crossThis only available for size 3\n");
01507     }
01508 }
01509
01510 #ifdef __sgi
01511 #pragma reset woff 1209
01512 #endif
01513 
01515
01516 template <class  ValueTypeT,
01517           UInt32 SizeI      > inline
01518 ValueTypeT Vector<ValueTypeT, SizeI>::dot(const Vector &vec) const
01519 {
01520     ValueTypeT rTmpVal = Self::_values[0] * vec._values[0];
01521
01522     for(UInt32 i = 1; i < Self::_uiSize; i++)
01523     {
01524         rTmpVal += Self::_values[i] * vec._values[i];
01525     }
01526
01527     return rTmpVal;
01528 }
01529
01530 template <class  ValueTypeT,
01531           UInt32 SizeI      > inline
01532 ValueTypeT Vector<ValueTypeT, SizeI>::operator * (const Vector &vec) const
01533 {
01534     return this->dot(vec);
01535 }
01536
01537 template <class  ValueTypeT,
01538           UInt32 SizeI      > inline
01539 ValueTypeT Vector<ValueTypeT, SizeI>::dot (const PointType &pnt) const
01540 {
01541     ValueTypeT rTmpVal = Self::_values[0] * pnt[0];
01542
01543     for(UInt32 i = 1; i < Self::_uiSize; i++)
01544     {
01545         rTmpVal += Self::_values[i] * pnt[i];
01546     }
01547
01548     return rTmpVal;
01549 }
01550
01551 template <class  ValueTypeT,
01552           UInt32 SizeI      > inline
01553 ValueTypeT Vector<ValueTypeT, SizeI>::operator * (const PointType &pnt) const
01554 {
01555      return this->dot(pnt);
01556 }
01557
01559
01560 template <class  ValueTypeT,
01561           UInt32 SizeI      > inline
01562 typename Vector<ValueTypeT, SizeI>::RealReturnType
01563      Vector<ValueTypeT, SizeI>::enclosedAngle(const Vector &vec) const
01564 {
01565     RealReturnType returnValue;
01566
01567     if(Self::isZero() || vec.isZero())
01568     {
01569         returnValue = TypeTraits<RealReturnType>::getZeroElement();
01570     }
01571     else
01572     {
01573         returnValue  = dot(vec);
01574         returnValue /= (length() * vec.length());
01575
01576         if((returnValue - Eps) < -1.)
01577         {
01578             returnValue = Pi;
01579         }
01580         else if((returnValue + Eps) > 1.)
01581         {
01582             returnValue = TypeTraits<RealReturnType>::getZeroElement();
01583         }
01584         else
01585         {
01586             returnValue = osgACos(returnValue);
01587         }
01588     }
01589
01590     return returnValue;
01591 }
01592
01593 template <class  ValueTypeT,
01594           UInt32 SizeI      > inline
01595 typename Vector<ValueTypeT, SizeI>::RealReturnType
01596     Vector<ValueTypeT, SizeI>::projectTo(const Vector &toVec)
01597 {
01598     RealReturnType rDot       = this ->dot(toVec);
01599     RealReturnType rSquareDot = toVec .dot(toVec);
01600
01601     if(rSquareDot > Eps)
01602     {
01603         rDot /= rSquareDot;
01604
01605         if(osgAbs(rDot) > Eps)
01606         {
01607             *this  = toVec;
01608             *this *= ValueTypeT(rDot);
01609         }
01610         else
01611         {
01612             this->setNull();
01613             rDot = TypeTraits<RealReturnType>::getZeroElement();
01614         }
01615     }
01616     else
01617     {
01618         rDot = TypeTraits<RealReturnType>::getOneElement();
01619     }
01620
01621     return rDot;
01622 }
01623
01625
01626 template <class  ValueTypeT,
01627           UInt32 SizeI      > inline
01628 const typename Vector<ValueTypeT, SizeI>::PointType &
01629     Vector<ValueTypeT, SizeI>::addToZero(void) const
01630 {
01631     return *(static_cast<const PointType *>(this));
01632 }
01633
01635
01636 template <class  ValueTypeT,
01637           UInt32 SizeI      > inline
01638 typename Vector<ValueTypeT, SizeI>::PointType &
01639     Vector<ValueTypeT, SizeI>::addToZero(void)
01640 {
01641     return *(static_cast<PointType *>(this));
01642 }
01643
01644 template <class  ValueTypeT,
01645           UInt32 SizeI      > inline
01646 Vector<ValueTypeT, SizeI> &
01647     Vector<ValueTypeT, SizeI>::subZero(void)
01648 {
01649     return *this;
01650 }
01651
01652 template <class  ValueTypeT,
01653           UInt32 SizeI      > inline
01654 const Vector<ValueTypeT, SizeI> &
01655     Vector<ValueTypeT, SizeI>::subZero(void) const
01656 {
01657     return (*this);
01658 }
01659
01660 /*-------------------------------------------------------------------------*/
01661 /*                                Math                                     */
01662
01664
01665 template <class  ValueTypeT,
01666           UInt32 SizeI      > inline
01667 Vector <ValueTypeT, SizeI>
01668     Vector<ValueTypeT, SizeI>::operator - (const Vector &vec) const
01669 {
01670     Vector<ValueTypeT, SizeI> returnValue;
01671
01672     for(UInt32 i = 0; i < Self::_uiSize; i++)
01673     {
01674         returnValue[i] = Self::_values[i] - vec[i];
01675     }
01676
01677     return returnValue;
01678 }
01679
01681
01682 template <class  ValueTypeT,
01683           UInt32 SizeI      > inline
01684 Vector <ValueTypeT, SizeI>
01685     Vector<ValueTypeT, SizeI>::operator + (const Vector &vec) const
01686 {
01687     Vector<ValueTypeT, SizeI> returnValue;
01688
01689     for(UInt32 i = 0; i < Self::_uiSize; i++)
01690     {
01691         returnValue[i] = Self::_values[i] + vec[i];
01692     }
01693
01694     return returnValue;
01695 }
01696
01697
01699
01700 template <class  ValueTypeT,
01701           UInt32 SizeI      > inline
01702 Vector <ValueTypeT, SizeI>
01703     Vector<ValueTypeT, SizeI>::operator * (const ValueType rVal) const
01704 {
01705     Vector<ValueTypeT, SizeI> returnValue;
01706
01707     for(UInt32 i = 0; i < Self::_uiSize; i++)
01708     {
01709         returnValue[i] = Self::_values[i] * rVal;
01710     }
01711
01712     return returnValue;
01713 }
01714
01716
01717 template <class  ValueTypeT,
01718           UInt32 SizeI      > inline
01719 Vector<ValueTypeT, SizeI>
01720     Vector<ValueTypeT, SizeI>::operator -(void) const
01721 {
01722     Vector<ValueTypeT, SizeI> returnValue;
01723
01724     for(UInt32 i = 0; i < Self::_uiSize; i++)
01725     {
01726         returnValue._values[i] = - Self::_values[i];
01727     }
01728
01729     return returnValue;
01730 }
01731
01732 /*-------------------------------------------------------------------------*/
01733 /*                             Assignment                                  */
01734
01735 template <class  ValueTypeT,
01736           UInt32 SizeI      > inline
01737 Vector<ValueTypeT, SizeI> &
01738     Vector<ValueTypeT, SizeI>::operator =(const Vector &source)
01739 {
01740     if(this == &source)
01741         return *this;
01742
01743     *(static_cast<Inherited *>(this)) =
01744         static_cast<const Inherited &>(source);
01745
01746     return *this;
01747 }
01748
01749 /*-------------------------------------------------------------------------*/
01750 /*                             Comparison                                  */
01751
01752 template <class  ValueTypeT,
01753           UInt32 SizeI      > inline
01754 bool Vector<ValueTypeT, SizeI>::operator < (const Vector &other) const
01755 {
01756     bool ret = false;
01757
01758     for(UInt32 i = 0; i < Self::_uiSize; i++)
01759     {
01760         if(Self::_values[i] > other._values[i])
01761         {
01762             break;
01763         }
01764         if(Self::_values[i] < other._values[i])
01765         {
01766             ret = true;
01767             break;
01768         }
01769     }
01770
01771     return ret;
01772 }
01773
01775
01776 template <class  ValueTypeT,
01777           UInt32 SizeI      > inline
01778 bool Vector<ValueTypeT, SizeI>::operator == (const Vector &other) const
01779 {
01780     return Self::equals(other, ValueTypeT(Eps));
01781 }
01782
01784
01785 template <class  ValueTypeT,
01786           UInt32 SizeI      > inline
01787 bool Vector<ValueTypeT, SizeI>::operator != (const Vector &other) const
01788 {
01789     return ! (*this == other);
01790 }
01791
01792 /*-------------------------------------------------------------------------*/
01793 /*                               Functions                                 */
01794
01796
01797 template <class  ValueTypeT,
01798           UInt32 SizeI      > inline
01799 Vector<ValueTypeT, SizeI>
01800     operator *(const ValueTypeT                 val,
01801                const Vector<ValueTypeT, SizeI> &vec )
01802 {
01803     Vector<ValueTypeT, SizeI> returnValue;
01804
01805     for(UInt32 i = 0; i < Vector<ValueTypeT, SizeI>::_uiSize; i++)
01806     {
01807         returnValue[i] = vec[i] * val;
01808     }
01809
01810     return returnValue;
01811 }
01812
01813 OSG_END_NAMESPACE