[GRASS5] v.spag loop and threshold

Radim Blazek Radim.Blazek at dhv.cz
Mon May 29 13:10:17 EDT 2000


Hi vector users,

A)  v.spag sometimes get stuck in a loop in which it creates the same line over
     and over again  (known bug). I found one reason in linecros.c  find_intersection ():
  [...]
  d  = D; 
  if (fabs (d) > EPSILON)  {  [...]  }  [...]
  /* segments are colinear. check for overlap */   [...]
  if (ax1 == ax2 && bx1==bx2 && ax1==bx1)   {    [...]   }else{
        if (ax1 > ax2)  {   t=ax1;  ax1=ax2;   ax2=t;  }
        if (bx1 > bx2)  {   t=bx1;  bx1=bx2;   bx2=t;  }
        if (ax1 > bx2) return 0;
        if (ax2 < bx1) return 0;
        if (ax1 == bx2)  { *x = ax1;  *y = ay1;   return 1;   }
        if (ax2 == bx1)  { *x = ax2;  *y = ay2;   return 1;   }
  }

A1)  if  ax1 > ax2  then   t=ax1;  ax1=ax2;   ax2=t;  and  for example *x = ax1( = original ax2!!!);  *y = ay1;  
       which is not the intersection
A2)  if  ax1 == ax2  == bx1 < bx2 (because EPSILON = 1.0e-10 and vectors may not be colinear)  
       and ay1 == by1 then *x = ax2;  *y = ay2;  which is not the intersection

My suggestion is: 
  if (ax1 == ax2 && bx1==bx2 && ax1==bx1)   {    [...]   }else{
        if ( (bx1 > ax1) && (bx2 > ax1) && (bx1 > ax2) && (bx2 > ax2)  ) return 0;
        if ( (bx1 < ax1) && (bx2 < ax1) && (bx1 < ax2) && (bx2 < ax2)  ) return 0;  
        if ( (ax1 == bx1 && ay1 == by1) || (ax1 == bx2 && ay1 == by2)  )
           { *x = ax1;  *y = ay1;   return 1;   }
        if ( (ax2 == bx1 && ay2 == by1) || (ax2 == bx2 && ay2 == by2)  )
            { *x = ax2;  *y = ay2;   return 1;  }
  }
This change helped on my v.spag loop.

B)  Snaping is never used because in main2.c :
static  int   snap_ok = 0 ; 
[...]
    if (snap_ok == 1)    {
        if (s_val->answer != NULL)
            snap_val = atof(s_val->answer);
        thresh_flag = 0;
    }    else    { snap_val = 0.0;   thresh_flag = 0;    } 
[...]
My suggestion is add options 
-s  Snap nodes
-p  Prompt user for threshold value.
and change code for these options and threshold in the same way as used in v.build.

What others think about it? I'm not sure and don't want cause problems. 


Radim


---------------------------------------- 
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo at geog.uni-hannover.de with
subject 'unsubscribe grass5'



More information about the grass-dev mailing list