bool CMesh::TVertex::CheckMaterialAtEdge(TVertex *pVert0, TVertex *pVert1) { // Parameters specify a new edge that will form after the removal of the current vertex // This function finds intersections of triangle edges that fan out of the vertex being removed // with the new edge, and makes sure interpolated material stays the same at the intersection points // This makes sure the vertex removal will not cause material change in the area of any of the changed triangles int iTri, i; TTriangle *pTri; TVertex *pOther[2]; CVector<2> vEdge0, vEdge1, vThis, vOther; float fTEdge, fTOther, fME0, fME1, fMOther, fME, fMOtherMid; vEdge0.Set(pVert0->m_vCoord); vEdge1.Set(pVert1->m_vCoord); vThis.Set(m_vCoord); fME0 = (pVert0->m_iMaterial == m_iMaterial); fME1 = (pVert1->m_iMaterial == m_iMaterial); for (iTri = 0; iTri < m_pTriangles->m_iCount; iTri++) { pTri = m_pTriangles->At(iTri); pTri->GetOtherVertices(this, pOther[0], pOther[1]); for (i = 0; i < 2; i++) { vOther.Set(pOther[i]->m_vCoord); if (!IntersectSegments(vEdge0, vEdge1, vThis, vOther, fTEdge, fTOther)) continue; fMOther = (pOther[i]->m_iMaterial == m_iMaterial); fME = fME0 + (fME1 - fME0) * fTEdge; fMOtherMid = 1 + (fMOther - 1) * fTOther; if (!IsEqual(fME, fMOtherMid)) return false; } } return true; }
void CTrack::MapOriginalPoint(DISTORT* pDistort, CPoint* lpSrc, CPoint* lpDst) { // Compute p0 and p2 based on the X percentage DISTORT& Distort = *pDistort; int Numer = lpSrc->x - Distort.RectOrig.left; int Denom = Distort.RectOrig.right - Distort.RectOrig.left; CPoint p0, p1, p2, p3; if (Numer == Denom /*UNITY*/) { p0 = Distort.p[1]; p2 = Distort.p[2]; } else if (!Numer) { p0 = Distort.p[0]; p2 = Distort.p[3]; } else { double fPercentX = (double)Numer / Denom; p0.x = Distort.p[0].x + ((Distort.p[1].x - Distort.p[0].x) * fPercentX); p0.y = Distort.p[0].y + ((Distort.p[1].y - Distort.p[0].y) * fPercentX); p2.x = Distort.p[2].x + ((Distort.p[3].x - Distort.p[2].x) * (-fPercentX+1.0)); p2.y = Distort.p[2].y + ((Distort.p[3].y - Distort.p[2].y) * (-fPercentX+1.0)); } // Compute P1 and p3 based on the Y percentage Numer = lpSrc->y - Distort.RectOrig.top; Denom = Distort.RectOrig.bottom - Distort.RectOrig.top; if (Numer == Denom /*UNITY*/) { p1 = Distort.p[2]; p3 = Distort.p[3]; } else if (!Numer) { p1 = Distort.p[1]; p3 = Distort.p[0]; } else { double fPercentY = (double)Numer / Denom; p1.x = Distort.p[1].x + ((Distort.p[2].x - Distort.p[1].x) * fPercentY); p1.y = Distort.p[1].y + ((Distort.p[2].y - Distort.p[1].y) * fPercentY); p3.x = Distort.p[3].x + ((Distort.p[0].x - Distort.p[3].x) * (-fPercentY+1.0)); p3.y = Distort.p[3].y + ((Distort.p[0].y - Distort.p[3].y) * (-fPercentY+1.0)); } // Compute the points at the same x and y percentages of each of the 4 segments // The intersection of P02 and P13 is our new point IntersectSegments(p0, p2, p1, p3, lpDst); }