Better reporting of the analyzed layout at startup.

This commit is contained in:
Fabian Schlenz 2021-01-18 05:53:50 +01:00
parent 5676b5d63c
commit d9708d9159
2 changed files with 24 additions and 27 deletions

View File

@ -42,24 +42,12 @@ void setup_layout() {
nodes.push_back(current_node); nodes.push_back(current_node);
} }
for(Node* node: nodes) { bool verbose = false;
for(Edge* edge: node->edges) {
auto e = std::find(edges.begin(), edges.end(), edge);
if (e == edges.end()) {
edges.push_back(edge);
}
}
LOGln("Node %p:", node);
for(Node* n : node->neighbours) {
LOGln(" %p", n);
}
}
for (Node* n1 : nodes) { for (Node* n1 : nodes) {
LOGln("Looking for neighbours of node #%d @ %d,%d", n1->_number, n1->coords.x, n1->coords.y); if (verbose) LOGln("Looking for neighbours of node #%d @ %d,%d", n1->_number, n1->coords.x, n1->coords.y);
for(int edge=0; edge<CORNERS_PER_PART; edge++) { for(int edge=0; edge<CORNERS_PER_PART; edge++) {
Coords c = n1->coords_at_direction(edge); Coords c = n1->coords_at_direction(edge);
LOGln(" Chcking edge %d @ %d,%d...", edge, c.x, c.y); if (verbose) LOGln(" Chcking edge %d @ %d,%d...", edge, c.x, c.y);
Node* found = nullptr; Node* found = nullptr;
for(Node* n2 : nodes) { for(Node* n2 : nodes) {
@ -72,7 +60,7 @@ void setup_layout() {
} }
} }
if (found != nullptr) { if (found != nullptr) {
LOGln(" Found node #%d", found->_number); if (verbose) LOGln(" Found node #%d", found->_number);
uint8_t inverse_dir = (n1->direction + 2*edge + 3) % 6; uint8_t inverse_dir = (n1->direction + 2*edge + 3) % 6;
int8_t e = (inverse_dir - found->direction) % 6; int8_t e = (inverse_dir - found->direction) % 6;
if (e < 0) e+=6; if (e < 0) e+=6;
@ -83,30 +71,39 @@ void setup_layout() {
int8_t e2 = (e - 1) % CORNERS_PER_PART; int8_t e2 = (e - 1) % CORNERS_PER_PART;
if (e2<0) e2+=CORNERS_PER_PART; if (e2<0) e2+=CORNERS_PER_PART;
LOGln(" Mapping Corner #%d,%d with #%d,%d", n1->_number, edge, found->_number, e2); if (verbose) LOGln(" Mapping Corner #%d,%d with #%d,%d", n1->_number, edge, found->_number, e2);
n1->_corners[edge]->_short_neighbours.push_back(found->_corners[e2]); n1->_corners[edge]->_short_neighbours.push_back(found->_corners[e2]);
LOGln(" Mapping Corner #%d,%d with #%d,%d", n1->_number, e1, found->_number, e); if (verbose) LOGln(" Mapping Corner #%d,%d with #%d,%d", n1->_number, e1, found->_number, e);
n1->_corners[e1]->_short_neighbours.push_back(found->_corners[e]); n1->_corners[e1]->_short_neighbours.push_back(found->_corners[e]);
} else { } else {
LOGln(" No match."); if (verbose) LOGln(" No match.");
} }
} }
} }
for(Corner* corner: corners) { for (Node* node : nodes) {
LOGln("Corner %p:", corner); LOGln("Node #%d:", node->_number);
for(auto c: corner->_long_neighbours) { for(Corner* corner : node->_corners) {
LOGln(" Long: %p", c); LOGln(" Corner #%d,%d:", node->_number, corner->number);
for (auto c: corner->_long_neighbours) {
LOGln(" Long neighbour: #%d,%d", c->node->_number, c->number);
}
for (auto c: corner->_short_neighbours) {
LOGln(" Short neighbour: #%d,%d", c->node->_number, c->number);
}
}
for (int i=0; i<CORNERS_PER_PART; i++) {
if (node->neighbours[i]==nullptr) {
LOGln(" Neighbour %d: NULL", i);
} else {
LOGln(" Neighbour %d: #%d", i, node->neighbours[i]->_number);
} }
for(auto c: corner->_short_neighbours) {
LOGln(" Short: %p", c);
} }
} }
LOGln("Counts:"); LOGln("Counts:");
LOGln("Nodes: %3d", nodes.size()); LOGln("Nodes: %3d", nodes.size());
LOGln("Edges: %3d", edges.size());
LOGln("Corners: %3d", corners.size()); LOGln("Corners: %3d", corners.size());
} }

View File

@ -14,7 +14,7 @@ Node::Node(uint16_t number, Coords c, uint8_t _dir) {
Corner* last_corner = nullptr; Corner* last_corner = nullptr;
for(int i=0; i<CORNERS_PER_PART; i++) { for(int i=0; i<CORNERS_PER_PART; i++) {
Corner* c = new Corner(edges[i], edges[(i+1) % CORNERS_PER_PART]); Corner* c = new Corner(this, i);
for(int j=0; j<LEDS_PER_CORNER; j++) { for(int j=0; j<LEDS_PER_CORNER; j++) {
c->add_led(number * CORNERS_PER_PART * LEDS_PER_CORNER + i * LEDS_PER_CORNER + j); c->add_led(number * CORNERS_PER_PART * LEDS_PER_CORNER + i * LEDS_PER_CORNER + j);
} }