library of assembled shared sources

http://lass.cocamware.com

vector_2d.h

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 
00044 
00045 /** @struct lass::prim::Vector2D
00046  *  @brief 2D Vector
00047  *  @author BdG
00048  *  @date 2003
00049  */
00050 
00051 
00052 
00053 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_VECTOR_2D_H
00054 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_VECTOR_2D_H
00055 
00056 
00057 
00058 
00059 #include "prim_common.h"
00060 #include "../io/xml_o_stream.h"
00061 
00062 
00063 
00064 namespace lass
00065 {
00066 
00067 namespace prim
00068 {
00069 
00070 template<typename T>
00071 struct Vector2D
00072 {
00073     typedef Vector2D<T> TSelf;
00074 
00075     typedef typename util::CallTraits<T>::TValue TValue;
00076     typedef typename util::CallTraits<T>::TParam TParam;
00077     typedef typename util::CallTraits<T>::TReference TReference;
00078     typedef typename util::CallTraits<T>::TConstReference TConstReference;
00079     typedef typename num::NumTraits<T> TNumTraits;
00080 
00081     enum { dimension = 2 }; /**< number of dimensions of vector */
00082 
00083     template <typename U> struct Rebind
00084     {
00085         typedef Vector2D<U> Type;
00086     };
00087 
00088 
00089     // public data
00090 
00091     TValue x;
00092     TValue y;
00093 
00094 
00095     // methods
00096 
00097     Vector2D();
00098     Vector2D(TParam x, TParam y);
00099     template <typename U> explicit Vector2D(const Vector2D<U>& other);
00100     template <typename U> Vector2D(const U& x, const U& y);
00101 
00102     typename Vector2D::TConstReference operator[](size_t index) const;
00103     typename Vector2D::TReference operator[](size_t index);
00104     typename Vector2D::TConstReference at(signed index) const;
00105     typename Vector2D::TReference at(signed index);
00106 
00107     const Vector2D<T>& operator+() const;
00108     const Vector2D<T> operator-() const;
00109     Vector2D<T>& operator+=(const Vector2D<T>& other);
00110     Vector2D<T>& operator-=(const Vector2D<T>& other);
00111     Vector2D<T>& operator*=(const Vector2D<T>& other);
00112     Vector2D<T>& operator/=(const Vector2D<T>& other);
00113     Vector2D<T>& operator+=(TParam other);
00114     Vector2D<T>& operator-=(TParam other);
00115     Vector2D<T>& operator*=(TParam other);
00116     Vector2D<T>& operator/=(TParam other);
00117 
00118     const bool isZero() const;
00119     const bool isNaN() const;
00120     const TValue squaredNorm() const;
00121     const TValue norm() const;
00122     const Vector2D<T> normal() const;
00123     const Vector2D<T> reciprocal() const;
00124     const Vector2D<T> perp() const;
00125     const Vector2D<T> project(const Vector2D<T>& other) const;
00126     const Vector2D<T> reject(const Vector2D<T>& other) const;
00127     const Vector2D<T> reflect(const Vector2D<T>& other) const;
00128     const Vector2D<T> transform(T (*iOperator)(T)) const;
00129 
00130     void normalize();
00131 
00132     template <class RandomGenerator> static Vector2D<T> random(RandomGenerator& generator);
00133 };
00134 
00135 template<typename T> typename Vector2D<T>::TValue dot(const Vector2D<T>& a, const Vector2D<T>& b);
00136 template<typename T> typename Vector2D<T>::TValue perpDot(const Vector2D<T>& a, const Vector2D<T>& b);
00137 template<typename T> typename Vector2D<T>::TValue cos(const Vector2D<T>& a, const Vector2D<T>& b);
00138 
00139 template<typename T> bool operator==(const Vector2D<T>& a, const Vector2D<T>& b);
00140 template<typename T> bool operator!=(const Vector2D<T>& a, const Vector2D<T>& b);
00141 
00142 template<typename T> Vector2D<T> operator+(const Vector2D<T>& a, const Vector2D<T>& b);
00143 template<typename T> Vector2D<T> operator-(const Vector2D<T>& a, const Vector2D<T>& b);
00144 template<typename T> Vector2D<T> operator*(const Vector2D<T>& a, const Vector2D<T>& b);
00145 template<typename T> Vector2D<T> operator/(const Vector2D<T>& a, const Vector2D<T>& b);
00146 
00147 template<typename T> Vector2D<T> operator+(const Vector2D<T>& a, typename Vector2D<T>::TParam b);
00148 template<typename T> Vector2D<T> operator-(const Vector2D<T>& a, typename Vector2D<T>::TParam b);
00149 template<typename T> Vector2D<T> operator*(const Vector2D<T>& a, typename Vector2D<T>::TParam b);
00150 template<typename T> Vector2D<T> operator/(const Vector2D<T>& a, typename Vector2D<T>::TParam b);
00151 
00152 template<typename T> Vector2D<T> operator+(typename Vector2D<T>::TParam a, const Vector2D<T>& b);
00153 template<typename T> Vector2D<T> operator-(typename Vector2D<T>::TParam a, const Vector2D<T>& b);
00154 template<typename T> Vector2D<T> operator*(typename Vector2D<T>::TParam a, const Vector2D<T>& b);
00155 // we don't allow scalar / vector.  you can do scalar * vector.reciprocal() for that.
00156 
00157 template<typename T> Vector2D<T> pointwiseMin(const Vector2D<T>& a, const Vector2D<T>& b);
00158 template<typename T> Vector2D<T> pointwiseMax(const Vector2D<T>& a, const Vector2D<T>& b);
00159 
00160 template <typename T> Vector2D<T> lerp(typename Vector2D<T>::TParam a, const Vector2D<T>& b, typename Vector2D<T>::TParam t);
00161 
00162 template<typename T, typename Char, typename Traits>
00163 std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& stream, const Vector2D<T>& b);
00164 template<typename T, typename Char, typename Traits>
00165 std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& ioIStream, Vector2D<T>& b);
00166 
00167 template<typename T> io::XmlOStream& operator<<(io::XmlOStream& stream, const Vector2D<T>& b);
00168 
00169 
00170 
00171 }
00172 
00173 }
00174 
00175 #include "vector_2d.inl"
00176 
00177 #define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_VECTOR_2D
00178 #ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_PLUS_H
00179 #   include "pyobject_util.h"
00180 #endif
00181 
00182 #endif

Generated on Mon Nov 10 14:22:02 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo