-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hit.cpp
78 lines (67 loc) · 1.84 KB
/
Hit.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "Hit.hpp"
#include <algorithm>
namespace dbscan {
//======================================================================
HitSet::HitSet()
{
hits.reserve(10);
}
//======================================================================
void
HitSet::insert(Hit* h)
{
// We're typically inserting hits at or near the end, so do a
// linear scan instead of full binary search. This turns out to be much
// faster in our case
auto it = hits.rbegin();
while (it != hits.rend() && (*it)->time >= h->time) {
// Don't insert the hit if we already have it
if (*it == h) {
return;
}
++it;
}
if (it == hits.rend() || *it != h) {
hits.insert(it.base(), h);
}
}
//======================================================================
Hit::Hit(float _time, int _chan)
{
reset(_time, _chan);
}
//======================================================================
void
Hit::reset(float _time, int _chan)
{
time=_time;
chan=_chan;
cluster=kUndefined;
connectedness=Connectedness::kUndefined;
neighbours.clear();
}
//======================================================================
// Return true if hit was indeed a neighbour
bool
Hit::add_potential_neighbour(Hit* other, float eps, int minPts)
{
if (other != this && euclidean_distance_sqr(*this, *other) < eps*eps) {
neighbours.insert(other);
if (neighbours.size() + 1 >= minPts) {
connectedness = Connectedness::kCore;
}
// Neighbourliness is symmetric
other->neighbours.insert(this);
if (other->neighbours.size() + 1 >= minPts) {
other->connectedness = Connectedness::kCore;
}
return true;
}
return false;
}
}
// Local Variables:
// mode: c++
// c-basic-offset: 4
// c-file-style: "linux"
// End: