1+ #pragma once
2+
13#include < string>
24#include < vector>
35#include < fstream>
1012#include " levelz/coordinate.h"
1113#include " levelz/block.h"
1214#include " levelz/level.h"
15+ #include " levelz/matrix.h"
1316
1417using namespace LevelZ ;
1518
@@ -88,40 +91,14 @@ namespace {
8891 static std::vector<Coordinate2D> read2DPoints (const std::string& input) {
8992 std::vector<Coordinate2D> points;
9093
91- const std::regex matrix (" [\\ [\\ ]()]" );
9294 const std::vector<std::string> split = splitString (input, " *" );
9395
9496 for (std::string s0 : split) {
9597 if (s0.empty ()) continue ;
9698
9799 if (s0.rfind (' (' , 0 ) == 0 && s0.rfind (' ]' ) == s0.size () - 1 ) {
98- s0 = std::regex_replace (s0, matrix, " " );
99-
100- unsigned int i = 0 ;
101- size_t cpos = 0 ;
102- std::string s1;
103-
104- int x1, x2, y1, y2;
105- double cx, cy;
106-
107- while ((cpos = s0.find (' ,' )) != std::string::npos) {
108- s1 = s0.substr (0 , cpos);
109- switch (i) {
110- case 0 : x1 = std::stoi (s1); break ;
111- case 1 : x2 = std::stoi (s1); break ;
112- case 2 : y1 = std::stoi (s1); break ;
113- case 3 : y2 = std::stoi (s1); break ;
114- case 4 : cx = std::stod (s1); break ;
115- case 5 : cy = std::stod (s1); break ;
116- }
117-
118- s0.erase (0 , cpos + 1 );
119- i++;
120- }
121-
122- for (int x = x1; x < x2; x++)
123- for (int y = y1; y < y2; y++)
124- points.push_back (Coordinate2D (cx + x, cy + y));
100+ for (const Coordinate2D& c : LevelZ::CoordinateMatrix2D::from_string (s0))
101+ points.push_back (c);
125102 } else
126103 points.push_back (Coordinate2D::from_string (s0));
127104 }
@@ -139,37 +116,8 @@ namespace {
139116 if (s0.empty ()) continue ;
140117
141118 if (s0.rfind (' (' , 0 ) == 0 && s0.rfind (' ]' ) == s0.size () - 1 ) {
142- s0 = std::regex_replace (s0, matrix, " " );
143-
144- unsigned int i = 0 ;
145- size_t cpos = 0 ;
146- std::string s1;
147-
148- int x1, x2, y1, y2, z1, z2;
149- double cx, cy, cz;
150-
151- while ((cpos = s0.find (' ,' )) != std::string::npos) {
152- s1 = s0.substr (0 , cpos);
153- switch (i) {
154- case 0 : x1 = std::stoi (s1); break ;
155- case 1 : x2 = std::stoi (s1); break ;
156- case 2 : y1 = std::stoi (s1); break ;
157- case 3 : y2 = std::stoi (s1); break ;
158- case 4 : z1 = std::stoi (s1); break ;
159- case 5 : z2 = std::stoi (s1); break ;
160- case 6 : cx = std::stod (s1); break ;
161- case 7 : cy = std::stod (s1); break ;
162- case 8 : cz = std::stod (s1); break ;
163- }
164-
165- s0.erase (0 , cpos + 1 );
166- i++;
167- }
168-
169- for (int x = x1; x < x2; x++)
170- for (int y = y1; y < y2; y++)
171- for (int z = z1; z < z2; z++)
172- points.push_back (Coordinate3D (cx + x, cy + y, cz + z));
119+ for (const Coordinate3D& c : LevelZ::CoordinateMatrix3D::from_string (s0))
120+ points.push_back (c);
173121 } else
174122 points.push_back (Coordinate3D::from_string (s0));
175123 }
0 commit comments