| 608 | }*/ |
| 609 | |
| 610 | void GetVertexOrdering(hemicube_point *t, int nv, int *vlt, int *vlb, int *vrt, int *vrb, float *top_y, float *bottom_y, |
| 611 | int *left_edge_dir) { |
| 612 | int i; |
| 613 | float min_y, max_y; |
| 614 | int min_index_l, min_index_r, max_index; |
| 615 | |
| 616 | // Scan all vertices, set min_y_ind to vertex with smallest y coordinate. |
| 617 | |
| 618 | *bottom_y = 0; |
| 619 | *top_y = 0; |
| 620 | |
| 621 | min_index_l = max_index = 0; |
| 622 | max_y = min_y = t[0].sy; |
| 623 | for (i = 1; i < nv; i++) { |
| 624 | if (t[i].sy < min_y) |
| 625 | min_y = t[min_index_l = i].sy; |
| 626 | else if (t[i].sy > max_y) |
| 627 | max_y = t[max_index = i].sy; |
| 628 | } |
| 629 | if (min_y == max_y) |
| 630 | return; |
| 631 | |
| 632 | // Scan in ascending order to find the last top-edge point */ |
| 633 | min_index_r = min_index_l; |
| 634 | while (t[min_index_r].sy == min_y) |
| 635 | min_index_r = NextIndex(min_index_r, nv); |
| 636 | min_index_r = PrevIndex(min_index_r, nv); |
| 637 | |
| 638 | // Now scan in descending order to find the first top-edge point |
| 639 | while (t[min_index_l].sy == min_y) |
| 640 | min_index_l = PrevIndex(min_index_l, nv); |
| 641 | min_index_l = NextIndex(min_index_l, nv); |
| 642 | |
| 643 | *left_edge_dir = -1; |
| 644 | if (t[min_index_l].sx != t[min_index_r].sx) { |
| 645 | // If the top is flat, just see which of the ends is leftmost |
| 646 | if (t[min_index_l].sx > t[min_index_r].sx) { |
| 647 | *left_edge_dir = 1; |
| 648 | |
| 649 | int temp = min_index_l; |
| 650 | min_index_l = min_index_r; |
| 651 | min_index_r = temp; |
| 652 | } |
| 653 | } else { |
| 654 | // Point to the downward end of the first line of each of the |
| 655 | // two edges down from the top |
| 656 | int next_index = min_index_r; |
| 657 | next_index = NextIndex(next_index, nv); |
| 658 | int prev_index = min_index_r; |
| 659 | prev_index = PrevIndex(prev_index, nv); |
| 660 | |
| 661 | /* Calculate X and Y lengths from the top vertex to the end of |
| 662 | the first line down each edge; use those to compare slopes |
| 663 | and see which line is leftmost */ |
| 664 | float deltaXN = t[next_index].sx - t[min_index_l].sx; |
| 665 | float deltaYN = t[next_index].sy - t[min_index_l].sy; |
| 666 | float deltaXP = t[prev_index].sx - t[min_index_l].sx; |
| 667 | float deltaYP = t[prev_index].sy - t[min_index_l].sy; |
no test coverage detected