I have a VEX program to connect those yellow points (grouped as “loosepts”) to its closest point in the mesh.
And it cannot be connected to another yellow point “loosepts”, nor to any of those points outside the red circle (“outerpts” point
group).
So, to prevent those situations, I added a simple if() statement inside the for() loop that searches for the closest point.
int pts = npoints(0); int closestpt = -1; float mindist = 0.0; for(int i = 0; i< pts; i++){//run over all pts int isouterpts = inpointgroup(0,"outerpts",i); int isloosepts = inpointgroup(0,"loosepts",i); //filter some points if(i == @ptnum || isouterpts==1 || isloosepts==1){ continue; } //vars vector cP = point(0,"P",i); float curdist = distance(@P,cP); if(i == 0){//assign mindist mindist = curdist; closestpt = i; } else if(curdist < mindist){ mindist = curdist; closestpt = i; } } printf("mindist: %f\nclosestpt: %d\n\n", mindist,closestpt); if(closestpt != -1){ //connect current point to closestpt int newprim = addprim(0,"polyline"); addvertex(0,newprim, @ptnum); addvertex(0,newprim, closestpt); }
The problem is that this code never finds a closest point, and never changes the “closestpt” variable, so it never runs the connection algorythm.
What have I done wrong?
The question is also if VEX nested loops and if() statements run in a particular way I'm not aware of
I'm having problem with this kind of code since weeks ago and can't find help