-
Notifications
You must be signed in to change notification settings - Fork 14
/
Cover_Tree_Point.cc
42 lines (36 loc) · 986 Bytes
/
Cover_Tree_Point.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "Cover_Tree_Point.h"
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
double CoverTreePoint::distance(const CoverTreePoint& p) const {
static int timescalled = 0;
//if(timescalled%1000000==0) cout << timescalled << "\n";
timescalled++;
const vector<double>& vec=p.getVec();
double dist=0;
size_t lim = vec.size();
for(int i=0; i<lim;i++) {
double d = vec[i]-_vec[i];
dist+=d*d;
}
dist=sqrt(dist);
return dist;
}
const vector<double>& CoverTreePoint::getVec() const {
return _vec;
}
const char& CoverTreePoint::getChar() const {
return _name;
}
void CoverTreePoint::print() const {
vector<double>::const_iterator it;
cout << "point " << _name << ": ";
for(it=_vec.begin();it!=_vec.end();it++) {
cout << *it << " ";
}
cout << "\n";
}
bool CoverTreePoint::operator==(const CoverTreePoint& p) const {
return (_vec==p.getVec() && _name==p.getChar());
}