From 47d0e2986863e33e28e8a65aef5ba2b7700946d7 Mon Sep 17 00:00:00 2001 From: Trygve Date: Tue, 7 May 2024 15:26:50 +0200 Subject: [PATCH] Started on validation if a case can come after another --- src/main.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 510f4d3..92b20df 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,6 @@ #include "contour_creator.hh" +#include +#include #include #include "ogrsf_frmts.h" #include @@ -33,6 +35,11 @@ std::vector produce_cellmap(HeightMap* heightmap, float z) return points; } +bool is_in(int value, std::array array) +{ + return std::binary_search(array.begin(), array.end(), value); +} + std::vector> create_lines(HeightMap* heightmap, int interval) { int num_contours = (heightmap->max - heightmap->min)/interval; @@ -51,39 +58,82 @@ std::vector> create_lines(HeightMap* heightmap, int interval) int points_allocated = 0; x = points[0].x; y = points[0].y; + int current_case = points[0].mscase; points[0].allocated = true; line.push_back(points[0]); for (int j = 0; j < points.size(); j++){ for (int k = 0; k < points.size(); k++){ Point* candidate = &points[k]; + std::array north{4, 5,6,7,8,9,10,11}; + std::array south{1,2,5,6,9,10,13,14}; + std::array east{2,3,4,5,10,11,12,13}; + std::array west{1,3,5,7,8,10,12,14}; + std::vector possible_connections; + switch (candidate->mscase) { + case 1: + case 14: + possible_connections.insert(possible_connections.end(), east.begin(), east.end()); + possible_connections.insert(possible_connections.end(), north.begin(), north.end()); + case 2: + case 13: + possible_connections.insert(possible_connections.end(), west.begin(), west.end()); + possible_connections.insert(possible_connections.end(), south.begin(), south.end()); + case 3: + case 12: + possible_connections.insert(possible_connections.end(), west.begin(), west.end()); + possible_connections.insert(possible_connections.end(), east.begin(), east.end()); + case 4: + case 11: + possible_connections.insert(possible_connections.end(), west.begin(), west.end()); + possible_connections.insert(possible_connections.end(), north.begin(), north.end()); + case 5: + case 10: + possible_connections.insert(possible_connections.end(), north.begin(), south.end()); + possible_connections.insert(possible_connections.end(), south.begin(), south.end()); + possible_connections.insert(possible_connections.end(), west.begin(), west.end()); + possible_connections.insert(possible_connections.end(), east.begin(), east.end()); + case 6: + case 9: + possible_connections.insert(possible_connections.end(), north.begin(), south.end()); + possible_connections.insert(possible_connections.end(), south.begin(), south.end()); + case 7: + case 8: + possible_connections.insert(possible_connections.end(), north.begin(), south.end()); + possible_connections.insert(possible_connections.end(), east.begin(), east.end()); + } + if (!candidate->allocated) { - if (candidate->x == x +1 && candidate->y == y) { + if (candidate->x == x +1 && candidate->y == y && is_in(candidate->mscase, west) && is_in(current_case, east)) { candidate->allocated = true; x = candidate->x; y = candidate->y; + current_case = candidate->mscase; line.push_back(*candidate); points_allocated++; break; } - else if (candidate->x == x -1 && candidate->y == y) { + else if (candidate->x == x -1 && candidate->y == y && is_in(candidate->mscase, east ) && is_in(current_case, west)) { x = candidate->x; y = candidate->y; + current_case = candidate->mscase; candidate->allocated = true; line.push_back(*candidate); points_allocated++; break; } - else if (candidate->x == x && candidate->y == y + 1) { + else if (candidate->x == x && candidate->y == y + 1 && is_in(candidate->mscase, south) && is_in(current_case, north)) { x = candidate->x; y = candidate->y; + current_case = candidate->mscase; candidate->allocated = true; line.push_back(*candidate); points_allocated++; break; } - else if (candidate->x == x && candidate->y == y - 1) { + else if (candidate->x == x && candidate->y == y - 1 && is_in(candidate->mscase, north) && is_in(current_case, south)) { x = candidate->x; y = candidate->y; + current_case = candidate->mscase; candidate->allocated = true; line.push_back(*candidate); points_allocated++;