Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (686)
Games in Android Showcase (198)
games submitted by our members
Games in WIP (758)
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 2130 times)
0 Members and 1 Guest are viewing this topic.
Offline Abuse

JGO Ninja

Medals: 50

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 Cheesy)

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

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?
Offline 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.
Offline Abuse

JGO Ninja

Medals: 50

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 Grin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Ninja

Medals: 50

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 Cheesy
The alternative whould be an IllegalArgumentException, but that would just be ugly.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

roseslayer (412 views)
2016-08-06 11:43:29

roseslayer (376 views)
2016-08-06 09:43:11

xTheGamerCodes (450 views)
2016-08-04 15:40:59

xTheGamerCodes (444 views)
2016-08-04 15:40:24

orrenravid (795 views)
2016-07-16 03:57:23

theagentd (870 views)
2016-07-11 14:28:54

Hydroque (967 views)
2016-07-06 05:56:57

Hydroque (989 views)
2016-07-03 08:52:54

GrandCastle (802 views)
2016-07-01 09:13:47

GrandCastle (637 views)
2016-07-01 09:09:45
Rendering resources
by Roquen
2016-08-08 05:55:21

Rendering resources
by Roquen
2016-08-08 05:52:42

Rendering resources
by Roquen
2016-08-08 05:50:38

Rendering resources
by Roquen
2016-08-08 05:49:53

Rendering resources
by Roquen
2016-08-08 05:32:39

Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42 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‑
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!