Main Page   Class Hierarchy   Compound List   File List   Compound Members  

coordinate.h

00001 /*============================================================================
00002         File: coordinate.h
00003      Purpose: 
00004     Revision: $Id: coordinate.h,v 1.2 2002/05/13 21:07:45 philosophil Exp $
00005   Created by: Philippe Lavoie          (26 January, 1999)
00006  Modified by: Martin Schuerch
00007 
00008  Copyright notice:
00009           Copyright (C) 1996-1999 Philippe Lavoie
00010  
00011           This library is free software; you can redistribute it and/or
00012           modify it under the terms of the GNU Library General Public
00013           License as published by the Free Software Foundation; either
00014           version 2 of the License, or (at your option) any later version.
00015  
00016           This library is distributed in the hope that it will be useful,
00017           but WITHOUT ANY WARRANTY; without even the implied warranty of
00018           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019           Library General Public License for more details.
00020  
00021           You should have received a copy of the GNU Library General Public
00022           License along with this library; if not, write to the Free
00023           Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024 =============================================================================*/
00025 #ifndef _Matrix_coordinate_h_
00026 #define _Matrix_coordinate_h_
00027 
00028 #include "matrix_global.h"
00029 #include "matrixTool.h"
00030 
00031 
00032 namespace PLib {
00033 
00034 
00042   class Coordinate {
00043   public:
00044     int i,j ;
00045     Coordinate() 
00046       { i=0;j=0;} 
00047     Coordinate(int I, int J) 
00048       { i=I ; j=J ; }
00049     Coordinate(int a) 
00050       { i=j=a; }
00051 
00052     const Coordinate& operator=(const Coordinate& c)
00053       {i=c.i; j=c.j; return *this ;}
00054     friend int operator==(const Coordinate& a, const Coordinate& b)
00055       { return ( a.i == b.i && a.j == b.j ); }
00056 
00057     friend float distance2(const Coordinate& a){ return float(a.i*a.i) + float(a.j*a.j) ; }
00058     friend float distance(const Coordinate& a) { return sqrt(distance(a)) ; }
00059 
00060     friend Coordinate operator-(const Coordinate& a, const Coordinate& b){ Coordinate m ; m.i = a.i-b.i ; m.j = a.j-b.j ; return m ; }
00061     friend Coordinate operator+(const Coordinate& a, const Coordinate& b){ Coordinate m ; m.i = a.i+b.i ; m.j = a.j+b.j ; return m ; }
00062 
00063     friend ostream& operator<<(ostream& os, const Coordinate& point);
00064     friend istream& operator>>(istream& os, Coordinate& point);
00065   };
00066 
00067   inline int operator<(const Coordinate& a, const Coordinate& b){ 
00068     return (a.i<b.i && a.j<b.j ) ; } // the smaller than operator
00069   inline int operator>(const Coordinate& a, const Coordinate& b){ 
00070     return (a.i>b.i && a.j>b.j ) ; } // the greater than operator
00071   inline int operator<=(const Coordinate& a, const Coordinate& b){ 
00072     return (a.i<=b.i && a.j<=b.j ) ; } // the smaller or equal operator
00073   inline int operator>=(const Coordinate& a, const Coordinate& b){ 
00074     return (a.i>=b.i && a.j>=b.j ) ; } // the greater or equal operator
00075 
00076 
00090   inline ostream& operator<<(ostream& os,const Coordinate& c)
00091   {
00092     os << c.i << " " << c.j << " " ;
00093     return os;  
00094   }
00095 
00096 
00109   inline istream& operator>>(istream& os, Coordinate& c){
00110     os >> c.i >> c.j ;
00111     return os ;
00112   }
00113 
00114 
00115   inline Coordinate minimum(Coordinate a, Coordinate b){
00116     Coordinate m ;
00117     m.i = minimum(a.i,b.i) ;
00118     m.j = minimum(a.j,b.j) ;
00119     return m ;
00120   }
00121 
00122   inline Coordinate maximum(Coordinate a, Coordinate b){
00123     Coordinate m ;
00124     m.i = maximum(a.i,b.i) ;
00125     m.j = maximum(a.j,b.j) ;
00126     return m ;
00127   }
00128 
00129 
00130   template <class T>
00131   inline Coordinate minimumByRef(const Coordinate &a, const Coordinate &b){
00132     Coordinate m ;
00133     m.i = minimum(a.i,b.i) ;
00134     m.j = minimum(a.j,b.j) ;
00135     return m ;
00136   }
00137 
00138 
00139   inline Coordinate maximumByRef(const Coordinate &a, const Coordinate &b){
00140     Coordinate m ;
00141     m.i = maximum(a.i,b.i) ;
00142     m.j = maximum(a.j,b.j) ;
00143     return m ;
00144   }
00145 
00146 
00147 } // end namespace
00148 
00149 #endif

Generated on Tue Jun 24 13:26:54 2003 for NURBS++ by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002