Possible bug. Raycast and Circles.

Hi, i'm new to this forum. First of all thanks to all the developers for this great physics engine. 🙂

Anyway, I was having some problems with raycasting and circle shapes: if you try to raycast from a point inside a circle bounding box that actually misses the circle, you get an immediate collide.

I was already updated to the last SVN version and also searched through most of the forum to find similar problems.

The piece of code I changed to get things working was in org.jbox2d.collision.shapes.CircleShape testSegment method:

Code:
// Does the segment start inside the circle?
      if (b < 0.0f) {
         return SegmentCollide.STARTS_INSIDE_COLLIDE;
      }

      Vec2 r = tlR.get();
      // Solve quadratic equation.
      r.set(segment.p2).subLocal(segment.p1);
      final float c = Vec2.dot(s, r);
      final float rr = Vec2.dot(r, r);
      final float sigma = c * c - rr * b;

      // Check for negative discriminant and short segment.
      if (sigma <= 0.0f || rr < Settings.EPSILON) {
         return SegmentCollide.MISS_COLLIDE;
      }

      // Find the point of intersection of the line with the circle.
      float a = -(c + MathUtils.sqrt(sigma));

//       System.out.println(a + "; " + maxLambda + "; " + rr + "  ; " + (a <= maxLambda * rr));

      // Is the intersection point on the segment?
      if (0.0f <= a && a <= maxLambda * rr) {
         // System.out.println("Got here");
         a /= rr;
         out.lambda = a;
         out.normal.set(r).mulLocal(a).addLocal(s);
         out.normal.normalize();
         
         return SegmentCollide.HIT_COLLIDE;
      }

      return SegmentCollide.HIT_COLLIDE;


I obviously changed the last line in:
Code:
return SegmentCollide.MISS_COLLIDE;
.

Hope not to have put up an already known bug.

Happy New Year to everyone!
Francesco
well that definitely looks like a mistake, thanks for finding that! Sorry for any time you lost. I'll fix and submit right away
No problem! After all, isn't this what open source software's all about? 😉
Glad to have contributed, even if in a really small way.

Original thread: https://box2d.org/forum/viewtopic.php?t=4242