diff options
| -rw-r--r-- | Source/Panel.cpp | 34 |
1 files changed, 15 insertions, 19 deletions
| diff --git a/Source/Panel.cpp b/Source/Panel.cpp index 4ed5c51..b204a28 100644 --- a/Source/Panel.cpp +++ b/Source/Panel.cpp | |||
| @@ -227,8 +227,8 @@ void PuzzleSerializer::WriteIntersections(const Puzzle& p, int id) { | |||
| 227 | // Dots | 227 | // Dots |
| 228 | for (int x=0; x<p.width; x++) { | 228 | for (int x=0; x<p.width; x++) { |
| 229 | for (int y=0; y<p.height; y++) { | 229 | for (int y=0; y<p.height; y++) { |
| 230 | if (p.grid[x][y].dot == Cell::Dot::NONE) continue; | ||
| 231 | if (x%2 == y%2) continue; // Cells are invalid, intersections are already handled. | 230 | if (x%2 == y%2) continue; // Cells are invalid, intersections are already handled. |
| 231 | if (p.grid[x][y].dot == Cell::Dot::NONE) continue; | ||
| 232 | 232 | ||
| 233 | // We need to introduce a new segment -- | 233 | // We need to introduce a new segment -- |
| 234 | // Locate the segment we're breaking | 234 | // Locate the segment we're breaking |
| @@ -272,40 +272,36 @@ void PuzzleSerializer::WriteIntersections(const Puzzle& p, int id) { | |||
| 272 | // Gaps | 272 | // Gaps |
| 273 | for (int x=0; x<p.width; x++) { | 273 | for (int x=0; x<p.width; x++) { |
| 274 | for (int y=0; y<p.height; y++) { | 274 | for (int y=0; y<p.height; y++) { |
| 275 | if (p.grid[x][y].gap == Cell::Gap::NONE) continue; | ||
| 276 | if (x%2 == y%2) continue; // Cells are invalid, intersections are already handled. | 275 | if (x%2 == y%2) continue; // Cells are invalid, intersections are already handled. |
| 276 | if (p.grid[x][y].gap == Cell::Gap::NONE) continue; | ||
| 277 | 277 | ||
| 278 | for (int i=0; i<connections_a.size(); i++) { | ||
| 279 | auto [x1, y1] = loc_to_xy(p, connections_a[i]); | ||
| 280 | auto [x2, y2] = loc_to_xy(p, connections_b[i]); | ||
| 281 | if ((x1+1 == x && x2-1 == x && y1 == y && y2 == y) || | ||
| 282 | (y1+1 == y && y2-1 == y && x1 == x && x2 == x)) { | ||
| 283 | int other_connection = connections_b[i]; | ||
| 284 | connections_b[i] = static_cast<int>(intersectionFlags.size()); // This endpoint | ||
| 285 | |||
| 286 | connections_a.push_back(other_connection); | ||
| 287 | connections_b.push_back(static_cast<int>(intersectionFlags.size() + 1)); // Next endpoint | ||
| 288 | break; | ||
| 289 | } | ||
| 290 | } | ||
| 291 | // Add the two halves of this gap to the end | ||
| 292 | float xPos = min + (x/2.0f) * width_interval; | 278 | float xPos = min + (x/2.0f) * width_interval; |
| 293 | float yPos = max - (y/2.0f) * height_interval; | 279 | float yPos = max - (y/2.0f) * height_interval; |
| 294 | // Reminder: Y goes from 0.0 (bottom) to 1.0 (top) | 280 | // Reminder: Y goes from 0.0 (bottom) to 1.0 (top) |
| 295 | if (x%2 == 0) { // Vertical gap | 281 | if (x%2 == 0) { // Vertical gap |
| 282 | connections_a.push_back(xy_to_loc(p, x, y-1)); | ||
| 283 | connections_b.push_back(static_cast<int>(intersectionFlags.size())); // This endpoint | ||
| 296 | intersectionLocations.push_back(xPos); | 284 | intersectionLocations.push_back(xPos); |
| 297 | intersectionLocations.push_back(yPos + verti_gap_size / 2); | 285 | intersectionLocations.push_back(yPos + verti_gap_size / 2); |
| 286 | intersectionFlags.push_back(Flags::HAS_NO_CONN | Flags::HAS_VERTI_CONN); | ||
| 287 | |||
| 288 | connections_a.push_back(xy_to_loc(p, x, y+1)); | ||
| 289 | connections_b.push_back(static_cast<int>(intersectionFlags.size())); // This endpoint | ||
| 298 | intersectionLocations.push_back(xPos); | 290 | intersectionLocations.push_back(xPos); |
| 299 | intersectionLocations.push_back(yPos - verti_gap_size / 2); | 291 | intersectionLocations.push_back(yPos - verti_gap_size / 2); |
| 300 | intersectionFlags.push_back(Flags::HAS_NO_CONN | Flags::HAS_VERTI_CONN); | 292 | intersectionFlags.push_back(Flags::HAS_NO_CONN | Flags::HAS_VERTI_CONN); |
| 301 | intersectionFlags.push_back(Flags::HAS_NO_CONN | Flags::HAS_VERTI_CONN); | ||
| 302 | } else if (y%2 == 0) { // Horizontal gap | 293 | } else if (y%2 == 0) { // Horizontal gap |
| 294 | connections_a.push_back(xy_to_loc(p, x-1, y)); | ||
| 295 | connections_b.push_back(static_cast<int>(intersectionFlags.size())); // This endpoint | ||
| 303 | intersectionLocations.push_back(xPos - horiz_gap_size / 2); | 296 | intersectionLocations.push_back(xPos - horiz_gap_size / 2); |
| 304 | intersectionLocations.push_back(yPos); | 297 | intersectionLocations.push_back(yPos); |
| 298 | intersectionFlags.push_back(Flags::HAS_NO_CONN | Flags::HAS_HORIZ_CONN); | ||
| 299 | |||
| 300 | connections_a.push_back(xy_to_loc(p, x+1, y)); | ||
| 301 | connections_b.push_back(static_cast<int>(intersectionFlags.size())); // This endpoint | ||
| 305 | intersectionLocations.push_back(xPos + horiz_gap_size / 2); | 302 | intersectionLocations.push_back(xPos + horiz_gap_size / 2); |
| 306 | intersectionLocations.push_back(yPos); | 303 | intersectionLocations.push_back(yPos); |
| 307 | intersectionFlags.push_back(Flags::HAS_NO_CONN | Flags::HAS_VERTI_CONN); | 304 | intersectionFlags.push_back(Flags::HAS_NO_CONN | Flags::HAS_HORIZ_CONN); |
| 308 | intersectionFlags.push_back(Flags::HAS_NO_CONN | Flags::HAS_VERTI_CONN); | ||
| 309 | } | 305 | } |
| 310 | } | 306 | } |
| 311 | } | 307 | } |
