-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.cpp
76 lines (64 loc) · 2.43 KB
/
Node.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
#include "KDTree.hpp"
#include <cmath>
/////////////////////////////////////////////////
/// @fn point Node::getPosition()
/// @brief Returns the Position of the Node object
/// @returns `point` The Position of the Node Object
/////////////////////////////////////////////////
point Node::getPosition() const {
return position;
}
/////////////////////////////////////////////////
/// @fn bool Node::visited()
/// @brief Check if we have visited this node before. This helps with
/// optimizing the search algorithm for completeness.
/// @returns `bool` true or false regarding whether we have
/// visited this node or not.
/////////////////////////////////////////////////
bool Node::visited() const {
return nodeVisited;
}
/////////////////////////////////////////////////
/// @fn bool Node::operator<(Node& secondNode)
/// @brief Check if this Node is less than another Node
/// @returns `bool` true if less than
/////////////////////////////////////////////////
bool Node::operator<(Node& secondNode) {
return position < secondNode.getPosition();
}
/////////////////////////////////////////////////
/// @fn bool Node::operator==(Node& secondNode)
/// @brief Check equality between two nodes
/// @returns `bool` true if equal
/////////////////////////////////////////////////
bool Node::operator==(Node& secondNode) {
return position == secondNode.getPosition();
}
/////////////////////////////////////////////////
/// @fn Node::operator=(const Node& secondNode)
/// @brief Copies the conents of the second node
/// into the curent node
/////////////////////////////////////////////////
void Node::operator=(const Node& secondNode) {
position = secondNode.getPosition();
nodeVisited = secondNode.visited();
}
/////////////////////////////////////////////////
/// @fn Node::findNode(point p, uint8_t dimensions, uint32_t index)
/// @brief Searches through the kd-tree for the specified point
/// @param p Point to search for
/// @param dimensions Dimensionality of the tree
/// @param index Curent index for tail recursive searching
/// @returns `Node *` Pointer to found node
/////////////////////////////////////////////////
Node* Node::findNode(point p, uint8_t dimensions, uint32_t index) {
if(this->getPosition() == p) {
return this;
}
else if(this->getPosition()[index % dimensions] > p[index % dimensions]) {
return this->left->findNode(p, dimensions, ++index);
}
else {
return this->right->findNode(p, dimensions, ++index);
}
}