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
00040
00041
00042
00043
00044
00045
00046 class Coord2D {
00047 public:
00048 double x, y;
00049
00050 Coord2D() {};
00051
00052 Coord2D(double a, double b): x(a), y(b) {};
00053
00054
00055 Coord2D operator-(const Coord2D & other) const {
00056 return Coord2D(x - other.x, y - other.y);};
00057
00058
00059 Coord2D operator+(const Coord2D & other) const {
00060 return Coord2D(x + other.x, y + other.y);};
00061
00062
00063 Coord2D operator*(double factor) const {return Coord2D(factor*x,factor*y);};
00064 friend Coord2D operator*(double factor, const Coord2D & coord) {
00065 return Coord2D(factor*coord.x,factor*coord.y);
00066 }
00067
00068
00069 Coord2D operator/(double divisor) const {
00070 return Coord2D(x / divisor, y / divisor);};
00071
00072
00073 friend double distance2(const Coord2D & a, const Coord2D & b) {
00074 double dx = a.x - b.x, dy = a.y-b.y;
00075 return dx*dx+dy*dy;
00076 };
00077
00078 double distance2(const Coord2D & b) const {
00079 double dx = x - b.x, dy = y-b.y;
00080 return dx*dx+dy*dy;
00081 };
00082 };
00083
00084
00085
00086
00087
00088
00089
00090
00091 class ClosestPair2DBase {
00092 public:
00093
00094
00095 virtual void closest_pair(unsigned int & ID1, unsigned int & ID2,
00096 double & distance2) const = 0;
00097
00098
00099 virtual void remove(unsigned int ID) = 0;
00100
00101
00102
00103 virtual unsigned int insert(const Coord2D & position) = 0;
00104
00105
00106
00107
00108 virtual unsigned int replace(unsigned int ID1, unsigned int ID2,
00109 const Coord2D & position) {
00110 remove(ID1);
00111 remove(ID2);
00112 unsigned new_ID = insert(position);
00113 return(new_ID);
00114 };
00115
00116
00117
00118 virtual void replace_many(const std::vector<unsigned int> & IDs_to_remove,
00119 const std::vector<Coord2D> & new_positions,
00120 std::vector<unsigned int> & new_IDs) {
00121 for(unsigned i = 0; i < IDs_to_remove.size(); i++) {
00122 remove(IDs_to_remove[i]);}
00123 new_IDs.resize(0);
00124 for(unsigned i = 0; i < new_positions.size(); i++) {
00125 new_IDs.push_back(insert(new_positions[i]));}
00126 }
00127
00128 virtual unsigned int size() = 0;
00129
00130 virtual ~ClosestPair2DBase() {};
00131
00132 };
00133
00134
00135 FASTJET_END_NAMESPACE
00136
00137 #endif // __FASTJET_CLOSESTPAIR2DBASE__HH__