Name: stC104175 Date: 05/02/2000
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)
Given certain variables the ptLineDistSq() call is returning negative numbers.
This is causing the error that ptLineDist() is returning NaN because when it
tries to get the sqrt() of the result of ptLineDistSq() and sees it is negative
automatically return NaN. The situation is where you can 2 lines which are
extremely close to being colinear. if you get the distance from the points of
one of the lines to the other, NaN will be returned for one of them.
Code:
mport java.awt.geom.*;
public class Test {
public static void main (String[] args) {
Line2D.Double l1 = new Line2D.Double(-313.0, 241.0, -97.0,
75.0);
Line2D.Double l2 = new Line2D.Double(126.15362619253153, -
96.49769420351959, -97.0, 75.0);
System.out.println(l1.ptLineDistSq(l2.getP1()));
System.out.println(l1.ptLineDist(l2.getP1()));
System.out.println(l1.ptLineDistSq(l2.getP1()));
System.out.println(l1.ptLineDist(l2.getP2()));
}
}
(Review ID: 104357)
======================================================================