-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNode.cpp
More file actions
99 lines (76 loc) · 2.39 KB
/
Node.cpp
File metadata and controls
99 lines (76 loc) · 2.39 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include <vector>
#include <utility>
#include <fstream>
using namespace std;
#define dimensions 2
#include "Rectangle.cpp"
#ifndef NODE_CPP
#define NODE_CPP
class Node{
public:
int capacity;
int parentId;
int blockId;
bool isLeaf;
pair<int, Rectangle> rectangles[51];
Rectangle boundingBox;
Node(){
initializeRectVector();
capacity = 0;
parentId = -1;
blockId = -1;
isLeaf = true;
}
Node(Rectangle bounding, bool isLeafNode, vector<pair<int, Rectangle>> rec, int aParentId, int aBlockId, bool shouldInit){
initializeRectVector();
isLeaf = isLeafNode;
setRectangles(rec, shouldInit);
boundingBox = bounding;
parentId = aParentId;
blockId = aBlockId;
}
Point defaultPoint(){
vector<double> dim(dimensions);
Point point(dim);
return point;
}
void initializeRectVector() {
for(int i = 0; i < 51; i++) {
Point p = defaultPoint();
Rectangle rec(p, p);
rectangles[i] = { 0, rec };
}
}
void setRectangles(vector<pair<int, Rectangle>> &rec, bool shouldInit) {
for(int i = 0; i < rec.size(); i++) {
rectangles[i] = rec[i];
}
capacity = (shouldInit ? rec.size() : 0);
Point p = defaultPoint();
for(int i = (int)rec.size(); i < 51; i++) {
Rectangle rec(p, p);
rectangles[i] = { 0, rec };
}
}
vector<pair<int, Rectangle>> getRectangles() {
vector<pair<int, Rectangle>> out(51);
for(int i = 0; i < 51; i++) {
out[i] = rectangles[i];
}
return out;
}
void addChild(int blockID, Rectangle rec){
rectangles[capacity] = { blockID, rec };
capacity++;
}
void modifiedNode(){
ofstream myfile;
myfile.open ("indexfile.dat", ios::out | ios::binary);
int blockStart = (blockId - 1) * (int)sizeof(Node);
myfile.seekp(blockStart, ios::beg);
myfile.write((char *) this, sizeof(Node));
myfile.close();
}
};
#endif