1
+ #pragma once
2
+
1
3
#include < string>
2
4
#include < vector>
3
5
#include < fstream>
10
12
#include " levelz/coordinate.h"
11
13
#include " levelz/block.h"
12
14
#include " levelz/level.h"
15
+ #include " levelz/matrix.h"
13
16
14
17
using namespace LevelZ ;
15
18
@@ -88,40 +91,14 @@ namespace {
88
91
static std::vector<Coordinate2D> read2DPoints (const std::string& input) {
89
92
std::vector<Coordinate2D> points;
90
93
91
- const std::regex matrix (" [\\ [\\ ]()]" );
92
94
const std::vector<std::string> split = splitString (input, " *" );
93
95
94
96
for (std::string s0 : split) {
95
97
if (s0.empty ()) continue ;
96
98
97
99
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);
125
102
} else
126
103
points.push_back (Coordinate2D::from_string (s0));
127
104
}
@@ -139,37 +116,8 @@ namespace {
139
116
if (s0.empty ()) continue ;
140
117
141
118
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);
173
121
} else
174
122
points.push_back (Coordinate3D::from_string (s0));
175
123
}
0 commit comments