FastJet 3.0.4
ClosestPair2DBase.hh
00001 //STARTHEADER
00002 // $Id: ClosestPair2DBase.hh 2577 2011-09-13 15:11:38Z salam $
00003 //
00004 // Copyright (c) 2005-2011, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
00005 //
00006 //----------------------------------------------------------------------
00007 // This file is part of FastJet.
00008 //
00009 //  FastJet is free software; you can redistribute it and/or modify
00010 //  it under the terms of the GNU General Public License as published by
00011 //  the Free Software Foundation; either version 2 of the License, or
00012 //  (at your option) any later version.
00013 //
00014 //  The algorithms that underlie FastJet have required considerable
00015 //  development and are described in hep-ph/0512210. If you use
00016 //  FastJet as part of work towards a scientific publication, please
00017 //  include a citation to the FastJet paper.
00018 //
00019 //  FastJet is distributed in the hope that it will be useful,
00020 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 //  GNU General Public License for more details.
00023 //
00024 //  You should have received a copy of the GNU General Public License
00025 //  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
00026 //----------------------------------------------------------------------
00027 //ENDHEADER
00028 
00029 #ifndef __FASTJET_CLOSESTPAIR2DBASE__HH__
00030 #define __FASTJET_CLOSESTPAIR2DBASE__HH__
00031 
00032 #include<vector>
00033 #include "fastjet/internal/base.hh"
00034 
00035 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
00036 
00037 //----------------------------------------------------------------------
00038 /// \if internal_doc
00039 /// @ingroup internal
00040 /// \class Coord2D
00041 /// class for representing 2d coordinates and carrying out some basic 
00042 /// operations on them
00043 /// \endif
00044 class Coord2D {
00045 public:
00046   double x, y;
00047 
00048   Coord2D() {};
00049 
00050   Coord2D(double a, double b): x(a), y(b) {};
00051 
00052   /// return the vector difference between two coordinates
00053   Coord2D operator-(const Coord2D & other) const {
00054     return Coord2D(x - other.x,  y - other.y);};
00055 
00056   /// return the vector sum between two coordinates
00057   Coord2D operator+(const Coord2D & other) const {
00058     return Coord2D(x + other.x,  y + other.y);};
00059 
00060   /// return the product of the coordinate with the factor
00061   Coord2D operator*(double factor) const {return Coord2D(factor*x,factor*y);};
00062   friend Coord2D operator*(double factor, const Coord2D & coord) {
00063     return Coord2D(factor*coord.x,factor*coord.y);
00064   }
00065 
00066   /// division of each component of coordinate
00067   Coord2D operator/(double divisor) const {
00068     return Coord2D(x / divisor,  y / divisor);};
00069 
00070   /// return the squared distance between two coordinates
00071   friend double distance2(const Coord2D & a, const Coord2D & b) {
00072     double dx = a.x - b.x, dy = a.y-b.y;
00073     return dx*dx+dy*dy;
00074   };
00075   /// return the squared distance between two coordinates
00076   double distance2(const Coord2D & b) const {
00077     double dx = x - b.x, dy = y-b.y;
00078     return dx*dx+dy*dy;
00079   };
00080 };
00081 
00082 
00083 //----------------------------------------------------------------------
00084 /// \if internal_doc
00085 /// @ingroup internal
00086 /// \class ClosestPair2DBase
00087 /// abstract base class for finding closest pairs in 2D
00088 /// \endif
00089 class ClosestPair2DBase {
00090 public:
00091   /// provides the IDs of the closest pair as well as the squared
00092   /// distance between them
00093   virtual void closest_pair(unsigned int & ID1, unsigned int & ID2, 
00094                             double & distance2) const = 0;
00095   
00096   /// removes the entry labelled by ID from the object;
00097   virtual void remove(unsigned int ID) = 0;
00098  
00099   /// inserts the position into the closest pair structure and returns the
00100   /// ID that has been allocated for the object.
00101   virtual unsigned int insert(const Coord2D & position) = 0;
00102 
00103   /// replaces the specified ID1 and ID2 with something at a new position
00104   /// assuming that ID1 and ID2 are in sequence wrt position; it returns
00105   /// the ID of the new object...
00106   virtual unsigned int replace(unsigned int ID1, unsigned int ID2, 
00107                                const Coord2D & position) {
00108     remove(ID1); 
00109     remove(ID2); 
00110     unsigned new_ID = insert(position);
00111     return(new_ID);
00112   };
00113 
00114   /// replaces IDs_to_remove with points at the new_positions
00115   /// indicating the IDs allocated to the new points in new_IDs
00116   virtual void replace_many(const std::vector<unsigned int> & IDs_to_remove,
00117                        const std::vector<Coord2D> & new_positions,
00118                        std::vector<unsigned int> & new_IDs) {
00119     for(unsigned i = 0; i < IDs_to_remove.size(); i++) {
00120       remove(IDs_to_remove[i]);}
00121     new_IDs.resize(0);
00122     for(unsigned i = 0; i < new_positions.size(); i++) {
00123       new_IDs.push_back(insert(new_positions[i]));}
00124   }
00125 
00126   virtual unsigned int size() = 0;
00127 
00128   virtual ~ClosestPair2DBase() {};
00129   
00130 };
00131 
00132 
00133 FASTJET_END_NAMESPACE
00134 
00135 #endif // __FASTJET_CLOSESTPAIR2DBASE__HH__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends