| 563 | } |
| 564 | |
| 565 | static void simplifyContour(dtTempContour& cont, const float maxError) |
| 566 | { |
| 567 | cont.npoly = 0; |
| 568 | |
| 569 | for (int i = 0; i < cont.nverts; ++i) |
| 570 | { |
| 571 | int j = (i+1) % cont.nverts; |
| 572 | // Check for start of a wall segment. |
| 573 | unsigned char ra = cont.verts[j*4+3]; |
| 574 | unsigned char rb = cont.verts[i*4+3]; |
| 575 | if (ra != rb) |
| 576 | cont.poly[cont.npoly++] = (unsigned short)i; |
| 577 | } |
| 578 | if (cont.npoly < 2) |
| 579 | { |
| 580 | // If there is no transitions at all, |
| 581 | // create some initial points for the simplification process. |
| 582 | // Find lower-left and upper-right vertices of the contour. |
| 583 | int llx = cont.verts[0]; |
| 584 | int llz = cont.verts[2]; |
| 585 | int lli = 0; |
| 586 | int urx = cont.verts[0]; |
| 587 | int urz = cont.verts[2]; |
| 588 | int uri = 0; |
| 589 | for (int i = 1; i < cont.nverts; ++i) |
| 590 | { |
| 591 | int x = cont.verts[i*4+0]; |
| 592 | int z = cont.verts[i*4+2]; |
| 593 | if (x < llx || (x == llx && z < llz)) |
| 594 | { |
| 595 | llx = x; |
| 596 | llz = z; |
| 597 | lli = i; |
| 598 | } |
| 599 | if (x > urx || (x == urx && z > urz)) |
| 600 | { |
| 601 | urx = x; |
| 602 | urz = z; |
| 603 | uri = i; |
| 604 | } |
| 605 | } |
| 606 | cont.npoly = 0; |
| 607 | cont.poly[cont.npoly++] = (unsigned short)lli; |
| 608 | cont.poly[cont.npoly++] = (unsigned short)uri; |
| 609 | } |
| 610 | |
| 611 | // Add points until all raw points are within |
| 612 | // error tolerance to the simplified shape. |
| 613 | for (int i = 0; i < cont.npoly; ) |
| 614 | { |
| 615 | int ii = (i+1) % cont.npoly; |
| 616 | |
| 617 | const int ai = (int)cont.poly[i]; |
| 618 | const int ax = (int)cont.verts[ai*4+0]; |
| 619 | const int az = (int)cont.verts[ai*4+2]; |
| 620 | |
| 621 | const int bi = (int)cont.poly[ii]; |
| 622 | const int bx = (int)cont.verts[bi*4+0]; |
no test coverage detected