private int DoSmoothing(Otri badotri, Vertex torg, Vertex tdest, Vertex tapex,
ref double[] newloc)
{
int numpoints_p = 0;// keeps the number of points in a star of point p, q, r
int numpoints_q = 0;
int numpoints_r = 0;
//int i;
double[] possibilities = new double[6];//there can be more than one possibilities
int num_pos = 0; // number of possibilities
int flag1 = 0, flag2 = 0, flag3 = 0;
bool newLocFound = false;
double[] points_p = new double[500];// keeps the points in a star of point p, q, r
double[] points_q = new double[500];
double[] points_r = new double[500];
//vertex v1, v2, v3; // for ccw test
//double p1[2], p2[2], p3[2];
//double temp[2];
//********************* TRY TO RELOCATE POINT "p" ***************
// get the surrounding points of p, so this gives us the triangles
numpoints_p = GetStarPoints(badotri, torg, tdest, tapex, 1, ref points_p);
// check if the points in counterclockwise order
// p1[0] = points_p[0]; p1[1] = points_p[1];
// p2[0] = points_p[2]; p2[1] = points_p[3];
// p3[0] = points_p[4]; p3[1] = points_p[5];
// v1 = (vertex)p1; v2 = (vertex)p2; v3 = (vertex)p3;
// if(counterclockwise(m,b,v1,v2,v3) < 0){
// // reverse the order to ccw
// for(i = 0; i < numpoints_p/2; i++){
// temp[0] = points_p[2*i];
// temp[1] = points_p[2*i+1];
// points_p[2*i] = points_p[2*(numpoints_p-1)-2*i];
// points_p[2*i+1] = points_p[2*(numpoints_p-1)+1-2*i];
// points_p[2*(numpoints_p-1)-2*i] = temp[0];
// points_p[2*(numpoints_p-1)+1-2*i] = temp[1];
// }
// }
// m.counterclockcount--;
// INTERSECTION OF PETALS
// first check whether the star angles are appropriate for relocation
if (torg.type == VertexType.FreeVertex && numpoints_p != 0 && ValidPolygonAngles(numpoints_p, points_p))
{
//newLocFound = getPetalIntersection(m, b, numpoints_p, points_p, newloc);
//newLocFound = getPetalIntersectionBruteForce(m, b,numpoints_p, points_p, newloc,torg[0],torg[1]);
if (behavior.MaxAngle == 0.0)
{
newLocFound = GetWedgeIntersectionWithoutMaxAngle(numpoints_p, points_p, ref newloc);
}
else
{
newLocFound = GetWedgeIntersection(numpoints_p, points_p, ref newloc);
}
//printf("call petal intersection for p\n");
// make sure the relocated point is a free vertex
if (newLocFound)
{
possibilities[0] = newloc[0];// something found
possibilities[1] = newloc[1];
num_pos++;// increase the number of possibilities
flag1 = 1;
}
}
//********************* TRY TO RELOCATE POINT "q" ***************
// get the surrounding points of q, so this gives us the triangles
numpoints_q = GetStarPoints(badotri, torg, tdest, tapex, 2, ref points_q);
// // check if the points in counterclockwise order
// v1[0] = points_q[0]; v1[1] = points_q[1];
// v2[0] = points_q[2]; v2[1] = points_q[3];
// v3[0] = points_q[4]; v3[1] = points_q[5];
// if(counterclockwise(m,b,v1,v2,v3) < 0){
// // reverse the order to ccw
// for(i = 0; i < numpoints_q/2; i++){
// temp[0] = points_q[2*i];
// temp[1] = points_q[2*i+1];
// points_q[2*i] = points_q[2*(numpoints_q-1)-2*i];
// points_q[2*i+1] = points_q[2*(numpoints_q-1)+1-2*i];
// points_q[2*(numpoints_q-1)-2*i] = temp[0];
// points_q[2*(numpoints_q-1)+1-2*i] = temp[1];
// }
// }
// m.counterclockcount--;
// INTERSECTION OF PETALS
// first check whether the star angles are appropriate for relocation
if (tdest.type == VertexType.FreeVertex && numpoints_q != 0 && ValidPolygonAngles(numpoints_q, points_q))
{
//newLocFound = getPetalIntersection(m, b,numpoints_q, points_q, newloc);
//newLocFound = getPetalIntersectionBruteForce(m, b,numpoints_q, points_q, newloc,tapex[0],tapex[1]);
if (behavior.MaxAngle == 0.0)
{
newLocFound = GetWedgeIntersectionWithoutMaxAngle(numpoints_q, points_q, ref newloc);
}
else
{
newLocFound = GetWedgeIntersection(numpoints_q, points_q, ref newloc);
}
//printf("call petal intersection for q\n");
// make sure the relocated point is a free vertex
if (newLocFound)
{
possibilities[2] = newloc[0];// something found
possibilities[3] = newloc[1];
num_pos++;// increase the number of possibilities
flag2 = 2;
}
}
//********************* TRY TO RELOCATE POINT "q" ***************
// get the surrounding points of r, so this gives us the triangles
numpoints_r = GetStarPoints(badotri, torg, tdest, tapex, 3, ref points_r);
// check if the points in counterclockwise order
// v1[0] = points_r[0]; v1[1] = points_r[1];
// v2[0] = points_r[2]; v2[1] = points_r[3];
// v3[0] = points_r[4]; v3[1] = points_r[5];
// if(counterclockwise(m,b,v1,v2,v3) < 0){
// // reverse the order to ccw
// for(i = 0; i < numpoints_r/2; i++){
// temp[0] = points_r[2*i];
// temp[1] = points_r[2*i+1];
// points_r[2*i] = points_r[2*(numpoints_r-1)-2*i];
// points_r[2*i+1] = points_r[2*(numpoints_r-1)+1-2*i];
// points_r[2*(numpoints_r-1)-2*i] = temp[0];
// points_r[2*(numpoints_r-1)+1-2*i] = temp[1];
// }
// }
// m.counterclockcount--;
// INTERSECTION OF PETALS
// first check whether the star angles are appropriate for relocation
if (tapex.type == VertexType.FreeVertex && numpoints_r != 0 && ValidPolygonAngles(numpoints_r, points_r))
{
//newLocFound = getPetalIntersection(m, b,numpoints_r, points_r, newloc);
//newLocFound = getPetalIntersectionBruteForce(m, b,numpoints_r, points_r, newloc,tdest[0],tdest[1]);
if (behavior.MaxAngle == 0.0)
{
newLocFound = GetWedgeIntersectionWithoutMaxAngle(numpoints_r, points_r, ref newloc);
}
else
{
newLocFound = GetWedgeIntersection(numpoints_r, points_r, ref newloc);
}
//printf("call petal intersection for r\n");
// make sure the relocated point is a free vertex
if (newLocFound)
{
possibilities[4] = newloc[0];// something found
possibilities[5] = newloc[1];
num_pos++;// increase the number of possibilities
flag3 = 3;
}
}
//printf("numpossibilities %d\n",num_pos);
//////////// AFTER FINISH CHECKING EVERY POSSIBILITY, CHOOSE ANY OF THE AVAILABLE ONE //////////////////////
if (num_pos > 0)
{
if (flag1 > 0)
{ // suggest to relocate origin
newloc[0] = possibilities[0];
newloc[1] = possibilities[1];
return flag1;
}
else
{
if (flag2 > 0)
{ // suggest to relocate apex
newloc[0] = possibilities[2];
newloc[1] = possibilities[3];
return flag2;
}
else
{// suggest to relocate destination
if (flag3 > 0)
{
newloc[0] = possibilities[4];
newloc[1] = possibilities[5];
return flag3;
}
}
}
}
return 0;// could not find any good relocation
}