Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (563) Games in Android Showcase (151) games submitted by our members Games in WIP (605) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 bug in java.awt.geom.Line2D.ptLineDistSq() ?  (Read 1788 times) 0 Members and 1 Guest are viewing this topic.
Abuse

JGO Knight

Medals: 17

falling into the abyss of reality

 « Posted 2003-07-13 21:07:39 »

Before I make a bug report on this I thought i'd get the opinions of you ppl. (cos I don't wanna get laughed at for my appauling knowledge of Maths )

The class java.awt.geom.Line2D has a method :-

 1 `public static double ptLineDistSq(double X1, double Y1, double X2, double Y2, double PX, double PY)`

It calculates the distance (squared) between a given point and the nearest part of a line segment.

If however you pass in a line segment of zero length (X1=X2, Y1=Y2), the method performs a div by zero, which causes NaN to be returned.

I believe this is a bug, as the method documentation makes no exceptions to valid input.
Also IMO the distance from a point to a line segment still has a value even if the line segment has a zero length.

A simple sanity check at the start of the method would fix it,

if(X1==X2 && Y1==Y2) return (X1-PX)*(X1-PX)+(Y1-PY)*(Y1-PY);

So, whadda you reckon, is it a bug?

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
cfmdobbie

Senior Devvie

Medals: 1

Who, me?

 « Reply #1 - Posted 2003-07-13 22:23:37 »

It's definitely a line segment is it?  If the two points are used to describe a line, then passing two points zero distance apart wouldn't be a valid description of a line.

HOWEVER, if it returns NaN but the documentation doesn't mention it, then yes, I'd say it's at least a documentation bug, regardless of what caused the problem!

Hellomynameis Charlie Dobbie.
Abuse

JGO Knight

Medals: 17

falling into the abyss of reality

 « Reply #2 - Posted 2003-07-13 22:39:32 »

sigh, stupid stupid me.

I meant segDist, but in the test case i made, i put lineDist DOH!

I just checked segDist, and it worked as it should <_<

there u go, I knew i HAD to be wrong

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
 Games published by our own members! Check 'em out!
Abuse

JGO Knight

Medals: 17

falling into the abyss of reality

 « Reply #3 - Posted 2003-07-13 22:48:50 »

incidentally, passing in 2 identical points to the ptLineDist method does generate a NaN (which isn't mentioned in the docs) but I guess its a perfectly valid return value for such stupid parameters
The alternative whould be an IllegalArgumentException, but that would just be ugly.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 wxwsk8er (49 views) 2015-03-20 15:39:46 Fairy Tailz (42 views) 2015-03-15 21:52:20 Olo (26 views) 2015-03-13 17:51:59 Olo (29 views) 2015-03-13 17:50:51 Olo (33 views) 2015-03-13 17:50:16 Olo (40 views) 2015-03-13 17:47:07 ClaasJG (29 views) 2015-03-10 11:36:42 ClaasJG (36 views) 2015-03-10 11:33:01 Pippogeek (45 views) 2015-03-05 14:36:23 Pippogeek (37 views) 2015-03-05 13:56:12
 KevinWorkman 23x LiquidNitrogen 23x BurntPizza 21x basil_ 21x theagentd 18x Riven 18x EgonOlsen 17x Roquen 14x princec 12x SHC 9x Varkas 9x Slyth2727 9x NegativeZero 9x Ecumene 8x teletubo 7x nsigma 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org