2021-01-03 16:12:47 +00:00
|
|
|
#include "node.h"
|
2021-01-04 11:44:41 +00:00
|
|
|
#include "prototypes.h"
|
2021-01-03 16:12:47 +00:00
|
|
|
|
2021-01-04 10:39:46 +00:00
|
|
|
Node::Node(uint16_t number) {
|
|
|
|
_number = number;
|
2021-01-03 16:12:47 +00:00
|
|
|
for(int i=0; i<CORNERS_PER_PART; i++) {
|
|
|
|
edges[i] = new Edge();
|
2021-01-04 10:39:46 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 11:44:41 +00:00
|
|
|
Corner* last_corner = nullptr;
|
2021-01-04 10:39:46 +00:00
|
|
|
for(int i=0; i<CORNERS_PER_PART; i++) {
|
|
|
|
Corner* c = new Corner(edges[i], edges[(i+1) % CORNERS_PER_PART]);
|
|
|
|
for(int j=0; j<LEDS_PER_CORNER; j++) {
|
|
|
|
c->add_led(number * CORNERS_PER_PART * LEDS_PER_CORNER + i * LEDS_PER_CORNER + j);
|
|
|
|
}
|
2021-01-04 11:44:41 +00:00
|
|
|
if (last_corner != nullptr) {
|
|
|
|
c->_long_neighbours.push_back(last_corner);
|
|
|
|
last_corner->_long_neighbours.push_back(c);
|
|
|
|
}
|
|
|
|
_corners[i] = c;
|
|
|
|
corners.push_back(c);
|
|
|
|
last_corner = c;
|
2021-01-03 16:12:47 +00:00
|
|
|
}
|
2021-01-04 11:44:41 +00:00
|
|
|
_corners[0]->_long_neighbours.push_back(last_corner);
|
|
|
|
last_corner->_long_neighbours.push_back(_corners[0]);
|
2021-01-03 16:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Node* Node::create_neighbour(uint8_t edge) {
|
2021-01-04 10:39:46 +00:00
|
|
|
Node* node = new Node(_number + 1);
|
2021-01-03 16:12:47 +00:00
|
|
|
node->neighbours[0] = this;
|
|
|
|
neighbours[edge] = node;
|
|
|
|
|
2021-01-04 10:39:46 +00:00
|
|
|
node->edges[0]->neighbour = this->edges[edge];
|
|
|
|
this->edges[edge]->neighbour = node->edges[0];
|
|
|
|
|
2021-01-04 11:44:41 +00:00
|
|
|
node->_corners[0]->_short_neighbours.push_back(_corners[(edge-1) % CORNERS_PER_PART]);
|
|
|
|
node->_corners[CORNERS_PER_PART - 1]->_short_neighbours.push_back(_corners[edge]);
|
|
|
|
_corners[(edge-1) % CORNERS_PER_PART]->_short_neighbours.push_back(node->_corners[0]);
|
|
|
|
_corners[edge]->_short_neighbours.push_back(node->_corners[CORNERS_PER_PART - 1]);
|
2021-01-04 10:39:46 +00:00
|
|
|
|
|
|
|
/*
|
2021-01-03 16:12:47 +00:00
|
|
|
delete node->edges[0];
|
|
|
|
node->edges[0] = this->edges[edge];
|
2021-01-04 10:39:46 +00:00
|
|
|
|
|
|
|
Corner* c = this->corners[(edge-1) % CORNERS_PER_PART];
|
|
|
|
c->merge_leds(node->corners[0]);
|
2021-01-03 16:12:47 +00:00
|
|
|
delete node->corners[0];
|
2021-01-04 10:39:46 +00:00
|
|
|
node->corners[0] = c;
|
|
|
|
|
|
|
|
c = this->corners[edge];
|
|
|
|
c->merge_leds(node->corners[CORNERS_PER_PART-1]);
|
2021-01-03 16:12:47 +00:00
|
|
|
delete node->corners[CORNERS_PER_PART-1];
|
2021-01-04 10:39:46 +00:00
|
|
|
node->corners[CORNERS_PER_PART-1] = c;
|
|
|
|
*/
|
2021-01-03 16:12:47 +00:00
|
|
|
return node;
|
|
|
|
}
|