Menu

Bug found in lq.c + correction

2007-06-04
2013-04-30
  • Nicolas Brodu

    Nicolas Brodu - 2007-06-04

    Hello,

    There is a bug in lq.c which causes "outside" points to be missed. An automated test is available here, showing the bug in action:
      http://nicolas.brodu.free.fr/opensteer/lqtest.cpp
    (Is there a way to attach a file in the forum?)

    The bug comes from the fact a raw float -> int conversion truncates toward 0, not toward -inf. Using floorf solves the problem.

    Example:    minBinX = (int) ((((x - radius) - lq->originx) / lq->sizex) * lq->divx);

    Should be:  minBinX = (int) floorf((((x - radius) - lq->originx) / lq->sizex) * lq->divx);

    The patched lq.c is available here:
      http://nicolas.brodu.free.fr/opensteer/lq.c

    Cheers,
    Nicolas

     

Log in to post a comment.