espleaf/src/node.cpp

56 lines
1.7 KiB
C++
Raw Normal View History

2021-01-03 16:12:47 +00:00
#include "node.h"
#include "prototypes.h"
2021-01-03 16:12:47 +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();
}
Corner* last_corner = nullptr;
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);
}
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
}
_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) {
Node* node = new Node(_number + 1);
2021-01-03 16:12:47 +00:00
node->neighbours[0] = this;
neighbours[edge] = node;
node->edges[0]->neighbour = this->edges[edge];
this->edges[edge]->neighbour = node->edges[0];
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-03 16:12:47 +00:00
delete node->edges[0];
node->edges[0] = this->edges[edge];
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];
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];
node->corners[CORNERS_PER_PART-1] = c;
*/
2021-01-03 16:12:47 +00:00
return node;
}