United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4335024 : Line2D.ptLineDistSq() can return negative numbers

Details
Type:
Bug
Submit Date:
2000-05-02
Status:
Resolved
Updated Date:
2003-04-12
Project Name:
JDK
Resolved Date:
2002-09-16
Component:
client-libs
OS:
windows_nt
Sub-Component:
2d
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.2.2
Fixed Versions:
1.4.2 (mantis)

Related Reports

Sub Tasks

Description

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

                                    

Comments
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mantis
mantis-b02

FIXED IN:
mantis
mantis-b02

INTEGRATED IN:
mantis
mantis-b02


                                     
2004-06-14
WORK AROUND



Name: stC104175			Date: 05/02/2000


Use Math.sqrt(Math.abs(Line2D.ptLineDistSq()))
======================================================================
                                     
2004-06-11
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.

###@###.### 2002-08-28
                                     
2002-08-28



Hardware and Software, Engineered to Work Together