[GRASS-dev] Vect_line_buffer tolerance setting

Hello all,

I was going to use Vect_line_buffer function but was unable to
understand it's tolerance parameter. Could somebody extend a bit
documentation to make it more clean what does it mean.

For my module I need to create buffer around line without any "round
caps" at line end -> buffer must look like square and not extend
beyond input line end. Ideas how to tweak tolerance setting to get
such functionality out of Vect_line_buffer?

Thanks!
Maris.

Maris:

I was going to use Vect_line_buffer function but was unable to
understand it's tolerance parameter. Could somebody
extend a bit documentation to make it more clean what does it mean.

I am not 100% sure,

For my module I need to create buffer around line without any "round
caps" at line end -> buffer must look like square and not extend
beyond input line end. Ideas how to tweak tolerance setting
to get such functionality out of Vect_line_buffer?

maybe 'v.parallel distance=' for both left and right side of line?

or v.segment / v.lrs.segment with offset.

Hamish

Thanks Hamish, Росен.

Unfortunately this is a quite big problem for GRASS if nobody from
-dev ML can not explain how GRASS internal stuff works :frowning:
I hope You, Росен, will spend some time to add comments and examples
to existing vector lib functions to make them more non-ūbercoder
friendly.

On Spearfish example that I used to test my initial version of my
module I managed to get "flat" buffer ends instead of "round caps" by
setting tolerance to 1000. Still I have no idea why it works and how
large should tolerance value bee for other buffer sizes/locations. I
will take a look on Vect_line_parallel solution as it will be not so
hackish.

Thanks for hints!
Maris.

2008/5/18 Hamish <hamish_b@yahoo.com>:

Maris:

I was going to use Vect_line_buffer function but was unable to
understand it's tolerance parameter. Could somebody
extend a bit documentation to make it more clean what does it mean.

I am not 100% sure,

For my module I need to create buffer around line without any "round
caps" at line end -> buffer must look like square and not extend
beyond input line end. Ideas how to tweak tolerance setting
to get such functionality out of Vect_line_buffer?

maybe 'v.parallel distance=' for both left and right side of line?

or v.segment / v.lrs.segment with offset.

Hamish

Maris:

Unfortunately this is a quite big problem for GRASS if nobody
from -dev ML can not explain how GRASS internal stuff works :frowning:

It's not so bad, Radim did leave notes. e.g. in lib/vector/Vlib/buffer.c in the case of public functions they are even Doxygen-ized so they appear in the programmer's manual. For me "grep" does the job.

/*!
  \brief Create parrallel line
  
  \param InPoints input line
  \param distance create parrallel line in distance
  \param tolerance maximum distance between theoretical arc and polygon segments
  \param rm_end remove end points falling into distance
  \param[out] OutPoints output line

  \return
*/
void
Vect_line_parallel ( ... )
{
....
}

here is the relevant code:

Vect_line_buffer()
....
    dangle = 2 * acos( 1-tolerance/fabs(distance) ); /* angle step */

parallel_line()
....
    atol = 2 * acos( 1-tol/fabs(d) );
....
    /* TODO: a <= PI can probably fail because of representation error */
    if ( a <= PI && a > atol)
    {
  na = (int) (a/atol);
  atol2 = a/(na+1) * side;
  for (j = 0; j < na; j++)
  {
      av+=atol2;
      nx = x[i+1] + fabs(d) * cos(av);
      ny = y[i+1] + fabs(d) * sin(av);
      Vect_append_point ( nPoints, nx, ny, 0 );
  }
    }

Hamish