Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (581) Games in Android Showcase (162) games submitted by our members Games in WIP (632) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 bug in java.awt.geom.Line2D.ptLineDistSq() ?  (Read 1833 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
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.

 Waterwolf (22 views) 2015-05-20 15:01:45 chrislo27 (26 views) 2015-05-20 03:42:21 BurntPizza (60 views) 2015-05-10 15:53:18 FrozenShade (46 views) 2015-05-07 09:11:21 TheLopais (209 views) 2015-05-06 13:36:48 TheLopais (193 views) 2015-05-06 13:35:14 TheLopais (200 views) 2015-05-06 13:33:39 TheLopais (217 views) 2015-05-06 13:32:48 TheLopais (215 views) 2015-05-06 13:31:28 ClaasJG (237 views) 2015-04-30 20:33:25
 Spasi 31x BurntPizza 16x DavidBVal 13x theagentd 13x ra4king 12x EgonOlsen 11x Husk 10x KevinWorkman 9x scanevaro 8x princec 8x opiop65 7x KaiHH 7x Riven 6x revers 6x SauronWatchesYou 5x Drenius 5x
 List of Learning Resources2015-05-05 10:20:32How 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:00
 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