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.GPL  **
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/Point.h>
00034 #include <ICLUtils/ClippedCast.h>
00035 
00036 namespace icl{
00037   namespace utils{
00038     
00040     class Point32f{
00041       public:
00042       
00044       float x;
00045   
00047       float y;
00048       
00050       static const Point32f null;
00051   
00053       Point32f(const Point32f& p=null):x(p.x),y(p.y){}
00054   
00056       Point32f(float x,float y):x(x),y(y){}
00057   
00059       Point32f(const Point &p):x(p.x),y(p.y){}
00060       
00062       bool isNull() const { return (*this)==null; }
00063   
00065       bool operator==(const Point32f &s) const {return x==s.x && y==s.y;}
00066   
00068       bool operator!=(const Point32f &s) const {return x!=s.x || y!=s.y;}
00069   
00071       Point32f operator+(const Point32f &s) const {return  Point32f(x+s.x,y+s.y);}
00072   
00074       Point32f operator-(const Point32f &s) const {return  Point32f(x-s.x,y-s.y);}
00075   
00077       Point32f operator*(double d) const { return Point32f(d*x,d*y);}
00078   
00080       Point32f& operator+=(const Point32f &s){x+=s.x; y+=s.y; return *this;}
00081   
00083       Point32f& operator-=(const Point32f &s){x-=s.x; y-=s.y; return *this;}
00084   
00086       Point32f& operator*=(double d) {x*=d; y*=d; return *this; }
00087   
00089       Point32f transform(double xfac, double yfac) const{ 
00090         return Point32f(xfac*x,yfac*y);
00091       }
00092       
00094       float distanceTo(const Point32f &p) const;
00095       
00097       bool inTriangle(const utils::Point32f &v1, 
00098                       const utils::Point32f &v2, 
00099                       const utils::Point32f &v3) const;
00100       
00102 
00109       float norm(float p=2) const;
00110       
00112 
00115       Point32f &normalize(){
00116         float l = norm(); x/=l; y/=l; return *this; 
00117       }
00118       
00120 
00121       Point32f normalized() const{
00122         return Point32f(*this).normalize();
00123       }
00124   
00126       float &operator[](int i) { return i?y:x; }
00127   
00129       const float &operator[](int i) const { return i?y:x; }
00130     };
00131   
00133     std::ostream &operator<<(std::ostream &s, const Point32f &p);
00134     
00136     std::istream &operator>>(std::istream &s, Point32f &p);
00137   
00138     
00139   } // namespace utils
00140 } // namespace icl
00141 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines