00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef __FASTJET_CLOSESTPAIR2DBASE__HH__
00032 #define __FASTJET_CLOSESTPAIR2DBASE__HH__
00033
00034 #include<vector>
00035 #include "fastjet/internal/base.hh"
00036
00037 FASTJET_BEGIN_NAMESPACE
00038
00039
00042 class Coord2D {
00043 public:
00044 double x, y;
00045
00046 Coord2D() {};
00047
00048 Coord2D(double a, double b): x(a), y(b) {};
00049
00051 Coord2D operator-(const Coord2D & other) const {
00052 return Coord2D(x - other.x, y - other.y);};
00053
00055 Coord2D operator+(const Coord2D & other) const {
00056 return Coord2D(x + other.x, y + other.y);};
00057
00059 Coord2D operator*(double factor) const {return Coord2D(factor*x,factor*y);};
00060 friend Coord2D operator*(double factor, const Coord2D & coord) {
00061 return Coord2D(factor*coord.x,factor*coord.y);
00062 }
00063
00065 Coord2D operator/(double divisor) const {
00066 return Coord2D(x / divisor, y / divisor);};
00067
00069 friend double distance2(const Coord2D & a, const Coord2D & b) {
00070 double dx = a.x - b.x, dy = a.y-b.y;
00071 return dx*dx+dy*dy;
00072 };
00074 double distance2(const Coord2D & b) const {
00075 double dx = x - b.x, dy = y-b.y;
00076 return dx*dx+dy*dy;
00077 };
00078 };
00079
00080
00081
00083 class ClosestPair2DBase {
00084 public:
00087 virtual void closest_pair(unsigned int & ID1, unsigned int & ID2,
00088 double & distance2) const = 0;
00089
00091 virtual void remove(unsigned int ID) = 0;
00092
00095 virtual unsigned int insert(const Coord2D & position) = 0;
00096
00100 virtual unsigned int replace(unsigned int ID1, unsigned int ID2,
00101 const Coord2D & position) {
00102 remove(ID1);
00103 remove(ID2);
00104 unsigned new_ID = insert(position);
00105 return(new_ID);
00106 };
00107
00110 virtual void replace_many(const std::vector<unsigned int> & IDs_to_remove,
00111 const std::vector<Coord2D> & new_positions,
00112 std::vector<unsigned int> & new_IDs) {
00113 for(unsigned i = 0; i < IDs_to_remove.size(); i++) {
00114 remove(IDs_to_remove[i]);}
00115 new_IDs.resize(0);
00116 for(unsigned i = 0; i < new_positions.size(); i++) {
00117 new_IDs.push_back(insert(new_positions[i]));}
00118 }
00119
00120 virtual unsigned int size() = 0;
00121
00122 virtual ~ClosestPair2DBase() {};
00123
00124 };
00125
00126
00127 FASTJET_END_NAMESPACE
00128
00129 #endif // __FASTJET_CLOSESTPAIR2DBASE__HH__