| 611 | } |
| 612 | |
| 613 | static bool mergeRegions(rcRegion& rega, rcRegion& regb) |
| 614 | { |
| 615 | unsigned short aid = rega.id; |
| 616 | unsigned short bid = regb.id; |
| 617 | |
| 618 | // Duplicate current neighbourhood. |
| 619 | rcIntArray acon; |
| 620 | acon.resize(rega.connections.size()); |
| 621 | for (int i = 0; i < rega.connections.size(); ++i) |
| 622 | acon[i] = rega.connections[i]; |
| 623 | rcIntArray& bcon = regb.connections; |
| 624 | |
| 625 | // Find insertion point on A. |
| 626 | int insa = -1; |
| 627 | for (int i = 0; i < acon.size(); ++i) |
| 628 | { |
| 629 | if (acon[i] == bid) |
| 630 | { |
| 631 | insa = i; |
| 632 | break; |
| 633 | } |
| 634 | } |
| 635 | if (insa == -1) |
| 636 | return false; |
| 637 | |
| 638 | // Find insertion point on B. |
| 639 | int insb = -1; |
| 640 | for (int i = 0; i < bcon.size(); ++i) |
| 641 | { |
| 642 | if (bcon[i] == aid) |
| 643 | { |
| 644 | insb = i; |
| 645 | break; |
| 646 | } |
| 647 | } |
| 648 | if (insb == -1) |
| 649 | return false; |
| 650 | |
| 651 | // Merge neighbours. |
| 652 | rega.connections.clear(); |
| 653 | for (int i = 0, ni = acon.size(); i < ni-1; ++i) |
| 654 | rega.connections.push(acon[(insa+1+i) % ni]); |
| 655 | |
| 656 | for (int i = 0, ni = bcon.size(); i < ni-1; ++i) |
| 657 | rega.connections.push(bcon[(insb+1+i) % ni]); |
| 658 | |
| 659 | removeAdjacentNeighbours(rega); |
| 660 | |
| 661 | for (int j = 0; j < regb.floors.size(); ++j) |
| 662 | addUniqueFloorRegion(rega, regb.floors[j]); |
| 663 | rega.spanCount += regb.spanCount; |
| 664 | regb.spanCount = 0; |
| 665 | regb.connections.resize(0); |
| 666 | |
| 667 | return true; |
| 668 | } |
| 669 | |
| 670 | static bool isRegionConnectedToBorder(const rcRegion& reg) |
no test coverage detected