The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mac/build/mpisearch.framework/Headers/square.h

Go to the documentation of this file.
00001 /*
00002  *  square.h
00003  *
00004  *  Copyright (c) 2002 Machine Perception Laboratory 
00005  *  University of California San Diego.
00006  *
00007  * Please read the disclaimer and notes about redistribution 
00008  * at the end of this file.
00009  *
00010  */
00011 #ifndef _SQUARE_H_
00012 #define _SQUARE_H_
00013 
00014 //#include <iostream.h>
00015 
00016 
00017 template <class T>
00018 class TSquare {
00019         //friend ostream& operator<<(ostream& s, const TSquare<T>& tsquare);
00020 
00021   public: 
00022     TSquare (T size_, T x_, T y_, T scale_);
00023     TSquare  ():x(0),y(0),size(0),scale(0){};
00024         TSquare (TSquare<double> &other) {
00025                 x = other.x;
00026                 y = other.y;
00027                 size = other.size;
00028                 scale = other.scale;
00029         }
00030         inline TSquare operator+ (T val) const {
00031       TSquare<T> c = *this;
00032       c.size += val; c.x += val; c.y += val;
00033           c.scale += val;
00034       return c;
00035         }
00036         inline TSquare operator- (T val) const {
00037       TSquare<T> c = *this;
00038       c.size -= val; c.x -= val; c.y -= val;
00039           c.scale -= val;
00040       return c;
00041         }
00042     inline TSquare operator/ (T val) const {
00043       TSquare<T> c = *this;
00044       c.size /= val; c.x /= val; c.y /= val;
00045           c.scale /= val;
00046       return c;
00047     }
00048     inline TSquare & operator*=(T val){
00049       x *= val;
00050       y *= val;
00051       size *= val;
00052           scale *= val;
00053       return *this;
00054     }
00055     inline TSquare & operator+=(TSquare<double> &other){
00056                 x += other.x;
00057                 y += other.y;
00058                 size += other.size;
00059                 scale += other.scale;
00060                 return *this;
00061         }
00062     bool intersect (TSquare<T>*);
00063     inline bool isValid() const { return (x || y || size || scale);}
00064     T x;
00065     T y;
00066     T size;
00067         T scale;
00068 
00069 };
00070 
00071 typedef TSquare<int> Square;
00072 
00073 template<class T>
00074 bool operator< (const TSquare<T> &Lft,const TSquare<T> &Rht){ return Lft.size < Rht.size; }
00075 template<class T>
00076 bool operator> (const TSquare<T> &Lft,const TSquare<T> &Rht){ return Lft.size > Rht.size; }
00077 template<class T>
00078 bool decreasing (const TSquare<T> &Lft,const TSquare<T> &Rht){ return Lft.size > Rht.size; }
00079 
00080 
00081 template <class T> 
00082 TSquare<T>::TSquare (T size_, T x_, T y_, T scale_=0)
00083 {
00084   size = size_;
00085   x = x_;
00086   y = y_;
00087   scale = scale_;
00088 }
00089 
00090 template <class T>
00091 bool TSquare<T>::intersect (TSquare<T> *other)
00092 {
00093   Square *smaller, *bigger; 
00094   
00095   if( size >= other->size) {
00096     bigger = this;
00097     smaller = other;
00098   } else {
00099     bigger = other;
00100     smaller = this;
00101   }
00102 
00103   if(smaller->x + smaller->size >= bigger->x && smaller->x <= bigger->x + bigger->size)
00104     if(smaller->y + smaller->size >= bigger->y && smaller->y <= bigger->y + bigger->size)
00105       return 1;
00106 
00107   return 0;
00108 }
00109 
00110 
00111 
00112 #endif
00113 
00114 /*
00115  * 
00116  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00117  * 
00118  *    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00119  *    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
00120  *    3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
00121  * 
00122  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00123  * 
00124  */
00125 

Generated on Mon Nov 8 17:07:52 2004 for MPT by  doxygen 1.3.9.1