Back to index

CCyclicCollection.C

 
//----------------------------------------------------------------------------- 
//  $Header: /tmp_mnt/asis/offline/ceres/cool/project/RCS/CCyclicCollection.C,v 2.1 1996/10/04 08:43:21 voigt Exp $ 
// 
//  COOL Program Library   
//  Copyright (C) CERES collaboration, 1996 
// 
//  Template definitions for CCyclicCollection<T> class. 
// 
//----------------------------------------------------------------------------- 
#include <iostream.h> 
 
#ifndef RW_COMPILE_INSTANTIATE 
#include "CCyclicCollection.h" 
#endif 
 
 
// 
// Calculates index from x/y according to maxX/Y 
// 
template<class T> long CCyclicCollection<T>::where(int x, int y) const  
{  
                                                  // remember that maxX is xSizeOfArray-1. 
  long xSizeOfArray = maxX-minX+1;                // this is the true x-size of the array 
  while ( x <  minX ) { x += (int)xSizeOfArray; } // negative index shifts up... 
  while ( x >  maxX ) { x -= (int)xSizeOfArray; } // too large index shifts down 
                                                  // now we are in range... 
  return (y-minY)*(xSizeOfArray) + (x-minX); 
} 
 
template<class T> 
CBoolean CCyclicCollection<T>::boundCheck(int x, int y) const 
{ 
                                                  // remember that maxX is xSizeOfArray-1. 
  long xSizeOfArray = maxX-minX+1;                // this is the true x-size of the array 
  while ( x <  minX ) { x += (int)xSizeOfArray; } // negative index shifts up... 
  while ( x >  maxX ) { x -= (int)xSizeOfArray; } // too large index shifts down 
                                                  // now we are in range... 
   return ( x >= minX && x <= maxX &&  
            y >= minY && y <= maxY ); 
} 
 

Back to index