Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 1638 times)
0 Members and 1 Guest are viewing this topic.
Offline Abuse

JGO Coder


Medals: 11


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! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline cfmdobbie

Senior Member


Medals: 1


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: 11


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! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Coder


Medals: 11


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! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

ctomni231 (33 views)
2014-07-18 06:55:21

Zero Volt (29 views)
2014-07-17 23:47:54

danieldean (24 views)
2014-07-17 23:41:23

MustardPeter (26 views)
2014-07-16 23:30:00

Cero (41 views)
2014-07-16 00:42:17

Riven (43 views)
2014-07-14 18:02:53

OpenGLShaders (31 views)
2014-07-14 16:23:47

Riven (30 views)
2014-07-14 11:51:35

quew8 (29 views)
2014-07-13 13:57:52

SHC (65 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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
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!