espleaf/src/node.cpp

51 lines
1.5 KiB
C++
Raw Normal View History

2021-01-03 16:12:47 +00:00
#include "node.h"
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();
}
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);
}
corners[i] = c;
}
for(int i=0; i<CORNERS_PER_PART; i++) {
corners[i]->_long_neighbours.push_back(corners[(i+1) % CORNERS_PER_PART]);
corners[i]->_long_neighbours.push_back(corners[(i-1) % CORNERS_PER_PART]);
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(this->corners[(edge-1) % CORNERS_PER_PART]);
node->corners[CORNERS_PER_PART - 1]->_short_neighbours.push_back(this->corners[edge]);
this->corners[(edge-1) % CORNERS_PER_PART]->_short_neighbours.push_back(node->corners[0]);
this->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;
}