namespace ewalena  0.2.15
ewalena is not an acronym
include/ewalena/base/point.h
Go to the documentation of this file.
00001 // -------------------------------------------------------------------
00002 // @author Toby D. Young
00003 // @version $Id: point.h 988 2012-11-26 19:09:39Z oneliefleft $
00004 //
00005 // Copyright 2012 namespace ewalena authors. All rights reserved.
00006 //
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions
00009 // are met:
00010 //
00011 // 1. Redistributions of source code must retain the above copyright
00012 //    notice, this list of conditions and the following disclaimer.
00013 //
00014 // 2. Redistributions in binary form must reproduce the above
00015 //    copyright notice, this list of conditions and the following
00016 //    disclaimer in the documentation and/or other materials provided
00017 //    with the distribution.
00018 //
00019 // THIS SOFTWARE IS PROVIDED BY THE NAMEPSACE EWALENA AUTHORS ``AS
00020 // IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00022 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00023 // NAMESPACE EWALENA AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00024 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00026 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00027 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00028 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00029 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00030 // OF THE POSSIBILITY OF SUCH DAMAGE.
00031 //
00032 // The views and conclusions contained in the software and
00033 // documentation are those of the authors and should not be
00034 // interpreted as representing official policies, either expressed or
00035 // implied, of the namespace ewalena authors.
00036 // -------------------------------------------------------------------
00037 
00038 #include <cassert>
00039 #include <cstdarg>
00040 #include <cstring>
00041 #include <cmath>
00042 #include <iostream>
00043 
00044 #ifndef __ewalena_point_h
00045 #define __ewalena_point_h
00046 
00047 #ifdef EWALENA_HAVE_CONFIG_H
00048 #include <ewalena/base/config.h>
00049 #endif
00050 
00051 #include <ewalena/base/utilities.h>
00052 #include <ewalena/base/tensor.h>
00053 
00054 namespace ewalena
00055 {
00056   
00062   template <int dim, typename ValueType = double>
00063     class Point
00064     :
00065     public ewalena::Tensor<dim, 1, ValueType>
00066     {
00067     public:
00068     
00072     Point () 
00073     :
00074     Tensor<dim, 1, ValueType> () 
00075     {}
00076     
00080     explicit Point (const ValueType x);
00081     
00085     explicit Point (const ValueType x,
00086                     const ValueType y);
00087     
00091     explicit Point (const ValueType x,
00092                     const ValueType y,
00093                     const ValueType z);
00094     
00098     ~Point ();
00099     
00103     void clone (const Point<dim, ValueType> &p);
00104     
00112     ValueType l2_norm (const Point<dim, ValueType> &p = Point<dim, ValueType> ()) const;
00113     
00118     ValueType operator = (const unsigned int i);
00119     
00124     const ValueType operator = (const unsigned int i) const;
00125     
00130     void operator *= (const ValueType &scalar);
00131 
00136     void operator /= (const ValueType &scalar);
00137     
00142     void operator -= (const Point<dim, ValueType> &p);
00143     
00148     void operator += (const Point<dim, ValueType> &p);
00149     
00150     protected:
00151     
00156     inline  
00157     ewalena::Tensor<dim, 1, ValueType> operator* ()
00158     {  
00159       return *this;  
00160     }
00161     
00166     inline  
00167     const ewalena::Tensor<dim, 1, ValueType> operator* () const  
00168     {  
00169       return *this;  
00170     }
00171     
00172     private:
00173     
00174     }; /* Point */
00175 
00176   /*-------------- Inline and Other Functions -----------------------*/
00177 
00178   template <int dim, typename ValueType>
00179     inline 
00180     Point<dim, ValueType>::Point (const ValueType x) 
00181     {
00182       assert (dim == 1);
00183       
00184       (*this)(0) = x;
00185     }
00186 
00187   template <int dim, typename ValueType>
00188     inline 
00189     Point<dim, ValueType>::Point (const ValueType x,
00190                                   const ValueType y) 
00191     {
00192       assert (dim == 2);
00193 
00194       (*this)(0) = x;
00195       (*this)(1) = y;
00196     }
00197 
00198   template <int dim, typename ValueType>
00199     inline 
00200     Point<dim, ValueType>::Point (const ValueType x,
00201                                   const ValueType y,
00202                                   const ValueType z) 
00203     {
00204       assert (dim == 3);
00205 
00206       (*this)(0) = x;
00207       (*this)(1) = y;
00208       (*this)(2) = z;
00209     }
00210 
00211   template <int dim, typename ValueType>
00212     inline
00213     void
00214     Point<dim, ValueType>::clone (const Point<dim, ValueType> &p)
00215     {
00216       /* Clone the underlying Tensor with the Tensor::clone (Tensor)
00217          function. @todo This is buggy. */
00218       
00219       /* (**this).clone (*p); */
00220       for (unsigned int i=0; i<dim; ++i)     
00221         (*this)(i) = (*p)(i); 
00222     }
00223   
00224   template <int dim, typename ValueType>
00225     inline 
00226     ValueType
00227     Point<dim, ValueType>::operator = (const unsigned int i) 
00228     {
00229       return (*this)(i);
00230     }
00231   
00232   template <int dim, typename ValueType>
00233     inline 
00234     const ValueType
00235     Point<dim, ValueType>::operator = (const unsigned int i) const
00236     {
00237       return (*this)(i);
00238     }
00239   
00240   template <int dim, typename ValueType>
00241     inline 
00242     void
00243     Point<dim, ValueType>::operator *= (const ValueType &scalar) 
00244     {
00245       (*this) *= scalar;
00246     }
00247 
00248   template <int dim, typename ValueType>
00249     inline 
00250     void
00251     Point<dim, ValueType>::operator /= (const ValueType &scalar) 
00252     {
00253       (*this) /= scalar;
00254     }
00255 
00256   template <int dim, typename ValueType>
00257     inline 
00258     void
00259     Point<dim, ValueType>::operator -= (const Point<dim, ValueType> &p) 
00260     {
00261       for (unsigned int i=0; i<dim; ++i)
00262         (*this)(i) -= (*p)(i);
00263     }
00264 
00265   template <int dim, typename ValueType>
00266     inline 
00267     void
00268     Point<dim, ValueType>::operator += (const Point<dim, ValueType> &p) 
00269     {
00270       for (unsigned int i=0; i<dim; ++i)
00271         (*this)(i) += (*p)(i);
00272     }
00273 
00274 } /* namespace ewalena */
00275   
00276 #endif /* __ewalena_point_h */
00277   
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines