Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Point32f.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLUtils/src/ICLUtils/Point32f.h                       **
00010 ** Module : ICLUtils                                               **
00011 ** Authors: Christof Elbrechter                                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <ICLUtils/CompatMacros.h>
00034 #include <ICLUtils/ClippedCast.h>
00035 #include <ICLUtils/Point.h>
00036 
00037 namespace icl{
00038   namespace utils{
00039     
00041     class ICLUtils_API Point32f{
00042       public:
00043       
00045       float x;
00046   
00048       float y;
00049       
00051       static const Point32f null;
00052 
00054             Point32f() :x(0.0f), y(0.0f){}
00055 
00057       Point32f(const Point32f& p):x(p.x),y(p.y){}
00058   
00060       Point32f(float x,float y):x(x),y(y){}
00061   
00063       Point32f(const Point &p):x(p.x),y(p.y){}
00064       
00066       bool isNull() const { return (*this)==null; }
00067   
00069       bool operator==(const Point32f &s) const {return x==s.x && y==s.y;}
00070   
00072       bool operator!=(const Point32f &s) const {return x!=s.x || y!=s.y;}
00073   
00075       Point32f operator+(const Point32f &s) const {return  Point32f(x+s.x,y+s.y);}
00076   
00078       Point32f operator-(const Point32f &s) const {return  Point32f(x-s.x,y-s.y);}
00079   
00081       Point32f operator*(double d) const { return Point32f(d*x,d*y);}
00082   
00084       Point32f& operator+=(const Point32f &s){x+=s.x; y+=s.y; return *this;}
00085   
00087       Point32f& operator-=(const Point32f &s){x-=s.x; y-=s.y; return *this;}
00088   
00090       Point32f& operator*=(double d) {x*=d; y*=d; return *this; }
00091   
00093       Point32f transform(double xfac, double yfac) const{ 
00094         return Point32f(xfac*x,yfac*y);
00095       }
00096       
00098       float distanceTo(const Point32f &p) const;
00099       
00101       bool inTriangle(const utils::Point32f &v1, 
00102                       const utils::Point32f &v2, 
00103                       const utils::Point32f &v3) const;
00104       
00106 
00113       float norm(float p=2) const;
00114       
00116 
00119       Point32f &normalize(){
00120         float l = norm(); x/=l; y/=l; return *this; 
00121       }
00122       
00124 
00125       Point32f normalized() const{
00126         return Point32f(*this).normalize();
00127       }
00128   
00130       float &operator[](int i) { return i?y:x; }
00131   
00133       const float &operator[](int i) const { return i?y:x; }
00134     };
00135   
00137     ICLUtils_API std::ostream &operator<<(std::ostream &s, const Point32f &p);
00138     
00140     ICLUtils_API std::istream &operator>>(std::istream &s, Point32f &p);
00141   
00142     
00143   } // namespace utils
00144 } // namespace icl
00145 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines