| 459 | // they all fail. If they all fail, the polygon is too complex to be decomposed with this method. |
| 460 | |
| 461 | bool decompPoly::decompose() |
| 462 | { |
| 463 | // Must have at least 3 verts to form a poly |
| 464 | if(mVertList.size() < 3) |
| 465 | return false; |
| 466 | |
| 467 | // Clear out any previously stored tris |
| 468 | mTris.clear(); |
| 469 | |
| 470 | // Initialize the edge list with the default edges |
| 471 | initEdgeList(); |
| 472 | |
| 473 | twoIndices otherVerts, outerVerts2; |
| 474 | U32 counter = 0; |
| 475 | U8 uniqueVertAttempt = 0; |
| 476 | U8 formTriAttempt = 0; |
| 477 | bool notUnique = false; |
| 478 | |
| 479 | // The main decomposition loop |
| 480 | while(mEdgeList.size() > 3) |
| 481 | { |
| 482 | // Find outermost vert in poly, LMV |
| 483 | U8 outerVertIdx; |
| 484 | |
| 485 | switch(uniqueVertAttempt) |
| 486 | { |
| 487 | case 0: outerVertIdx = leftmost(); break; |
| 488 | case 1: outerVertIdx = rightmost(); break; |
| 489 | case 2: outerVertIdx = uppermost(); break; |
| 490 | case 3: outerVertIdx = uppermost(); break; |
| 491 | default: outerVertIdx = leftmost(); |
| 492 | } |
| 493 | |
| 494 | // Find edges that share LMV |
| 495 | twoIndices edgesIdx = findEdges(outerVertIdx, notUnique); |
| 496 | |
| 497 | // If vert shares more than two edges, try decomposing from different direction |
| 498 | if(notUnique) |
| 499 | { |
| 500 | if(uniqueVertAttempt < 4) |
| 501 | { |
| 502 | uniqueVertAttempt++; |
| 503 | continue; |
| 504 | } |
| 505 | else |
| 506 | { |
| 507 | newPoly(); |
| 508 | return false; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | // Sanity check |
| 513 | if(edgesIdx.i1 >= mEdgeList.size() || edgesIdx.i2 >= mEdgeList.size()) |
| 514 | { |
| 515 | newPoly(); |
| 516 | return false; |
| 517 | } |
| 518 |
no test coverage detected