Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4335024
Votes 2
Synopsis Line2D.ptLineDistSq() can return negative numbers
Category java:classes_2d
Reported Against 1.2.2
Release Fixed 1.4.2(mantis)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs
Submit Date 02-MAY-2000
Description




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) 
======================================================================
Work Around




Use Math.sqrt(Math.abs(Line2D.ptLineDistSq()))
======================================================================
Evaluation
We should protect against the relative point vector length being
less than the calculated projected vector length and return 0.0 in
those cases.

 xxxxx@xxxxx  2002-08-28
Comments
  
  Include a link with my name & email   

Submitted On 31-JUL-2002
metasim
Please fix, as the fix is very easy. I'm having to add
Math.abs() for proper operation.


Submitted On 12-AUG-2002
ghedges99
I agree with metasim, the fix is pretty easy and I'd like to see it fixed too.  Line2D is very useful otherwise.



PLEASE NOTE: JDK6 is formerly known as Project Mustang