Menu

Bug in LineSegment2D#distance

inovel
2014-04-28
2014-05-07
  • inovel

    inovel - 2014-04-28

    I found a problem with the distance calculation for a line segment, which occurs in the following sample usage:

        @Test
    public void testLineDistanceBug() {
        final LineSegment2D line = new LineSegment2D(44154, 37711, 45754, 30113);
        final Point2D point = new Point2D(44767, 34320);
        final Point2D projPoint = line.projectedPoint(point);
        final double dist = line.distance(point);
        final double dist2 = point.distance(projPoint);
    
        assertEquals(dist, dist2, 1e-5);
    }
    

    In this case, the projected point lies inside the segment, but AbstractLine2D#supportContains returns false for the projected point. The actual distance should be somewhat less than 100, but the distance call currently (tested with 0.11.2) returns about 3445 as distance.

     
  • David

    David - 2014-05-05

    Hi,
    thanks for report. There should be a bug inside... I will check it.
    regards,
    David

     
  • David

    David - 2014-05-07

    Hi,
    I have found the problem, and changed the method for computing distance. This should be now more robust!
    You can either checkout the current development version, or wait for next release.
    Regard,
    David

     

Log in to post a comment.