library of assembled shared sources

http://lass.cocamware.com

point_3d.inl

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 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_POINT_3D_INL
00046 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_POINT_3D_INL
00047 
00048 
00049 
00050 
00051 #include "point_3d.h"
00052 
00053 
00054 
00055 namespace lass
00056 {
00057 
00058 namespace prim
00059 {
00060 
00061 template<typename T> inline
00062 Point3D<T>::Point3D() :
00063     x(TNumTraits::zero),
00064     y(TNumTraits::zero),
00065     z(TNumTraits::zero)
00066 {
00067     LASS_ASSERT(isZero());
00068 }
00069 
00070 
00071 
00072 template<typename T> inline
00073 Point3D<T>::Point3D(TParam x, TParam y, TParam z) :
00074     x(x),
00075     y(y),
00076     z(z)
00077 {
00078 }
00079 
00080 
00081 
00082 template<typename T>
00083 template<typename U>
00084 Point3D<T>::Point3D(const Point3D<U>& other):
00085     x(static_cast<TValue>(other.x)),
00086     y(static_cast<TValue>(other.y)),
00087     z(static_cast<TValue>(other.z))
00088 {
00089 }
00090 
00091 
00092 
00093 template<typename T>
00094 template<typename U>
00095 Point3D<T>::Point3D(const Vector3D<U>& position):
00096     x(static_cast<TValue>(position.x)),
00097     y(static_cast<TValue>(position.y)),
00098     z(static_cast<TValue>(position.z))
00099 {
00100 }
00101 
00102 
00103 
00104 template<typename T>
00105 template<typename U>
00106 Point3D<T>::Point3D(const U& x, const U& y, const U& z):
00107     x(static_cast<TValue>(x)),
00108     y(static_cast<TValue>(y)),
00109     z(static_cast<TValue>(z))
00110 {
00111 }
00112 
00113 
00114 
00115 template <typename T> inline
00116 const typename Point3D<T>::TVector
00117 Point3D<T>::position() const
00118 {
00119     return TVector(x, y, z);
00120 }
00121 
00122 
00123 
00124 template<typename T> inline
00125 typename Point3D<T>::TConstReference
00126 Point3D<T>::operator[](size_t index) const
00127 {
00128     LASS_ASSERT(index < dimension);
00129     return *(&x + index);
00130 }
00131 
00132 
00133 
00134 template<typename T> inline
00135 typename Point3D<T>::TReference
00136 Point3D<T>::operator[](size_t index)
00137 {
00138     LASS_ASSERT(index < dimension);
00139     return *(&x + index);
00140 }
00141 
00142 
00143 
00144 /** Wrap index around range.
00145  */
00146 template<typename T> inline
00147 typename Point3D<T>::TConstReference
00148 Point3D<T>::at(signed index) const
00149 {
00150     return *(&x + num::mod(index, dimension));
00151 }
00152 
00153 
00154 
00155 /** Wrap index around range.
00156  */
00157 template<typename T> inline
00158 typename Point3D<T>::TReference
00159 Point3D<T>::at(signed index)
00160 {
00161     return *(&x + num::mod(index, dimension));
00162 }
00163 
00164 
00165 
00166 
00167 template<typename T>
00168 Point3D<T>& Point3D<T>::operator+=(const TVector& offset)
00169 {
00170     x += offset.x;
00171     y += offset.y;
00172     z += offset.z;
00173     return *this;
00174 }
00175 
00176 
00177 
00178 template<typename T>
00179 Point3D<T>& Point3D<T>::operator-=(const TVector& offset)
00180 {
00181     x -= offset.x;
00182     y -= offset.y;
00183     z -= offset.z;
00184     return *this;
00185 }
00186 
00187 
00188 
00189 template<typename T>
00190 const bool Point3D<T>::isZero() const
00191 {
00192     return x == TNumTraits::zero && y == TNumTraits::zero && z == TNumTraits::zero;
00193 }
00194 
00195 
00196 
00197 /** Return true if at least one of the components is NaN
00198  */
00199 template<typename T> inline
00200 const bool Point3D<T>::isNaN() const
00201 {
00202     return num::isNaN(x) || num::isNaN(y) || num::isNaN(z);
00203 }
00204 
00205 
00206 
00207 // --- FREE FUNCTIONS ---------------------------------------------------------------------------
00208 
00209 /** @relates lass::prim::Point3D
00210  */
00211 template<typename T>
00212 bool operator==(const Point3D<T>& a, const Point3D<T>& b)
00213 {
00214     return a.x == b.x && a.y == b.y && a.z == b.z;
00215 }
00216 
00217 
00218 
00219 /** @relates lass::prim::Point3D
00220  */
00221 template<typename T> inline
00222 bool operator!=(const Point3D<T>& a, const Point3D<T>& b)
00223 {
00224     return !(a == b);
00225 }
00226 
00227 
00228 
00229 /** @relates lass::prim::Point3D
00230  */
00231 template<typename T> inline
00232 Point3D<T> operator+(const Point3D<T>& a, const Vector3D<T>& b)
00233 {
00234     Point3D<T> result(a);
00235     result += b;
00236     return result;
00237 }
00238 
00239 
00240 
00241 /** @relates lass::prim::Point3D
00242  */
00243 template<typename T> inline
00244 Point3D<T> operator-(const Point3D<T>& a, const Vector3D<T>& b)
00245 {
00246     Point3D<T> result(a);
00247     result -= b;
00248     return result;
00249 }
00250 
00251 
00252 
00253 /** @relates lass::prim::Point3D
00254  */
00255 template<typename T> inline
00256 Point3D<T> operator+(const Vector3D<T>& a, const Point3D<T>& b)
00257 {
00258     Point3D<T> result(b);
00259     result += a;
00260     return result;
00261 }
00262 
00263 
00264 
00265 /** @relates lass::prim::Point3D
00266  */
00267 template<typename T>
00268 Vector3D<T> operator-(const Point3D<T>& a, const Point3D<T>& b)
00269 {
00270     return Vector3D<T>(a.x - b.x, a.y - b.y, a.z - b.z);
00271 }
00272 
00273 
00274 
00275 /** return the distance between two points
00276  *  @relates lass::prim::Point3D
00277  */
00278 template<typename T>
00279 typename Point3D<T>::TValue distance(const Point3D<T>& a, const Point3D<T>& b)
00280 {
00281     const Vector3D<T> difference = a - b;
00282     return difference.norm();
00283 }
00284 
00285 /** @relates lass::prim::Point2D
00286  */
00287 template<typename T>
00288 typename Point3D<T>::TValue squaredDistance(const Point3D<T>& a, const Point3D<T>& b)
00289 {
00290     const Vector3D<T> difference = a - b;
00291     return difference.squaredNorm();
00292 }
00293 
00294 
00295 
00296 /** return a point with, for each coordinate, the minimum value of a and b
00297  *  @relates lass::prim::Point3D
00298  */
00299 template<typename T>
00300 Point3D<T> pointwiseMin(const Point3D<T>& a, const Point3D<T>& b)
00301 {
00302     return Point3D<T>(std::min(a.x, b.x), std::min(a.y, b.y), std::min(a.z, b.z));
00303 }
00304 
00305 
00306 
00307 /** interpolate linearly between two points: a + t * (b - a)
00308  *  @relates lass::prim::Point3D
00309  */
00310 template<typename T>
00311 inline Point3D<T> lerp(const Point3D<T>& a, const Point3D<T>& b, typename Point3D<T>::TParam t)
00312 {
00313     return Point3D<T>(lerp(a.position(), b.position(), t));
00314 }
00315 
00316 
00317 
00318 /** return a point with, for each coordinate, the maximum value of a and b
00319  *  @relates lass::prim::Point3D
00320  */
00321 template<typename T>
00322 Point3D<T> pointwiseMax(const Point3D<T>& a, const Point3D<T>& b)
00323 {
00324     return Point3D<T>(std::max(a.x, b.x), std::max(a.y, b.y), std::max(a.z, b.z));
00325 }
00326 
00327 
00328 
00329 /** @relates lass::prim::Point3D
00330  */
00331 template<typename T>
00332 std::ostream& operator<<(std::ostream& stream, const Point3D<T>& b)
00333 {
00334     LASS_ENFORCE_STREAM(stream) << b.position();
00335     return stream;
00336 }
00337 
00338 
00339 
00340 /** @relates lass::prim::Point3D
00341  */
00342 template<typename T>
00343 io::XmlOStream& operator<<(io::XmlOStream& stream, const Point3D<T>& b)
00344 {
00345     LASS_ENFORCE_STREAM(stream)
00346         << "<Point3D>" << b.x << " " << b.y << " " << b.z << "</Point3D>\n";
00347     return stream;
00348 }
00349 
00350 
00351 /** @relates lass::prim::Point3D
00352  */
00353 template<typename T>
00354 std::istream& operator>>(std::istream& stream, Point3D<T>& b)
00355 {
00356     Vector3D<T> temp;
00357     LASS_ENFORCE_STREAM(stream) >> temp;
00358     b = Point3D<T>(temp);
00359     return stream;
00360 }
00361 
00362 
00363 
00364 }
00365 
00366 }
00367 
00368 #endif

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