- // if ( isBad && myHelper->HasRealSeam() )
- // {
- // // detect a case where a face intersects the seam
- // for ( int iPar = 1; iPar < 3; ++iPar )
- // if ( iPar & myHelper->GetPeriodicIndex() )
- // {
- // double min = uv[0].Coord( iPar ), max = uv[0].Coord( iPar );
- // for ( int i = 1; i < nbN; ++i )
- // {
- // min = Min( min, uv[i].Coord( iPar ));
- // max = Max( max, uv[i].Coord( iPar ));
- // }
- // }
- // }
+ if ( isBad && myHelper->HasRealSeam() )
+ {
+ // fix uv for a case where a face intersects the seam
+ for ( int iPar = 1; iPar < 3; ++iPar )
+ if ( iPar & myHelper->GetPeriodicIndex() )
+ {
+ double max = uv[0].Coord( iPar );
+ for ( int i = 1; i < nbN; ++i )
+ max = Max( max, uv[i].Coord( iPar ));
+
+ for ( int i = 0; i < nbN; ++i )
+ {
+ double par = uv[i].Coord( iPar );
+ double shift = ShapeAnalysis::AdjustByPeriod( par, max, myHelper->GetPeriod( iPar ));
+ uv[i].SetCoord( iPar, par + shift );
+ }
+ }
+ double sign1 = getArea( uv[0], uv[1], uv[2] );
+ double sign2 = getArea( uv[0], uv[2], uv[3] );
+ if ( sign1 * sign2 < 0 )
+ {
+ sign2 = getArea( uv[1], uv[2], uv[3] );
+ sign1 = getArea( uv[1], uv[3], uv[0] );
+ if ( sign1 * sign2 < 0 )
+ continue; // this should not happen
+ }
+ isBad = ( sign1 * okSign < 0 );
+ }
+