From 4bf6310e0f7c3c242509dd2c0893d6e7ca612b8a Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 20 Jan 2023 18:27:37 +0800 Subject: [PATCH] feat: svg basic rendering --- src/analyse/analyse.h | 2 +- src/graph/graph.cc | 96 +++++++++++++++++++++++++++++++++++-------- src/graph/graph.h | 11 +++++ 3 files changed, 92 insertions(+), 17 deletions(-) diff --git a/src/analyse/analyse.h b/src/analyse/analyse.h index 3888962..c57d9a5 100644 --- a/src/analyse/analyse.h +++ b/src/analyse/analyse.h @@ -53,7 +53,7 @@ public: }; typedef std::vector> track_data_t; - // TODO: try using unordered_set + // TODO: using RawCode instead of uint64_t track_data_t backtrack(const std::vector &codes); }; diff --git a/src/graph/graph.cc b/src/graph/graph.cc index e29c0cd..cd13391 100644 --- a/src/graph/graph.cc +++ b/src/graph/graph.cc @@ -1,30 +1,94 @@ #include "graph.h" +#include #include void Graph::svg_demo(Analyse::track_data_t track_data) { +// +// for (uint32_t i = 0; i < track_data.size(); ++i) { +// +// const auto &ly = track_data[i]; +// +// std::cout << std::endl; +// std::cout << "----------------------------------"; +// std::cout << " layer " << i << " "; +// std::cout << "----------------------------------" << std::endl; +// +// for (const auto &c : ly) { +// for (const auto &l : c.second.last) { +// std::cout << l->code << " "; +// } +// std::cout << " <- [" << c.second.code << "] -> "; +// for (const auto &n : c.second.next) { +// std::cout << n->code << " "; +// } +// std::cout << std::endl; +// } +// +// } + + struct inner_t { + uint64_t code; + uint32_t layer_num; + uint32_t layer_index; + std::list next; + }; + + std::vector> layer_data(track_data.size()); for (uint32_t i = 0; i < track_data.size(); ++i) { - const auto &ly = track_data[i]; - - std::cout << std::endl; - std::cout << "----------------------------------"; - std::cout << " layer " << i << " "; - std::cout << "----------------------------------" << std::endl; - - for (const auto &c : ly) { - for (const auto &l : c.second.last) { - std::cout << l->code << " "; - } - std::cout << " <- [" << c.second.code << "] -> "; - for (const auto &n : c.second.next) { - std::cout << n->code << " "; - } - std::cout << std::endl; + for (const auto &c : track_data[i]) { + layer_data[i].emplace_back(inner_t { + .code = c.second.code, + .layer_num = c.second.layer_num, + .layer_index = (uint32_t)layer_data[i].size(), + .next = std::list{}, + }); + } + + } + + + uint32_t max_length_num = 0; + for (const auto &ld : layer_data) { + if (ld.size() > max_length_num) { + max_length_num = ld.size(); + } + } +// std::cout << "max length -> " << max_length_num << std::endl; + + + uint64_t MAIN_WIDTH = CASE_WIDTH * max_length_num + CASE_GAP_X * (max_length_num + 1); + uint64_t MAIN_HEIGHT = CASE_HEIGHT * layer_data.size() + CASE_GAP_Y * (layer_data.size() + 1); + +// std::cout << "MAIN_WIDTH = " << MAIN_WIDTH << std::endl; +// std::cout << "MAIN_HEIGHT = " << MAIN_HEIGHT << std::endl; + + printf(R"()", MAIN_WIDTH, MAIN_HEIGHT); + printf("\n"); + + for (uint32_t i = 0; i < layer_data.size(); ++i) { + + uint64_t CASE_Y = CASE_GAP_Y * (i + 1) + CASE_HEIGHT * i; + +// std::cout << "TOP: " << CASE_Y << std::endl; + + uint64_t left_offset = (MAIN_WIDTH - (CASE_GAP_X * (layer_data[i].size() + 1) + CASE_WIDTH * layer_data[i].size())) / 2; + + for (uint32_t j = 0; j < layer_data[i].size(); ++j) { + uint64_t CASE_X = CASE_GAP_X * (j + 1) + CASE_WIDTH * j + left_offset; +// printf("(%ld, %ld, %ld, %ld)\n", CASE_Y, CASE_X, CASE_WIDTH, CASE_HEIGHT); + + printf(R"( )", CASE_X, CASE_Y, CASE_WIDTH, CASE_HEIGHT); + printf("\n"); + } } + printf("\n"); + + } diff --git a/src/graph/graph.h b/src/graph/graph.h index 7aeb3fa..6608a29 100644 --- a/src/graph/graph.h +++ b/src/graph/graph.h @@ -2,10 +2,21 @@ #include "analyse.h" + + class Graph { public: + uint64_t BLOCK_LENGTH = 12; + uint64_t BLOCK_GAP = 4; + + uint64_t CASE_GAP_X = 12; + uint64_t CASE_GAP_Y = 20; + + uint64_t CASE_WIDTH = BLOCK_LENGTH * 4 + BLOCK_GAP * 5; + uint64_t CASE_HEIGHT = BLOCK_LENGTH * 5 + BLOCK_GAP * 6; + void svg_demo(Analyse::track_data_t track_data); };