Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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 1282 times)
0 Members and 1 Guest are viewing this topic.
Offline Abuse

JGO Coder


Medals: 2


falling into the abyss of reality


« Posted 2003-07-13 23: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 Cheesy)

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!
Offline cfmdobbie

Senior Member




Who, me?


« Reply #1 - Posted 2003-07-14 00: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.
Offline Abuse

JGO Coder


Medals: 2


falling into the abyss of reality


« Reply #2 - Posted 2003-07-14 00: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 Grin

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here!
Games published by our own members! Check 'em out!
Try the Free Demo of Droid Assault
Offline Abuse

JGO Coder


Medals: 2


falling into the abyss of reality


« Reply #3 - Posted 2003-07-14 00: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 Cheesy
The alternative whould be an IllegalArgumentException, but that would just be ugly.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (78 views)
2013-05-17 21:29:12

alaslipknot (89 views)
2013-05-16 21:24:48

gouessej (122 views)
2013-05-16 00:53:38

gouessej (113 views)
2013-05-16 00:17:58

theagentd (126 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (157 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (179 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.112 seconds with 20 queries.