(output *B2DistanceOutput, cache *B2SimplexCache, input *B2DistanceInput)
| 564 | } |
| 565 | |
| 566 | func B2Distance(output *B2DistanceOutput, cache *B2SimplexCache, input *B2DistanceInput) { |
| 567 | b2_gjkCalls++ |
| 568 | |
| 569 | proxyA := &input.ProxyA |
| 570 | proxyB := &input.ProxyB |
| 571 | |
| 572 | transformA := input.TransformA |
| 573 | transformB := input.TransformB |
| 574 | |
| 575 | // Initialize the simplex. |
| 576 | simplex := MakeB2Simplex() |
| 577 | simplex.ReadCache(cache, proxyA, transformA, proxyB, transformB) |
| 578 | |
| 579 | // Get simplex vertices as an array. |
| 580 | vertices := &simplex.M_vs |
| 581 | k_maxIters := 20 |
| 582 | |
| 583 | // These store the vertices of the last simplex so that we |
| 584 | // can check for duplicates and prevent cycling. |
| 585 | saveA := make([]int, 3) |
| 586 | saveB := make([]int, 3) |
| 587 | saveCount := 0 |
| 588 | |
| 589 | // Main iteration loop. |
| 590 | iter := 0 |
| 591 | for iter < k_maxIters { |
| 592 | // Copy simplex so we can identify duplicates. |
| 593 | saveCount = simplex.M_count |
| 594 | for i := 0; i < saveCount; i++ { |
| 595 | saveA[i] = vertices[i].IndexA |
| 596 | saveB[i] = vertices[i].IndexB |
| 597 | } |
| 598 | |
| 599 | switch simplex.M_count { |
| 600 | case 1: |
| 601 | break |
| 602 | |
| 603 | case 2: |
| 604 | simplex.Solve2() |
| 605 | break |
| 606 | |
| 607 | case 3: |
| 608 | simplex.Solve3() |
| 609 | break |
| 610 | |
| 611 | default: |
| 612 | B2Assert(false) |
| 613 | } |
| 614 | |
| 615 | // If we have 3 points, then the origin is in the corresponding triangle. |
| 616 | if simplex.M_count == 3 { |
| 617 | break |
| 618 | } |
| 619 | |
| 620 | // Get search direction. |
| 621 | d := simplex.GetSearchDirection() |
| 622 | |
| 623 | // Ensure the search direction is numerically fit. |
no test coverage detected