forked from sguerra/Image-Analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classitem.cpp
50 lines (36 loc) · 1.01 KB
/
classitem.cpp
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
43
44
45
46
47
48
#include "classitem.h"
#include <QtMath>
// Constructor
ClassItem::ClassItem(){
}
ClassItem::ClassItem(QVector<double> vector, QString className)
{
this->vector = vector;
this->className = className;
}
// Public Methods
QVector<double> ClassItem::getVector(){
return this->vector;
}
QString ClassItem::getClassName(){
return this->className;
}
double ClassItem::getDistance(QVector<double> vector, int metric){
double distance = 0;
for(int i = 0; i < this->vector.size(); i++){
if(metric == METRIC_ABSOLUTE){
distance += qAbs(this->vector[i] - vector[i]);
}
else if(metric == METRIC_EUCLIDEAN){
distance += qPow(this->vector[i] - vector[i], 2);
}
else if(metric == METRIC_INFINITE){
double absolute = qAbs(this->vector[i] - vector[i]);
distance = absolute > distance ? absolute : distance;
}
}
if(metric == METRIC_EUCLIDEAN){
distance = qSqrt(distance);
}
return distance;
}