From 40efeee43647ba9e958f658e6045f4d56f96b3d4 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Fri, 8 Jan 2021 22:21:44 +0100 Subject: [PATCH] Corner.short_neighbours are now searched for based on the coordinates of the nodes. --- include/node.h | 7 +++---- src/main.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/node.cpp | 5 ----- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/include/node.h b/include/node.h index 5807c62..6981393 100644 --- a/include/node.h +++ b/include/node.h @@ -7,7 +7,7 @@ // Delta-X data. Per direction of a triangle is a triple with Delta-X values for each direction. static const int8_t dx[][3] = {{0, 1, -1}, {1, 0, -1}, {1, -1, 0}, {0, -1, 1}, {-1, 0, 1}, {-1, 1, 0}}; -static const int8_t dy[][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, -1}, {1, 0, 0}, {0, -1, 0}, {0, 0, 1}}; +static const int8_t dy[][3] = {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}, {1, 0, 0}, {0, -1, 0}, {0, 0, 1}}; typedef struct { int8_t x; @@ -15,10 +15,8 @@ typedef struct { } Coords; class Node { - private: - uint16_t _number; - Coords coords_at_direction(uint8_t edge); public: + uint16_t _number; Coords coords; uint8_t direction; Node* neighbours[CORNERS_PER_PART]; @@ -26,6 +24,7 @@ class Node { Corner* _corners[CORNERS_PER_PART]; Node(uint16_t number, Coords c, uint8_t direction); Node* create_neighbour(uint8_t edge); + Coords coords_at_direction(uint8_t edge); void blend_to(CRGB color, uint16_t effect_id=0, uint8_t effect_speed=0); void set_color(CRGB color); diff --git a/src/main.cpp b/src/main.cpp index c77172f..87577fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,6 +54,45 @@ void setup_layout() { } } + for (Node* n1 : nodes) { + LOGln("Looking for neighbours of node #%d @ %d,%d", n1->_number, n1->coords.x, n1->coords.y); + for(int edge=0; edgecoords_at_direction(edge); + LOGln(" Chcking edge %d @ %d,%d...", edge, c.x, c.y); + + Node* found = nullptr; + for(Node* n2 : nodes) { + if (n2 == n1) { + continue; + } + if (n2->coords.x == c.x && n2->coords.y == c.y) { + found = n2; + break; + } + } + if (found != nullptr) { + LOGln(" Found node #%d", found->_number); + uint8_t inverse_dir = (n1->direction + 2*edge + 3) % 6; + int8_t e = (inverse_dir - found->direction) % 6; + if (e < 0) e+=6; + e = e / 2; + //LOGln(" inverse_dir: %d, edge: %d", inverse_dir, edge); + int8_t e1 = (edge - 1) % CORNERS_PER_PART; + if (e1<0) e1+=CORNERS_PER_PART; + int8_t e2 = (e - 1) % CORNERS_PER_PART; + if (e2<0) e2+=CORNERS_PER_PART; + + LOGln(" Mapping Corner #%d,%d with #%d,%d", n1->_number, edge, found->_number, e2); + n1->_corners[edge]->_short_neighbours.push_back(found->_corners[e]); + + LOGln(" Mapping Corner #%d,%d with #%d,%d", n1->_number, e1, found->_number, e); + n1->_corners[e1]->_short_neighbours.push_back(found->_corners[e2]); + } else { + LOGln(" No match."); + } + } + } + for(Corner* corner: corners) { LOGln("Corner %p:", corner); for(auto c: corner->_long_neighbours) { diff --git a/src/node.cpp b/src/node.cpp index b53bf1a..6aa1315 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -45,11 +45,6 @@ Node* Node::create_neighbour(uint8_t edge) { 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]); - return node; }