   TJunction elimination on a single polygon
  I implemented a very simple and slow TJunction elimination algorithm only dealing with a polygon at a time. The problem is that sometimes it gets the UV's slightly off and i can't understant why. Here it is:void CMeshOptimizer::FixTJunction(CVector3D<float> *&Vertices, CVector2D<float> *&TexCoords, int &NumVertices){char *TJunction = new char[NumVertices];memset(TJunction, 0, NumVertices);int NumTJunction=0;int V1, V2, J;   for (V1=0; V1<NumVertices-2; V1++)for (V2=V1+2; V2<NumVertices; V2++){   for (J=0; J<NumVertices; J++)if (J!=V1 && J!=V2){float Dist = Distance(Vertices[V1], Vertices[J])+Distance(Vertices[J], Vertices[V2]);float Dist2 = Distance(Vertices[V1], Vertices[V2]);if (fabs(Dist-Dist2)<Optimizer_Epsilon){TJunction[J]=1;}}}NumTJunction=0;int tj = -1;for (V1=0; V1<NumVertices; V1++){NumTJunction += TJunction[V1];if (TJunction[V1] == 1)tj = V1;}int NewNumVertices = NumVertices - NumTJunction;CVector3D<float> *NewVertices = new CVector3D<float>[NewNumVertices]; CVector2D<float> *NewTexCoords = new CVector2D<float>[NewNumVertices]; int Current = 0;for (V1=0; V1<NumVertices; V1++){if (TJunction[V1]==0){NewVertices[Current] = Vertices[V1];if (TexCoords)NewTexCoords[Current] = TexCoords[V1];Current++;}}delete[] Vertices; Vertices = NULL;delete[] TexCoords;TexCoords = NULL;delete[] TJunction;TJunction = NULL;Vertices = NewVertices;TexCoords = NewTexCoords;NumVertices = NewNumVertices;}Any ideas on why it happens that sometimes incorrect UV's arise? can you help me with a better and/or simple algorithm? :D   