| 496 | } |
| 497 | |
| 498 | void constraintSplit(s32 i0, s32 i1, s32 newVtx, Triangle* tri, Vec2f it, const Vec2f* c0, const Vec2f* c1, f32 prevConstIt) |
| 499 | { |
| 500 | // Find the matching edge. |
| 501 | s32 startIndex = -1; |
| 502 | s32 t0, t1; |
| 503 | for (s32 i = 0; i < 3; i++) |
| 504 | { |
| 505 | s32 a = i, b = (i + 1) % 3; |
| 506 | if ((tri->idx[a] == i0 && tri->idx[b] == i1) || (tri->idx[a] == i1 && tri->idx[b] == i0)) |
| 507 | { |
| 508 | startIndex = i; |
| 509 | t0 = tri->idx[a]; |
| 510 | t1 = tri->idx[b]; |
| 511 | break; |
| 512 | } |
| 513 | } |
| 514 | if (startIndex < 0) { return; } |
| 515 | |
| 516 | // Now see if the line intersects either of the other two edges. |
| 517 | for (s32 i = 1; i < 3; i++) |
| 518 | { |
| 519 | s32 a = (i + startIndex) % 3; |
| 520 | s32 b = (a + 1) % 3; |
| 521 | |
| 522 | s32 A = tri->idx[a]; |
| 523 | s32 B = tri->idx[b]; |
| 524 | |
| 525 | const Vec2f* v0 = &s_vertices[A]; |
| 526 | const Vec2f* v1 = &s_vertices[B]; |
| 527 | |
| 528 | // Compute the intersection between line segment c0->c1 and v0->v1 |
| 529 | f32 constInter, triEdgeInter; |
| 530 | if (!TFE_Math::lineSegmentIntersect(c0, c1, v0, v1, &constInter, &triEdgeInter)) |
| 531 | { |
| 532 | continue; |
| 533 | } |
| 534 | |
| 535 | if (constInter - prevConstIt < FLT_EPSILON) |
| 536 | { |
| 537 | // We aren't making any progress... |
| 538 | // Abort to avoid a long running or infinite loop. |
| 539 | PolyAssert(0); |
| 540 | return; |
| 541 | } |
| 542 | |
| 543 | // Constraint ends at vertex 'v0' or 'v1' |
| 544 | const bool atV0 = triEdgeInter <= eps; |
| 545 | const bool atV1 = triEdgeInter >= 1.0f - eps; |
| 546 | if (atV0 || atV1) |
| 547 | { |
| 548 | PolyAssert(i != 1 || !atV0); |
| 549 | PolyAssert(i != 2 || !atV1); |
| 550 | s32 endVertex = atV0 ? A : B; |
| 551 | // Triangles are: |
| 552 | // T(newVtx, endVertex, t0) |
| 553 | // T(newVtx, t1, endVertex) |
| 554 | |
| 555 | deleteTriangle(tri); |
no test coverage detected