JDK-4335024 : Line2D.ptLineDistSq() can return negative numbers
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.2.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2000-05-02
  • Updated: 2003-04-12
  • Resolved: 2002-09-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 mantisFixed
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