some operations require that inside test is performed, not pre-calculated
| 674 | |
| 675 | // some operations require that inside test is performed, not pre-calculated |
| 676 | void PolyVertices::Split(TLVertexTable& mesh, PolyVertices& clip, PolyVertices& rest, Vector3Par normal, Coord d) |
| 677 | { |
| 678 | // initialize resulting polygon |
| 679 | if (_n < 3) |
| 680 | { |
| 681 | rest._n = clip._n = 0; |
| 682 | return; |
| 683 | } |
| 684 | |
| 685 | // search for first vertex inside clipping half-space |
| 686 | int i; |
| 687 | VertexIndex* pVertex; // previous vertex |
| 688 | VertexIndex* aVertex; // actual vertex |
| 689 | |
| 690 | pVertex = _vertex + _n - 1; |
| 691 | bool pOut = normal * mesh.TransPosA(*pVertex) + d < 0; |
| 692 | |
| 693 | int nClipped = 0; |
| 694 | int nRest = 0; |
| 695 | |
| 696 | for (i = 0; i < _n; i++) |
| 697 | { |
| 698 | aVertex = _vertex + i; |
| 699 | bool aOut = normal * mesh.TransPosA(*aVertex) + d < 0; |
| 700 | // four possible situations |
| 701 | if (aOut != pOut) |
| 702 | { |
| 703 | // edge going in or out |
| 704 | Coord t = Intersect(mesh.TransPosA(*aVertex), mesh.TransPosA(*pVertex), normal, d); |
| 705 | rest._vertex[nRest++] = clip._vertex[nClipped++] = Interpolate(mesh, *aVertex, *pVertex, t); |
| 706 | } |
| 707 | if (!aOut) |
| 708 | { |
| 709 | clip._vertex[nClipped++] = *aVertex; // point in |
| 710 | } |
| 711 | else |
| 712 | { |
| 713 | rest._vertex[nRest++] = *aVertex; // point out (in rest) |
| 714 | } |
| 715 | pVertex = aVertex; |
| 716 | pOut = aOut; |
| 717 | } |
| 718 | |
| 719 | PoseidonAssert(nClipped <= MaxPoly); |
| 720 | PoseidonAssert(nRest <= MaxPoly); |
| 721 | |
| 722 | if (nClipped < 3) |
| 723 | { |
| 724 | clip._n = 0; // polygon completely out |
| 725 | } |
| 726 | else |
| 727 | { |
| 728 | clip._n = nClipped; |
| 729 | } |
| 730 | if (nRest < 3) |
| 731 | { |
| 732 | rest._n = 0; // polygon completely out |
| 733 | } |
no test coverage detected